HW1
Assignment
In this homework you will implement a agent that can play the game checkers. The aim is to get a deep understanding of for the methods for solving a game. You will focus on calculating what move to make. The representation of the board and the rules of the game will be handled by the skeleton that you will be provided with.This is an individual assignment.
Submission
You submit your solution to a system called Kattis. Click on "Courses" and select ai14. Please read the documentation about Kattis to learn more if you have not used it before.
The portal will not show your Kattis result until we run the update. You have to register for the course in Kattis, else your submission will not be recognized and you will fail the assignment.
Direct link to Kattis submission for HW1.
Code skeleton
We provide code skeletons in Java and C++ that you should use as a starting point when writing your program. This allows you to focus on the core AI bits.
NOTE: You cannot modify any files but the Player class file among the files provided by the skeleton. When you upload to Kattis, all skeleton files but this(java)/these(C++) file(s) will be overwritten. This/these files are the only files from the skeleton that you need to upload, the rest are there already. You can add more files if you want.
Testing outside Kattis
You can test your agent by making it play against the agents of your friends or itself. The first step is to make sure that you can consistently beat the agent that is defined by the skeleton. This agent picks a random move from all available moves in every iteration.
The agents use standard input and output to communicate. The Moves made are shown as unicode-art on std err if the parameter verbose is given. The following sections show how you can test your agent on a Unix/Linux/Mac OS X system. If you use Windows please read further down.
To play in a single terminal
Assume that agentX is your C++ agent which is in the current directory together with another agent called checkers. First you have to set up a pipe for them to communicate with
mkfifo pipe
which you do this once only.
Now you can make them play with
./agentX init verbose < pipe | ./checkers > pipe
The agent that issues "init" will be WHITE (one of them have to issue "init". IMPORTANT: Exactly one agent should issue "Init"
If you want to test a Java client with one of these you would do
java Main init verbose < pipe | ./agentX > pipe
Testing in two terminals
To play in two different terminals (so that we can tell who does what in an easier way) you would have to create two pipes with
mkfifo pipe1 pipe2
which you do only once.
In Terminal 1:
./checkers init verbose < pipe1 > pipe2
In Terminal 2:
java Main verbose > pipe1 < pipe2
NOTE: If you run in two different terminals or directories, make sure that you use the same named pipes for both agents. That is if agent1 writes to pipe1 (">") then agent2 must read ("<") from the same file. You can specify the full path of the pipe to make sure hat you use the same pipes.
NOTE: If you work on for example the lab computers that use the AFS filesystem you cannot create named pipes like above. BUT you can create your named pipes in the /tmp directory.
mkfifo /tmp/mypipe
and then replace pipe above with /tmp/mypipe
Windows users
If you want to run your code in windows with the above technique you can use Cygwin.
C++
If you want to be able to compile your C++ code in cygwin you should select the gcc-g++ package. You find it easy with the search function on the screen that lets you select additional packages during the installation.
Java
Install the JDK on your Windows machine. In cygwin you need add the path to the java executables with something like
export PATH=$PATH:/cygdrive/c/Program Files/Java/jdk1.7.0_40/bin/
Advanced use
You can run your agent directly in the terminal without any pipe, for example, for debugging/testing purposes. Start the agent
./agent verbose
and then paste in a board state message in the terminal and press ENTER. When you run an agent in verbose mode you see the board state message together with the graphical representation. This what you should pass into your agent. You can also do this by putting such a message into a file (make sure to have an end of line) and do
java Main verbose < file.txt
If you use eclipse you can use the same method as described in the BPT to send files into your program.
The start state is represented by the following string
rrrrrrrrrrrr........wwwwwwwwwwww -1 r 50
where the first 32 characters describe the board state, -1 says that the game just begun, r says that it is RED's turn and 50 says that it is at least 50 reversible moves until draw.
Grading
Kattis will give your agent a number of board states and will ask for the best move for each state. You will be scored based on these answers. The states are selected in or near the end game and the states represents situations where the answer makes a big difference for the outcome of the game. Note that you are not playing a full game as you would when you play against a friend or yourself.
You can get up to 25 points and we require you to get at least 10 to pass this assignment.
Minimum requirement
You need at least 10 points to pass the course