Out: April 18, 2012
Due: April 30, 2012 at 17:00:00
Type: Individual assignment
Tic-tac-toe is a classic two-player, turn-based game in which players try to get three Xs or Os in a row on a 3x3 board. In this assignment you will convert a two-player game of tic-tac-toe into a one-player version in which a human player gets to play against a very smart computer opponent. You will be implementing the computer opponent using the MiniMax algorithm discussed in class.
The game of tic-tac-toe is small enough that we can generate the entire game tree while doing the MiniMax search. As a result, you do not need to create an evaluation function for non-terminal nodes. What you will need to create is a utility function which returns the utility at terminal states.
You will also need to create a successor function. This function takes the current state of the game and generates all the successors that can be reached within one move of the current state. Both the utility function and the successor function need to be written. You get to decide what these functions should look like. Once these two functions are in place, you can begin coding the actual MiniMax algorithm.
You can use Java, C++ or C. If you choose to use a programming language other than these three, please email the TA for approval. For the assignment, you must implement a GUI for the tic-tac-toe game. If you are programming in Java, I have provided code for a GUI below. Your main function should take the following command line arguments:
The command line arguments are: [Player 1 Type] [Player 2 Type] where the player type can be one of:
Player 1 is the X player who always goes first while player 2 is the O player. You can currently play against either another human opponent or the random opponent that selects the next move randomly from among the empty squares. Running against a minimax opponent will currently cause the program to crash since the code is incomplete.
If you choose to use Java, you may use source code below for the GUI. You will need to set up the directory structure as To help you navigate through the code, here is a set of Java docs for you. Click here.
The main function for the program is in GameFrame.java.
The core of this assignment is in the function: This function calculates the next move in the game for the appropriate player. It returns the move in a Position class, which simply stores the row and column index of the move.
All of your source . Zip everything up with a zip program. To hand in your assignment, go to the TEACH electronic handin site:
https://secure.engr.oregonstate.edu:8000
Correctness of your code will be determined primarily by the markers interacting with the game. If the computer player cannot be beaten, you will get full credit. Also, 10% of your grade will depend on how readable your code is.
public Position getNextMove(TicTacToeBoard state) in MiniMax.java
Hand in
Grading Criteria