Fighting Bots API
Quick Start Guide
Using the sample app
Before using the API, one may start off by witnessing a sample run to get a feel for the game. We have provided the platform specific server applications as executable jars and a sample client (which is platform independant).
First, run the server application from the command line with the following command
java -jar <SquaresGameServer<platform>.jar> <board-size-width> <board-size-height> <gui-delay in milliseconds>
eg: java -jar SquaresGameServerLinux.jar 10 10 100
Then invoke the sample client twice to make it play against itself.
i.e, in separate terminals, invoke the command
java -jar SquaresGameSampleClient.jar localhost
You will now be able to witness a match progress between two instances of the sample client.
Building your app
Building your own application using the API is very simple. Just add
the SquaresClientAPI.jar to your build path. In case of Eclipse you
may do this by right clicking on your project --> Configure Build
Path --> Add External Jars and choosing the SquaresClientAPI.jar.

This
is a screenshot of the eclipse project for the sample client. Notice
that the API is in the build path...
Next instantiate a SquaresGame Object. The constructor takes as its parameter the host ip of the server arbiter.
To start a game, call the start function of this object with your name as the argument. This function will return the grid size and starting player info encoded in an object of the type GameInfo (Refer API).
You may use this information, instantiate your own board etc and depending on starting player info, you will either have to call makeMove or getMove functions.
Note that it is your responsibility to figure our an AI to compute the next move, maintain a board to analyze the current board state etc. All the API does is send your move over to your opponent and vice-versa. For example, if you get a box, then you will have to call makeMove again. Similarly if your opponent gets a box, you will have to call getMove, i.e. Give the opponent an extra move. It is therefore your duty to figure out the logical order in which to invoke functions.
Given below is a snippet from the sample client program. Note that this is not the entire sample client code but only the main function, just to give an idea of how to use the API. In case of any ambiguities, please get back to us.
package squares;
/**
* Think of the following class as a demo of using the client API. For now, one may assume the
* SquaresBoard class as a black box implementation of some AI that computes and returns a move.
* Now, one can clearly see how to communicate your move to the server via the API and process
* moves returned by the server with your own AI.
* Note that a binary of this client has been provided for download.
*/
import squaresClientAPI.SquaresGame;
import squares.SquaresBox.Owner;
import squaresClientAPI.Dash;
import squaresClientAPI.GameInfo;
public class SquaresFactory {
public static void main(String args[]) throws Exception
{
/**
* This particular program accepts as its commandline argument the host ip
*/
if(args.length!=1)
{
System.err.println("Usage: SquaresGameRajkishan.jar <hostname/ip of game arbiter>");
return;
}
/**
* This is how we initialize a connection to the server arbiter.
*/
SquaresGame sq = new SquaresGame(args[0]); // Here, args[0] is the host ip
int blah=(int) (Math.random()*100);
String playerName = "Rajkishan"+blah;
/**
* This is how a game instance is started by invoking the start function of the
* SquaresGame object. The function inturn, returns a GameInfo object containing
* grid size and starting player info (a boolean)
*/
GameInfo info=sq.start(playerName);
System.out.println(playerName);
//Here I use my own board representation. I initialize it with the grid size
SquaresBoard board=new SquaresBoard(info.y_no_of_dots,info.x_no_of_dots);
//If I am the starting player, I make a move
if(info.is_starting_player)
{
//compute move is my own function that computes the next move
Dash dash=board.computeMove();
//I update my board with the move I just computed
//Note that from my point of view, I am player 1 and my opponent
// is player 2
board.makeMove(dash,Owner.PLAYER1);
//I now send over the computed move to my opponent using the API
sq.makeMove(dash);
}
try{
//The game loop. I keep track of various conditions to make or get a move and
//invoke the API functions accordingly
while(!board.isFull())
{
Dash dash=sq.getMove();
boolean flag=board.makeMove(dash,Owner.PLAYER2);
if(flag)
{
System.out.println("Opponent got a box");
if(board.isFull())
break;
else
continue;
}
if(board.isFull())
break;
else
{
flag=true;
while(flag)
{
dash=board.computeMove();
flag=board.makeMove(dash, Owner.PLAYER1);
if(flag)
System.out.println("I got a box");
sq.makeMove(dash);
if(board.isFull())
break;
}
}
}
board.printWinner();
}
catch(Exception e)
{
System.out.println((board.player1Score+board.player2Score));
e.printStackTrace();
}
}
}Warning
The above snippet is part of the logic behind the sample client and has been given for clarity's sake. It is not a working standalone Java program. Please do not let the book keeping stuff surrounding the actual code confuse you becuase they are part of the sample client's logic. You may come up with a completely different design and its perfectly ok with us.
The kay steps all clients should adhere to are
Instantiate the SquaresGame object
call the start function
use GameInfo returned by the start function to get grid size and starting player info
call getMove and makeMove in appropriate order. Mistakes here lead to the player being disqualified from that particular game instantaneously.
Submission format
All submissions should be in the form of executable jar files. Please use some tool like Eclipse (or manually write the manifest files if you are hard core) and generate the final executable jar file. This should be free of any non standard dependencies. This means the API's jar should also be repackaged into the jar you submit. What we will be doing to run your program is something similar to java -jar <your-program.jar> ip-address
This implies your program should take a single command line argument, which is the ip-address of the server arbiter application. Again, this does not involve any work on your part. Just pass args[0] to SquaresGame object's constructor as shown in the sample client's snippet above.
Not adhering to these standards will lead to your program not being evaluated.
Please do get back to us in case of any (even trivial) doubts.
Naming conventions
Please name your jar file as <userid>_<yourname>.jar