Assigned Date: Friday, Apr. 3, 2015
Due Date: Friday, Mar. 10, 2015
Due Time: 12:20pm
Last modified on April 09, 2015, at 09:04 PM (see updates)
Write a program that simulates a game of Tic-Tac-Toe. In our version of the game, two players, human and computer, play in turns, placing X's and O's, respectively, on the 3x3 square board. The human player always goes first. The game goes on until either there is a winner (3 X's or 3 O's in a vertical, horizontal, or diagonal line), or the game is a draw (all squares are occupied and no one has won).
The program should display the current board configuration (via print statements) after each move, e.g.,
X | |
O | |
X | O |
and prompt the user (via an input statement) to enter a move (a number from 1 to 9).
The human player always goes first. Squares are numbered consecutively, from 1 to 9, where 2 is the middle square in the top row. The program should be as robust as possible. When the game is over it should output a message describing the outcome.
This is a solo assignment (you must work alone).
- To design expressions using relational and logical operators
- To design selection statements
- To design repetition statements
- To design simple data structures using lists
- To design functions
- To apply top-down design in program development
In general, you should comment any variable, obscure statement, block of code, etc. you create.
Your comments should reflect the "why" something is there (or being done), as opposed to the "how". The "how" is reflected in the code. The "why" usually comes from the thought you had, as to what you were trying to do, before you wrote the corresponding Python code.
So, since that info is in your head first (i.e., before you write the code), it is much easier to type it in your program (before you figure out the corresponding code that does what needs to be done).
Conversely, once you have already written the code, it is very hard to go back and recreate the original thought (thus comments written after the code tend to focus on the "how" something is being done, and not the "why" - the latter being what we need.)
The goal of comments is to gently introduce someone accurately into the big picture of our code - the forest view - while the code itself represents the tree view.
Additionally, your code should always have header documentation that explains what the program does, in general terms.
Follow the documentation instructions from Homework 1.
You will submit your assignment via OAKS. Your submission consists of:
- Your Python program. Call it, ticTacToe.py.
- A printout of your program - to be submitted in class on the due date.
- Be ready to play (demonstrate) your game in class.
Your grade will be based on how well you followed the above instructions.