Back to index

gcompris  8.2.2
board.py
Go to the documentation of this file.
00001 #  gcompris - connect4 
00002 # 
00003 # Time-stamp: 
00004 # 
00005 # Copyright (C) 2005 Laurent Lacheny 
00006 # 
00007 #   This program is free software; you can redistribute it and/or modify
00008 #   it under the terms of the GNU General Public License as published by
00009 #   the Free Software Foundation; either version 2 of the License, or
00010 #   (at your option) any later version.
00011 # 
00012 #   This program is distributed in the hope that it will be useful,
00013 #   but WITHOUT ANY WARRANTY; without even the implied warranty of
00014 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015 #   GNU General Public License for more details.
00016 # 
00017 #   You should have received a copy of the GNU General Public License
00018 #   along with this program; if not, write to the Free Software
00019 #   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 
00021 #
00022 # This code comes from the project 4stattack
00023 # http://forcedattack.sourceforge.net/
00024 #
00025 #########################################################################
00026 #                            4st Attack 2                               #
00027 #########################################################################
00028 # Created by:                                                           #
00029 # Developer            - "slm" - Jeroen Vloothuis                       #
00030 # Graphics             - "Korruptor" - Gareth Noyce                     #
00031 # Music                - "theGREENzebra"                                #
00032 #########################################################################
00033 # Specail thanks:                                                       #
00034 # chakie(Jan Elkholm)    - letting me "embrace and extend" his gui lib  #
00035 # Mighty(Xander Soldaat) - for the Makefile and the Debian packages     #
00036 # Han                    - for the rpms                                 #
00037 # jk                     - for the FreeBSD port                         #
00038 # Tjerk Nan              - for the Windows version                      #
00039 # Micon                  - for the webdesign                            #
00040 # Everyone in #pygame and the opensource community in general           #
00041 #########################################################################
00042 # This software is licensed under the GPL - General Public License      #
00043 #########################################################################
00044 
00045 
00046 
00047 class Board:
00048   # Setup an empty board
00049   def __init__(self):
00050     self.state = []
00051     for x in range(7):
00052       self.state.append([])
00053     self.last_move = -1
00054   
00055   def move(self, move, player):
00056     self.state[move].append(player)
00057     self.last_move = move
00058   
00059   def domoves(self, moves):
00060     for (move, player) in moves:
00061       self.move(move, player)
00062       
00063   def undomove(self, move):
00064     if len(self.state[move]) > 0:
00065       del self.state[move][len(self.state[move])-1]