Othello (Reversi) is a two-player game using 8×8 board of 64 squares and 64 identical discs. The discs are black on one side and white on the other. Each player takes 32 discs and chooses one color to use throughout the game. The object of the game is to have the majority of your discs on the board at the end of the game.
In your prelab you thought of some strategies for playing Othello. Now it is time to implement a strategy for your own personal Othello Bot.
Download lab10.zip and extract its contents to the cps001 subdirectory of your public_html folder. You should now have a folder in your cps001 directory named lab10. Open the lab10 folder. Follow the directions below.
Find the file named YourOwnStrategy.java and right-click on it to rename it. You can name it anything you want, as long as it would be a legal Java identifier. Go to the Class Applications folder on your Desktop and use the link inside to start emacs. Open the file you just renamed. It should look like this:
Change the class name YourOwnStrategy to match the name of your file. Check spelling and capitalization.
In the getName() method, replace I_need_a_NAME with a name for your Othello Bot. Make sure to leave the quotation marks in place.
Save your file and compile it.
Now open the file in your lab10 folder named Othello.bat. Change YourStrategy to match the name of your class and java file. Save the file and close it.
To run Othello we need to start a client program and a server program. You start these by double-clicking on the files Othello.bat and Server.bat in your lab10 folder. You will see two command windows appear and a "Connection" dialog box for connecting to the Othello server and loading your Bot. Click on the OK button to start Othello.
In the Control Panel of the Othello program you will see a player list, with your Bot included. To see how your Bot performs, select one of the names from the list and click "Match". The two Bots will play each other while you watch.
Your Bot will most likely lose to all the Players. This is because he isn't programmed to do anything smart yet. All he does is return zero in the evaluate method.
Each of the Bots is already programmed with a specific strategy. The RandomBot's strategy is not to have one, it just assigns random values for evaluate. The GreedyBot's strategy is to make moves that give him the largest number of discs. The CornerBot assigns high values to the four corner positions and zero values to all others. The remaining Bots are somewhat smarter than these three!
What you need to do is implement the strategy you designed in your prelab (plus anything else you may have thought of). Your code will go in the evaluate method of your strategy.
The evaluate method is as follows:
The input parameters are the column and row corresponding to the move you are evaluating and the game board that results from making that move. The rows and colums of the board are indexed from 1 to 8 in both dimensions. The method returns an integer value. This value corresponds to the value assigned by your heuristic or evaluation function. You need to declare a variable to represent it, assign it a value accordingly, and return the value inside the evaluate method.
You can get started by programming a heuristic that assigns high values to the corners. By the indexing of the game board, the coordinates of the corners are (1,1), (1,8), (8,1) and (8,8). It is up to you to decide what value to assign to these positions. Suppose we assign a value of 5 to the corners. Your implementation could be as follows:
This means if the col,row position we are evaluating happens to be a corner, we will assign it a score of 5. If it is not, it gets a score of 0. This is just an example for you to follow if you are having trouble getting started, you do not have to use it at all or you can change or modify it as you wish.
After you have typed in your code, save and compile.
Now that your Bot has some "intelligence", let's see how he fares against the others. If you still have the Othello game running, click the Quit button on the Control Panel to stop it and double-click on Othello.bat to load your new and improved Bot. He should be able to beat the RandomBot and GreedyBot with no problems, and likely the CornerBot too. Can you win playing against any of the others?
Chances are, your bot isn't good enough to win Othello against all of the other Bots. This means you have to come up with a better heuristic for evaluating your moves. There are many methods provided for you in the Othello code to extract information from the game board. Here are some you may find useful:
board.player()
returns an integer
representing the color of the current player (WHITE or
BLACK)
board.opponent()
returns an integer
representing the opponent's color, which is the opposite of the
one returned by the method above (BLACK or
WHITE)
board.numDiscs(board.player())
returns the
number of discs the player has on the board
board.numDiscs(board.opponent())
returns the
number of discs the opponent has on the board
board.disc(c,r)
returns WHITE,
BLACK or EMPTY for an input column c
and row r
board.isEmpty(c,r)
returns true
if the position at column c and row r is not
occupied and false otherwise
board.numOccupied()
returns the number of
occupied squares on the game board
board.numEmpty()
returns the number of
occupied squares on the game board
board.numMoves(board.opponent())
returns
the number of moves your opponent can make at the next turn
These methods should make your implementation a bit easier. After you have written your code, compile and test your heuristic. For full credit on this lab, your Bot should be able to win against RandomBot, GreedyBot and CornerBot with no problem and also against the majority of the remaining Bots in a majority of the games.
On Monday we will have an Othello Bot Tournament in class. The contestant pool will be composed of student Bots only. To get an idea of your competition, you can download an updated zip file (updated post-class on 6/18) containing the most recent versions of your classmate's Bots here. Unzip the file to your lab10 folder. It is okay to say "yes to all" when WinZip asks you to confirm file overwrite. None of your own files will be overwritten.
The programmers with Bots finishing in second and third place will receive 4% and 2% extra credit on the final exam, respectively.
You can work on your program in class today and as much as you like
over the weekend. Your Bot must be in working order at class time on
Monday to be able to participate, so you may want to keep a backup file of
a working version if you are planning on "fine-tuning" your code to any
major extent.