Difference between revisions of "Introduction to Artificial Intelligence (Fall 2007)/Assignment 2/Programming"

From GICL Wiki
Jump to: navigation, search
 
 
(3 intermediate revisions by one user not shown)
Line 1: Line 1:
 +
[[Category:Introduction to Artificial Intelligence]]
 +
[[Category:Assignments]]
 +
 
==Instructions==
 
==Instructions==
  
Line 25: Line 28:
 
agent takes no more than about 30 seconds to choose a move. Your agent must honor the deadline argument
 
agent takes no more than about 30 seconds to choose a move. Your agent must honor the deadline argument
 
for the competition, however.
 
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:
 +
 +
  $ vim EvansOthelloPlayer.java
 +
 +
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 "students." 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:
 +
 +
  import edu.drexel.cs.ai.othello.*;
 +
 +
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
 +
  [... PRINTS OUT A LOT OF JUNK ...]
 +
  $ 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 edu.drexel.cs.ai.othello.Othello
 +
 +
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 edu.drexel.cs.ai.othello.RandomOthelloPlayer 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 edu.drexel.cs.ai.othello.HumanOthelloPlayer 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.
 +
 +
===Documentation===
 +
 +
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.

Latest revision as of 08:29, 18 October 2007


Contents

Instructions

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

edu.drexel.cs.ai.othello.OthelloPlayer
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;
import edu.drexel.cs.ai.othello.*;

public class EvansOthelloPlayer extends OthelloPlayer {
  public EvansOthelloPlayer(String name) {
    super(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:

 $ vim EvansOthelloPlayer.java

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 "students." 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:

 import edu.drexel.cs.ai.othello.*;

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
 [... PRINTS OUT A LOT OF JUNK ...]
 $ 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 edu.drexel.cs.ai.othello.Othello

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 edu.drexel.cs.ai.othello.RandomOthelloPlayer 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 edu.drexel.cs.ai.othello.HumanOthelloPlayer 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.

Documentation

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.