Tic Tac Toe Tic-tac-toe is a game for two players. The players take turns marking the spaces in a 3×3 grid. The player who succeeds in placing three marks in a horizontal, vertical, or diagonal row wins the game.
Tic Tac Toe GUI You will implement a Graphical User interface for a Tic Tac Toe game with the following specifications: • The user will play against the computer. • The user is assigned one color and the computer is assigned another color. These may be any 2 colors of your choice. • The user always starts playing first. The user marks a space on the grid by clicking on that space. That space is then colored with the user’s assigned color. The computer immediately plays its move by coloring an available space with the other color. • If the user attempts to mark a space that is already taken, either by the user or the computer, nothing happens. • The game goes on until one player (the user or the computer) has 3 colored spaces in a line. The line can be horizontal, vertical, or diagonal. The game can also end in a tie if the entire board fills with no player completing such a line. • The player is given the option to restart the game, at any point during a game or after a win, a loss or a tie.
Screencast on youtube To get a feel of the general flow of the game, watch the screencast: • http://youtu.be/SjV7yz_VPcE
Brainstorming Data Structures Before you start coding, think about the following decisions you’ll have to make and their implications: • How will you represent the 3x3 grid? • How will you indicate that a space is empty, is marked by the player or is marked by the computer? • How will you translate event coordinates into one of 9 spaces in your grid? • How will you check that one player has won? • How will you check for a tie? • How will you decide what space the computer will mark? Just a random empty space is OK for the purpose of this assignment but if you like a challenge, think of ‘smarter’ moves.
The random Module To generate a random move, you’ll need to generate random numbers in a certain range: • To generate a random integer between a and b (including a and b), you may use the randint function as follows: import random my_random_int = random.randint(a, b)
tictac.py • Start with the module tictac.py provided under Resources. • This is more than a template. It sketches an object oriented implementation that you will have to follow.
tictac.py
main
__init__
initialize_game
restart()
play()
check_game
More Methods You’ll probably define more methods in your class definition but you are required to have at least the ones included in tictac.py.
Testing Make sure you test your module before submitting it! You have to be able to win, lose and end the game in a tie.
Grading Rubric Appearance – 30 points The GUI application looks right as illustrated in the screencast. Correctness - 50 points total The GUI application behaves correctly as illustrated in the screencast. The right space is colored when the user clicks somewhere - 10 points The computer plays a valid space immediately after the user - 10 points Clicking on a space that is already taken does not result in a play - 5 points The 3 different outcomes (win, lose and tie) are detected correctly and announced: 15 points Restarting the game at any point reinitializes the game correctly - 10 points