How to write a bot
All about Maps
Winbots API and Tips
Common Errors

Here are the list of functions that you can use in your bot.

1. public int init(String name)
Before your program does anything else (except perhaps a few initializations), it should call the init function with the NAME of your bot. This function will block till the game starts. After you've called the function, the server does not allow the function to return until all the bots have been loaded. After that, when the game is about to begin, it lets the init functions of all the bots return simulaneously. So, ideally a call to init should be your first statement. This function returns the total number of players in the map.

2. public void move(int dir,int steps)
This is the function which controls your bots movements. As it suggests, it asks the combat server to move your bot in the direction specified by dir (in degrees) and for a distance specified by steps. Please note that it is not guaranteed that you'll be able to move those many steps since you could hit a wall, another player or die while moving. In all these cases, you'll stop moving. If you generally want to move in a direction and don't want to stop, give an arbitrary high value for steps like 500. And one more thing, if you call this function, if your bot isn't facing the direction dir it'll be made to turn in that direction which might take some time cycles.

3.public void stop()
This one's pretty simple to understand. It just stops your bot dead in its tracks.

4. BotInfo getBotInfo()
This function returns assorted info about the bot. The BotInfo class contains the following fields
		class BotInfo	
			int health; //Your bot's current health
			int hx;	    //The health package's current x coordinate
 			int hy;     //The health package's current x coordinate
			int posnX,posnY; //Your bot's current location in the map
			long gameTime;   //How much time has progressed since start of game
			boolean isMoving; //Is bot moving or has it stopped.
You may use the getBotInfo() method like BotInfo bInfo=getBotInfo(); System.out.println(bInfo.posnX);

5. boolean isFlag(int x,int y)
This is a pretty useful function. It'll tell you if there's a flag at the co-ordinates (x,y). Since you have the map before hand and know where all the flags are, you can use this function to determine which flags have been taken. Initially, all flags in the map will return true, but if any other bot has taken the flag, it will return false for the corresponding flag.

6. boolean isFlagMine(int x,int y)
This function tells you if you have taken the flag at the specified position. 7. int scan(int dir)
This is another crucial function. It returns the distance to nearest player in the direction dir. If no player can be found in that direction, it returns -1. Now there are two things that you should remember about this function. The second thing is that the scanning resolution is +/- 5 degrees. This means that the function will return the range of a player even if the angle that it makes is within 5 degrees of dir.

8. int fire(int dir,int range)
This throws a bomb in the specified direction and range. Range can be 20 at max. If it's more than 20, then it'll be truncated to 20. You can only have one bomb exploding at a time. Also, bombs can be thrown over walls. The function returns 0 if the fire failed (mostly because you have another bomb exploding somewhere).

That's it about the functions. If you care how these are available to you, BaseBot is an abstract base class that contains the implementation of all the methods given above(init,fire,scan etc..) and contains the abstract method start(). Your class is dynamically instantiated at run time and the start() method is called using reflection API.

Tips and Tricks
  • Take a good look at the samples available. They'll help you a lot in understanding the basic mechanism
  • It's your strategy that matters. Choices include the order in which you fetch the flags, concentrating on killing others more than capturing flags, the sky is the limit..