Introduction to Artificial Intelligence (Fall 2007)/Assignment 2/Programming

From GICL Wiki
Revision as of 12:00, 17 October 2007 by Evan (Talk | contribs)

Jump to: navigation, search



You should downloaded and install the sourcecode for Othello, available here. An Eclipse project for the code should be available soon.

You are to create a new othello-playing agent. Your agent should be implemented as a class extending
Your class should be in a package called "students.lastname" and the class itself should be called "FirstnamesOthelloPlayer." For example:
package students.sultanik;
import java.util.Date;

public class EvansOthelloPlayer extends OthelloPlayer {
  public EvansOthelloPlayer(String name) {
  public Square getMove(GameState currentState, Date deadline) {
    /* Implement MiniMax with Alpha-Beta and return your move choice here */

You must implement, at a minimum, MiniMax search with Alpha-Beta pruning, as is described in Figure 6.7 from the textbook.

NOTE: for this assignment you are not required to implement time-critical reasoning code to interface with the deadline argument. Instead, you may choose to implement a naïve depth-based cutoff in your Terminal-Test function. If you choose this approach, you must decide on a cutoff depth such that your agent takes no more than about 30 seconds to choose a move. Your agent must honor the deadline argument for the competition, however.

Interfacing with the existing API

Creating a new Othello playing agent

Students should first create a new directory for themselves in `src/students/'. This directory name must be unique for each student, so it is suggested that students use their surname (assuming last names are unique among all students in the class). For example, I would create the following directory:

 $ cd src/students
 $ mkdir sultanik
 $ cd sultanik

Inside this directory the student should create a new .java file for his/her othello-playing agent. This filename does not need to be unique, although it is wise to give it a meaningful name. For example:

 $ emacs

The combination of the directory name and the othello-playing agent's class name should be able to provide the professor with enough information to figure out who wrote the code.

The first line of the java file should be a line defining the package in which this class will reside. The package name is not arbitrary; it must be "student." followed by the name of the directory you created above. For example:

 package students.sultanik;

It is then useful to import all of the classes that are related to the Othello game. This is done with the following command:


You will also need the `Date' class from `java.util' in order to handle the deadlines:

 import java.util.Date;

You can then create your class. Each student's othello playing agent must be a class that extends off of OthelloPlayer. The class name must be the same as the filename. Since I named my file "EvansOthelloPlayer," I would create the class as follows:

 public class EvansOthelloPlayer extends OthelloPlayer {

For an example, see `src/students/example'.

Compiling your code

To compile your code, simply run `make` from the root directory. If successful, it should create a new ".jar" file in the "lib" directory named after the directory you created above.

 $ ls lib
 example.jar  othello.jar
 $ make
 $ ls lib
 example.jar  othello.jar  sultanik.jar

Note that running `make` will rebuild a lot of the code, not just your own. This can often be time consuming and unnecessary. To compile just your code, simply run:

 $ make lib/sultanik.jar

where `sultanik' is replaced with the name of the directory you created above.

Note that yourlastname.jar contains only your code. Therefore, you can feel free to trade your .jar files with friends such that you can try your agent against others' agents without fear that they will steal your sourcecode. The other person could theoretically decompile your java bytecode and reverse-engineer your algorithms, but a student with such skills would easily get an A+ in this class anyway so he/she would have little or no incentive to do so.

Running your code

You can manually run your code with the following java command:

 $ java -cp lib/othello.jar:lib/sultanik.jar

A script is also provided for convenience called `othello':

 $ ./othello

This will run Othello with a graphical user interface. If you are running the program "headless" (e.g. over SSH), a console-based user interface is also available. This can be invoked using the command line option `-nw':

 $ ./othello -nw

You may also supply on the command line the list of players that are to participate in the game. Players are specified by their class name. For example, the following command will play a game between my agent and an agent that plays randomly:

 $ ./othello students.sultanik.EvansOthelloPlayer

There is also a HumanOthelloPlayer that will allow the user to control one of the agents through the user interface. To play against one's own agent, one could run:

 $ ./othello students.sultanik.EvansOthelloPlayer

If the players are not provided on the command line the user interface will display a list of all of the possible player classes it found in the classpath.


For a complete list of command line options, simply run

 $ ./othello -nw

A JavaDoc is automatically built each time your code is recompiled. To manually force a rebuild of the JavaDoc, run:

 $ make javadoc

The JavaDoc is built in the `doc' directory.

The remainder of the documentation is located within the JavaDoc.