Perfect Tic-Tac-Toe

PSU CS 410/510 Games Homework 3
Due before class Tuesday July 25
Not accepted after Tuesday August 1

``Everybody knows'' that perfect Tic-Tac-Toe is a draw. As we discussed in class, this is different than being able to prove it.

For this assignment, you will construct a program which, given an arbitrary Tic-Tac-Toe position, returns the true minimax value of that position by complete search.

The input to the program should be a Tic-Tac-Toe position (given in a file or on standard input, whichever is convenient for you). Let the integer 1 represent the maximizer (player ``X'', who plays first) and -1 represent the minimizer (player ``O'', who plays second). Let the integer 0 represent a blank square. Then a position is given by a sequence of nine integers, one per line, representing board positions 1-9 in the format

123
456
789
Note that the player on move can be determined by counting the number of moves each player has made, and thus does not require a separate description.

For example, the board position

1
0
1
-1
1
0
-1
0
0
encodes the board
X X
OX 
O  
with O to move, which is a lost position for O.

The program's output should be an integer 1, -1, or 0 depending on whether the input position is a maximizer win, minimizer win, or draw.

  1. Use your evaluator to determine the value of the initial Tic-Tac-Toe position. Is it a draw?

  2. The game of Toroidal Tic-Tac-Toe (T4), suggested to me by a colleague at Lewis and Clark, is identical to Tic-Tac-Toe in that it is played on a 3x3 board and a row of 3 squares vertically, horizontally, or diagonally is a win.

    However it is played on a board which has been folded into a torus or doughnut by identifying opposite edges: that is, cells 1 and 7, 2 and 8, 3 and 9, 1 and 3, 4 and 6, and 7 and 9 share their corresponding outside edges. Thus there are some ``extra'' winning positions in T4.

    1. There are 8 winning lines in ordinary Tic-Tac-Toe. (For example, 1-2-3 is a win.) List all 8.
    2. There are exactly 4 ``extra'' winning lines in T4. List these.
    3. Modify your code to determine the value of T4 positions. What is the value of the initial position in T4?


Homework should be submitted by e-mail to <cs510games@cs.pdx.edu>. The words "cs510games hw3" should appear somewhere in the subject line. The homework submission should be a MIME message containing your source code, a writeup in ASCII answering all questions posed by the assignment, and the results of program runs. Please follow all accepted coding and software engineering practices for your programming language. Remember, if I can't understand your submission, I can't give you credit for it.

I'd like you to do this assignment by yourself. If you do work with anyone else, you must credit them in your submission.