Tic-Tac-Toe Board Evaluation

PSU CS 441/541 Homework 2
Due before class Thursday, November 15

A board evaluator is a function which, given a game state, returns the minimax value of the state. The minimax value of a game state is the final game score that will be achieved in the state given perfect play by both sides.

In this assignment, you will construct a board evaluator for the game of Tic-Tac-Toe (TTT).

The input to the program should be a TTT position on standard input. 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 game state is given by a sequence of nine integers, one per line, representing squares 1-9 of a board position 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 win for X.

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.

``Everybody knows'' that with perfect play from the initial position, TTT is a draw. Does your program prove this? (Answer in a comment in the source.)

BONUS EXTRA CREDIT: Add a transposition table. Does this improve the performance of your program?

BONUS EXTRA CREDIT: Add alpha-beta pruning. Does this improve the performance of your program? How can you order the moves to improve the pruning achieved by alpha-beta?


Your program may be written in the language of your choice (let me know if you're planning on something other than C, C++, or Java) but should compile and run on the department UNIX machines. If you are developing on the department machines, please follow the departmental computing Safety Guidelines.

Homework should be submitted by e-mail to <cs541@cs.pdx.edu>. The words "CS441/541 HW2" should appear somewhere in the subject line. The homework submission should be a computer program giving the requested input-to-output mapping. It will be manually scanned for readability and approach, then automatically graded by validating it against a set of reasonable test cases. Remember, if I can't understand your submission, I can't give you credit for it.