O X X _then the opponent can place their mark at the other end, in the empty space (_), like this, O X X O. This captures the marks in the middle, and they are removed from the board:
O _ _ O
Play continues until someone gets 5 in a line, either horizontally, vertically, or diagonally, or when a player captures 5 pairs of their opponent's pieces.
You can read the history and rules of Pente at http://en.wikipedia.org/wiki/Pente. The game is usually played on a 19-by-19 board, but we will use 9-by-9. Here is the start of a sample game:
$ python Pente.py X's captures: 0 O's captures: 0 00 01 02 03 04 05 06 07 08 00 _ _ _ _ _ _ _ _ _ 01 _ _ _ _ _ _ _ _ _ 02 _ _ _ _ _ _ _ _ _ 03 _ _ _ _ _ _ _ _ _ 04 _ _ _ _ _ _ _ _ _ 05 _ _ _ _ _ _ _ _ _ 06 _ _ _ _ _ _ _ _ _ 07 _ _ _ _ _ _ _ _ _ 08 _ _ _ _ _ _ _ _ _ Type your move: row,col: 2,2 The computer moved to (2, 3) X's captures: 0 O's captures: 0 00 01 02 03 04 05 06 07 08 (the human placed their X at 2,2 00 _ _ _ _ _ _ _ _ _ and the computerized opponent chose 2,3) 01 _ _ _ _ _ _ _ _ _ 02 _ _ X O _ _ _ _ _ 03 _ _ _ _ _ _ _ _ _ 04 _ _ _ _ _ _ _ _ _ 05 _ _ _ _ _ _ _ _ _ 06 _ _ _ _ _ _ _ _ _ 07 _ _ _ _ _ _ _ _ _ 08 _ _ _ _ _ _ _ _ _ Type your move: row,col: 3,3 The computer moved to (1, 1) X's captures: 0 O's captures: 0 00 01 02 03 04 05 06 07 08 00 _ _ _ _ _ _ _ _ _ (the human is trying to make some pieces in 01 _ O _ _ _ _ _ _ _ a line, but the computer is trying to block) 02 _ _ X O _ _ _ _ _ 03 _ _ _ X _ _ _ _ _ 04 _ _ _ _ _ _ _ _ _ 05 _ _ _ _ _ _ _ _ _ 06 _ _ _ _ _ _ _ _ _ 07 _ _ _ _ _ _ _ _ _ 08 _ _ _ _ _ _ _ _ _ Type your move: row,col: 2,1 The computer moved to (4, 4) Capture between 4 4 and 1 1 X's captures: 0 O's captures: 1 00 01 02 03 04 05 06 07 08 00 _ _ _ _ _ _ _ _ _ (when the human placed an X at 2,1 -- a bad move -- 01 _ O _ _ _ _ _ _ _ the computer placed an O at 4,4 and captured 02 _ X _ O _ _ _ _ _ the two pieces that were between the two Os) 03 _ _ _ _ _ _ _ _ _ 04 _ _ _ _ O _ _ _ _ 05 _ _ _ _ _ _ _ _ _ 06 _ _ _ _ _ _ _ _ _ 07 _ _ _ _ _ _ _ _ _ 08 _ _ _ _ _ _ _ _ _ Type your move: row,col:The program you will write will use a computerized player that I have already built for you.
You will build your game in this architecture. I have already written module ComputerPlayer, and I have written ``skeletons'' of PenteBoard and Pente. You must finish writing PenteBoard.py and you must improve Pente.py so that it controls the Pente game like the example shown above so that the human and computer can make moves until someone wins.
# Build the board: size = 9 # this size can be adjusted to make differently sized boards EMPTY = "_" # the value used for an empty square on the board board = [] for i in range(size) : # a clever way to build the nested list of correct size board = board + [ size * [EMPTY] ] def printBoard() : """printBoard displays the board as a grid, with coordinate numbers along the top and left side """ # IMPROVE THIS FUNCTION so that it prints the board as a grid print board def makeMove(row, col, mark): """makeMove attempts to insert a mark into the board at position, row,col. If the move is made, then any captures that result are performed. parameters: row - the row index; col - the column index; mark - "X" or "O" returns True if the move is successful; returns False otherwise. """ # IMPROVE THIS FUNCTION so that it checks that the row and col are legal # coordinates, that the selected square is empty, and once the # mark is placed in the square, all captures are correctly computed result = False board[row][col] = mark # TOO simple! doCaptures(row,col,mark) # call this function to compute the captures result = True return result . . .
You must finish this module, completing the functions. Do not change the names of the functions. (The reason is that the ComputerPlayer module depends on the functions exactly as named. This is standard procedure when teams of people build a multi-module program: the teams will agree on the names of the functions, and each team fills in the details in their module's functions.) PenteBoard.py is found at http://www.cis.ksu.edu/~schmidt/200s08/Assign/Assign5/PenteBoard.py
When you read this module, you will see that it imports PenteBoard.py and calls its functions. But the Controller module does not alter the game board directly! This is standard procedure that programming teams take: each team builds its own module to fit with the others, and each team minds its own business and promises not to alter the insides of the other modules. (That is, one module can call another module's functions and can look at another module's variables, but a module never changes, by assignment, the values of another module's variables --- in practice, this is far too dangerous!)
Finally, you need not look at it --- and you are certainly not allowed to change it --- but you should copy the ComputerPlayer module into the same folder where you copy the model and controller. When you are ready to use it, uncomment the lines in the controller that import and call the ComputerPlayer. The computer player is at http://www.cis.ksu.edu/~schmidt/200s08/Assign/Assign5/ComputerPlayer.py
Do as much of this assignment as you can, following the stages listed above. (The last two stages are the hardest.) You will get partial credit for a partially completed project.
Before you submit your program, you must ``zip'' (compress) your folder, Assign5: