This project consists of designing and implementing a program that plays Othello. To some this game is also known as Reversi. It will exemplify the minimax algorithm and alpha-beta pruning. Usage of any machine learning technique (e.g. Decision Trees) along with the MinMax algorithm will earn extra credit and perhaps improve performance in the tournament.
Othello is a two player game (one of them being your computer program). The classical game board is an 8 by 8 grid. At the start of the game there are four pieces in the center of the grid. White in the top-left and bottom-right. Black in the top-right and bottom-left. (See Figure 1 for initial configuration) Players take turns placing pieces on the board until the board is full. The object is to catch opponent's pieces between two of your pieces to flip them to your color. At the end of the game, whoever has the most pieces on the board wins.
One of the players uses white pieces and the other one uses black pieces.
We will use an 8x8 board. We will label the the board as in Figures 1-3: columns A through H (left to right), and the rows 1 through 8 (bottom to top).
There are two types of legal moves. First are those which trap at least one opponent piece between pre-existing pieces of your color on the board and the currently placed piece. This trapping could be horizontal, vertical, or diagonal. The other legal move is a PASS. This move can only be taken when there are no trapping legal moves available for the player to take. See links at the bottom for game downloads and online play.
It is true that moves alternate between black and white, but to be explicit, we will describe a move as a triple: (color column row) where:
For example, a possible first move of the game is (W D 3), meaning that a white piece is placed in column D (the fourth from the left), and it occupies row 3 (the third from the bottom). This would result in the black piece at (D,4) being converted to a white piece (see Figure 2). It would then be player 2's turn. A possible move for Black would be (B C 3), placing a black piece in column C, row 3. This results in the white piece at (D,4) being converted to a black piece (see Figure 3).
A game will consist of a sequence of the following actions:
- It is selected at random which player will use the white pieces and which player will use the black pieces. In what follows, the player that gets to use the white pieces is called player 1 and the player that gets to use the black pieces is called player 2.
- Player 1 gets to play first.
- After that, the players take turns moving. A move (color column row) must satisfy the following constraints:
- Time Limit There is a 60 second time limit for a player to make his move. (user time, not CPU time.)
- Move preconditions (if not passing)
- color is W if it is player 1's turn and B if it is player 2's turn.
- There is no piece at column, row.
- column, row is a valid board location (A <= column <= H, 1 <= row <= 8)
- There is a sequence of opponent pieces followed by your piece starting from column, row in at least one of eight directions. If not, the turn is lost and the other player goes again.
- Move postconditions (if not passing)
- After the move, the place at column and row on the board will be occupied by a color piece.
- For each of eight directions (up, up-right, right, right-down, down, down-left, left, left-up) any sequence of opponent pieces followed by your piece starting at column, row is converted to a color piece.
- It will be the other player's turn.
- Move preconditions (if column = P)
- There is no open (col,row) with a necessary sequence of opponent pieces followed by your piece starting there.
- Move postconditions (if column = P)
- The board configuration remains unchanged
- It will be the other player's turn.
- The game ends in any of the following cases:
- The board is full. The player with the most pieces wins the game, and the other loses the game. If the number of pieces is equal, then the game is a draw.
- neither player can make a legal move, the player with the most pieces wins.
- a player makes an illegal move - the other player wins.
- a player fails to move within the time limit - the other player wins.
There are many communication methods that are far more elegant and efficient than this one, but the intent is that this method will result in the least elaborated code, and that it allows you to implement your program in your choice of languages. The debugging is also simple since you can control the contents of these files with the use of any text editor.
The program will read input from groupname.in and output its moves to groupname.out
A referee program is provided. This referee program is in charge of deciding which program goes first, giving each program's turn to the other program, displaying the board configuration, detecting illegal moves, and enforcing time limits.
Here are some programs for download:
Specifically, the referee program will be in charge of:
Along with your code, you must also submit code documentation. It must follow the Departmental Documentation Standard (see http://www.cs.wpi.edu/Help/documentation-standard.html). Project 3 is due on February 17, 2002 at 9 pm. One (and only one) member of your group must submit the following files using the turnin program:
- the names of the members of your group
- instructions on compiling and running your program
- the static evaluation your program uses,
- the heuristics employed,
- strategy used for minimax and alpha beta pruning,
- results:
- describe which tests you ran to try out your program. Did you program play against human players? Did you program play against other programs? How did your program do during those games?
- describe the strengths and the weaknesses of your program.
- a discussion of why the evaluation function and the heuristic are good choices.
Finding a good static evaluation function and a good heuristic depends heavily on the experience you have with the game. I recommend you start playing the game and getting the flavor of what a good Othello strategy is. Also, research the strategies that other people have used for this and other games. Lots of information can be found in the references listed in your syllabus, the web, and magazine articles.
35 points minimax implementation 15 points alpha-beta pruning 15 points heuristic evaluation function, i.e. function that assigns a number to any intermediate board configuration. 15 points heuristic strategy to avoid expanding the whole minimax tree so that a move is produced within the time limit. 10 points playing "reasonably well" - showing evidence of good offensive and defensive behavior. 10 points interacting well with referee + good documentation ---------- 100 points + Extra points for using machine learning (decision trees, neural networks, genetic algorithms, etc.) to make your system better at playing Othello + Extra points for good performance in the tournament
SUMMARY OF HELP SESSIONS:(By Yakov Kronrod)
Project #3 Helpsession Review 1. Dynamics of the Game -make sure you play it yourself to get an idea of strategies -read up on existing strategies for good hints for heuristics 2. Basic Structure of an Othello Player a-read groupname.in to find out your color b-delete groupname.in c-BLACK will wait until the group2name.in has a move in it -WHITE will chose the first move, write it to group1name.out, and also wait until group1name.in has a move in it (NOTE: At this point the two players behave the same.) while(game is not over) { d-no processing until groupname.in exists with a move in it e-read in the move from groupname.in, validate it, and update your board f-chose the next move according to MinMax with A-B Pruning g-write your move to groupname.out within time limit } 3. List of Preliminary Details (not the juicy stuff) -you must make sure opponent move is valid. If it is not, your program should print this out to the screen and announce itself the victor. -you MUST delete groupname.in after reading it -you have to check who won if the board is filled up (do not depend on the referee) -REMEMBER, the referee is for the tournament. Your program is responsible for the same error checking that the referee performs. -see the referee and email sent out about timing in C. 4. Choosing the next move There are a lot of things that can be said about choosing the next move. In one regard, this is the key to this project, the rest is just a framework. Of course, you will need to use the MinMax algorithm here with alpha-beta pruning. The first step is figuring out what information you need at each node in the tree. 1. The board configuration 2. the level (min/max) in the tree 3. the alpha and beta values 4. perhaps a list of legal moves for children nodes With this in hand, there are several ways to go about constructing the tree and evaluating for the next move. I will provide here an overview of what I consider an effective approach. This method is similar to iterative deepening search. Basically, you want to evaluate the legal-move tree to a certain depth initially, and chose an 'okay' move. Then, as long as there is time available, you search deeper and deeper in the tree, incrementing 1 or 2 levels each time, updating the 'okay' move. Once time runs out, or close to doing so, you write the best move you have found so far to the groupname.out file. As for the implementation of the actual algorithm, I can throw around some ideas. 1. You can either make copies of the board for every single node and actually keep them there in memory (this could get large), or you could find some backtracking scheme to avoid the extra memory usage. 2. In Java or C++, creating a separate class for the board is probably a good idea. That way you can give it functions that will make your code look clean and easy to debug. 3. write separate functions for things such as evaluating a single board, finding the legal moves given a board configuration and color, checking the legality of a single move, reading and writing to the .in and .out files, etc... There are many issues that can arise and many questions that might be trivial to some and impossible to others. Please use the email list wisely and communicate. There are many areas of this project where your classmates could be your best resource.