Tic-Tac-Toe Board Evaluation

PSU CS 441/541 Homework 3
Due before class Monday, November 6

A board evaluator is a function which, given a board position and a player on move, returns the value of the position for the player. The value of a position for a player is the best score that can be achieved by that player from that position with perfect play by both sides. In this assignment, you will construct a perfect 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 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.

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

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

BONUS: 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.

Homework should be submitted by e-mail to <cs541@cs.pdx.edu>. The words "CS441/541 HW3" 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.