Minimax Reversi

Getting the Files

The game uses a JAR file and configuration file.  Both of these are in the directory reversi under the course directory:

/cse/courses/csep573/04au/reversi

They can also be downloaded directly from the web here:

reversi.jar

reversi.properties

The configuration file must be found in the directory from which you run the game.

Running the Game

To run a sample game, type:

java -jar reversi.jar ZeroEvaluator ScoreEvaluator

A window should pop up to showing the computer playing a game against itself.

The two arguments after the JAR file are the names of classes that evaluate board configurations.

If you want to play against one of these evaluators, use Human as one of the names:

java -jar reversi.jar Human ScoreEvaluator

Black always plays first in Reversi, and the game randomly assigns a player to black.  If you want to control which player gets to go first, use the -o option:

java -jar reversi.jar -o Human ScoreEvaluator

The players will then play in the order that they are passed in.  (So the human would be assigned black in the previous example.)

Creating a New Evaluator

As mentioned above, ZeroEvaluator and ScoreEvaluator are the names of two classes that provide evaluations of boards that are used by the minimax search algorithm. 

ZeroEvaluator always returns 0, no matter the contents of the board.  ScoreEvaluator just returns his score minus his opponent's score.

Obviously, much better evaluation methods can be devised.  Your job is to come up with one and create a new evaluator class that implements it.

To create a new evaluator you just need to create a class that extends ReversiEvaluator.  Leave your class in the default package (don't give it a package name), which in turn means you have to keep it in the directory from which you run the game.  If you keep all the files you download or create in one directory, everything will work fine.

Your class will have to provide two methods:

public String getName()

This method returns the name that will be displayed in the window for your evaluator.

public int evaluate()

This method returns your evaluation of the board.  Helper methods that give you information about the board are described below.

The source for the sample evaluators is in both the course directory and here on the web, so look to them for guidance:

ScoreEvaluator.java

ZeroEvaluator.java

To compile your class, make sure to include the game JAR file in the classpath for your Java compiler.  For example:

javac -classpath reversi.jar MyReversiEvaluator.java

Board Information

You inherit several methods from ReversiEvaluator to tell you things about the board.  You can call these methods from anywhere in your class (look in the source for ScoreEvaluator to see two examples.)

int boardSize()

The length of one side of the board.  The board is always square.

boolean iHaveSquare(int x, int y)

Whether you control square (x, y).  Square indices start at 0 and go to board size - 1.

boolean iMustPass()

Whether you must pass (always returns false if its not your turn).

boolean isDraw()

Whether the state is a draw.

boolean isEmpty(int x, int y)

Whether square (x, y) is empty.  

boolean isLoss()

Whether the state is a loss for you.

boolean isMyTurn()

Whether it's your turn.

boolean isWin()

Whether the state is a win for you. 

int myScore()

How many squares belong to you.

int numberOfPossibleMoves()

How many moves can be made from this state.  Best used in conjunction with isMyTurn().

int numberOfMyMoves()

How many moves you could make from this state, regardless of whether it's your turn.

int numberOfOpponentsMoves()

How many moves your opponent could make from this state, regardless of whether it's his turn.

boolean opponentHasSquare(int x, int y)

Whether your opponent controls square (x, y).

boolean opponentMustPass()

Whether your opponent must pass (always returns false if its not his turn).

int opponentsScore()

How many squares belong to your opponent.

Experimenting with the Search

The file reversi.properties is a configuration file that controls several parameters of the search.  These apply to both players' searches (excluding, of course, a human player).  The parameters are explained in comments in the file itself.

Getting Help

As always email any any questions and bug reports to Danny:  danny@cs.washington.edu.