Due Monday, December 12 at Midnight.
At the conclusion of this programming assignment, participants should be able to:
Before starting this programming assignment, participants should be able to:
Content used in this assignment is based upon information in the following sources:
For this assignment you can choose one of the following two programs to implement:
The following program details apply to either program (Tic Tac Toe or game of your choice).
__init__() method and getter/setter methods. You should not directly access any attributes of an object. Call the appropriate getter or setter methods instead.Write a program (tictactoe.py) for two-player interactive game to play Tic Tac Toe. The Tic Tac Toe game board consists of a total of n x n cells, where n is selected by the user of the game. Your program should randomly select who goes first, X or O. Once a player has been chosen, your program should prompt the player for a position (row and column) in which to draw his/her symbol. Players continue to alternate moves until either a winner has been determined or a "scratch" game occurs. A player wins if his/her symbols align with n in a row diagonally, vertically, or horizontally. A "scratch" game occurs if all cells on the board are occupied and no player aligned n of his/her symbols in a row.
The underlying game board should be represented with the following structures:
Coordinate: representing the coordinates of a cell on the board. Coordinate should contain the following attributes and methods (at a minimum):row: a row locationcol: a column location__str__(): returns a string representation of a Coordinate, i.e. (0, 0)Cell, representing a cell on the board. Cell should contain the following attributes (at a minimum):occupied: whether or not this cell is occupiedsymbol: the symbol to display at this cell (X for player one, O for the other player)location: the location of this cell on the board (a Coordinate object).__str__(): returns a string representation of a Cell, i.e. return the symbolTicTacToeBoard: representing the Tic Tac Toe board. Board should contain the following attributes and methods (at a minimum):n: dimension of board (entered by user)board: the Tic Tac Toe n x n grid (a 2-Dimensional list of Cell objects)__str__(): returns a string representation of a TicTacToeBoard, i.e. display the game boardis_valid_move(): accepts the coordinates of a cell. Returns True if the coordinates are valid and the cell is unoccuppied; otherwise returns False.make_move(): accepts the coordinates of a cell and a symbol. Marks the cell with the symbol.is_winner(): accepts a player symbol (X or O). Returns True if there are n in a row of the player symbol; otherwise returns FalseThe program should prompt the users to determine if they want to play another game. Keep track of each player's number of wins, losses, and total game played in a GameStats class. When the user wants to quit playing Tic Tac Toe games, report both of the user's game stats, including:
Use functions and methods where appropriate!
Here is an example run of the program:
Welcome to Tic Tac Toe! There are two players, player 'X' and player 'O'.
Player X is going first.
0 1 2
0 - - -
1 - - -
2 - - -
Player X, please enter the coordinates of your placement: 2 2
0 1 2
0 - - -
1 - - -
2 - - X
Player O, please enter the coordinates of your placement: 1 1
0 1 2
0 - - -
1 - O -
2 - - X
Player X, please enter the coordinates of your placement: 0 0
0 1 2
0 X - -
1 - O -
2 - - X
Player O, please enter the coordinates of your placement: 2 1
0 1 2
0 X - -
1 - O -
2 - O X
Player X, please enter the coordinates of your placement: 0 2
0 1 2
0 X - X
1 - O -
2 - O X
Player O, please enter the coordinates of your placement: 0 1
0 1 2
0 X O X
1 - O -
2 - O X
O won!
Would you like to play again? Enter 'y' to play or 'q' to quit: y
Player O is going first.
0 1 2
0 - - -
1 - - -
2 - - -
...[output omitted for brevity]...
Player O, please enter the coordinates of your placement: 1 2
0 1 2
0 O X X
1 X O O
2 O O X
Scratch game, too bad.
Would you like to play again? Enter 'y' to play or 'q' to quit: q
Player X game stats
-------------------
Win to loss ratio: 0:1
Win percentage: 0.00%
Number of scratch games: 1
Player O game stats
-------------------
Win to loss ratio: 1:0
Win percentage: 50.00%
Number of scratch games: 1
Provide a option for the user to play against the computer. Introduce some basic artificial intelligence so that the computer makes "educated" moves.
Write a program (mygame.py) that is a game of your choosing. Your game can be a commonly known game or one you make up. If you choose to implement a game (or version of a game) that you didn't author, cite the game source(s) in your header comment in mygame.py.
Your program needs to adhere to the following requirements:
GameStats class that tracks the user(s) progress through the game (or multiple iterations of the game, as is the case with Option 1: Tic Tac Toe).GameStats. These could be characters and/or weapons in your game, a board and pieces for your game, cards and a deck if it is a card game, etc.Feel free to ask me or your TA if your game idea/program meets this requirements. We are happy to hear your ideas, have fun with this assignment!
Note: Keep your game simple and functional. You should strive to turn in a fully functioning, low-complexity game instead of a fancy game with lots of broken features!
Here are some ideas for games. Most of these games are fairly complex. I encourage you to implement a simplified version of the game, so long as the game meets the requirements specified above.
Present your game to the class during the last day of class (12/7). The presentation should be about 5 minutes and include the following:
Please email me by midnight on 12/6 if you would like to do this.
Note: Your game most likely will not be complete by this day. That is okay! Show us what you have, it will be great!
<your last name>_pa9.zip by the due date and time.This assignment is worth 125 points + 10 points bonus. Your assignment will be evaluated based on a successful compilation and adherence to the program requirements. We will grade according to the following criteria:
GameStats objectCoordinate, Cell, and TicTacToeBoard for Option 1: Tic Tac Toe)__init__() and getter/setter methods