Introduction
| Driving program
| Tips
What are the basic things I need to know before writing a driving
program?
You must know the basics of C/C++ programming. You must also know the functions
available to control the bots. These functions are declared and defined in the
files aibots.h and aibots.c which are in aibots-x.xx/files . Given below
is a summary of those functions.
01. int init(char *name) : This function is for initializing the bot. This
functions should be called before you do anything else (except, perhaps, some
initializations). You should not call any other functions before you call this
function. When the combat server starts your driving program it will wait for
nearly 1 second for it to call init. Otherwise it will be disqualified. This
function returns only when all other programs have been loaded and they have
called init.The init functions of all the bots return simultaneously.
The init function returns the id of the bot( 0 to 9). The name should not be
more than 18 characters including '\0'. Otherwise it is truncated to 18
characters.
02. void move(int direction,int steps) :
This function makes the bot to move a particular number of steps in a
particular direction. The direction parameter is given in degrees
measured from the eastern direction. Whenever you give a move
instruction the request is sent to the combat server and the
function returns the moment the combat server processes the request.
If your bot is not facing that direction then it will take some time to
turn to that direction and then it will start moving in that direction.
Your bot will stop moving whenever it travels the required number of
steps or hits a wall or another bot. So there is no assurance that the
bot moves the number of steps you wanted it to move.
03. void stop(void) :
This function will stop a bot dead in its tracks.
04. void getinfo(int *x,int *y,int *ismoving,int *life,
unsigned long *lastscan,unsigned long *gametime) : This function is
used to get various information about the bot. x,y are the bot's current
coordinates, ismoving determines whether your bot is moving or not, life gives
the current health points the bot has, lastscan gives the game time at which
one of the enemy bots saw you in a scan and gametime gives the game time at that
instant. If you are not interested in a parameter you can give pass NULL as
argument.
05. void myflagpos(int *x,int *y) :When you call this function, the
position of your team's flag is stored in the addresses x and y. If the flag is
taken by an enemy, x and y will have -1 in them.
06. void hisflagpos(int *x,int *y) :Same as the above function, but
returns the position of the enemy's flag.
07. int whohasmyflag() :This function returns the index of the enemy who
has taken your team's flag. Returns -1 if the flag is not taken.
08. int whohashisflag() :This function returns the index the bot which has
the enemy's flag. It returns -1 if the flag is not taken.
09. int fire(int dir,int range) :This function throws a bomb at the
specified direction and range. If the range is greater than 20, it is truncated
to 20. You can throw bombs over walls. The function returns 0 if a bomb could
not be thrown. This is because you can have only one bomb belonging to you
exploding at a time and you already have a bomb exploding somewhere.(Oh, I
forgot to tell you something. A bomb explodes in 4 stages each lasting for 3
game time.)
10. void scan(int dir,int *playerid,int *range) :This function makes the
scan a particular direction. You can not "see" bots belonging to your team.
You can not see through walls but you can see through your team's players
(because you can't see them). The player index of the nearest enemy bot in the
direction is stored in playerid and the distance of that bot is stored in
range. Both of these will have -1 stored in them if there is no enemy bot in
that direction. You can't see enemies beyond 35 units.
11. int msgsend(int playerindex,char *msg) :This function sends a message
(a string) to the bot with the particular playerindex. Messages that are longer
than 10 character will be truncated to 10 characters. The function returns 1
if the message is sent successfully, 0 otherwise. A message is not sent whenever
the bot with player index playerindex does not exist or it does not belong to
your team (No Spamming!!) or its stack is full.
12. void broadcast(char *msg) :This function sends a message to all the
bots that belong to your team. CAUTION :You will not know whether all the
bots received the message (Some of their message stacks might be full).
13. int msgrecv(char *msg) :This function is used to read the message on
the top of the message stack. The message stored on the top of the stack is put
in msg. The function returns -1 if the stack is empty. Otherwise it returns the
number of messages that remain in the stack after the message is read.
14. int passflagto(int botindex) :If a bot has the enemy's flag, it can
throw it to a nearby team-mate using this function. The flag is passed if the
bot with id 'botindex' belongs to the same team and is not more than 10 steps
away.
15. int newmsgcount() : This function returns the number of unread
messages that a bot had when it last sent a request to the combat server. This is
the only function that is not blocked. Note that this function returns the local
copy of the number of unread messages. This local copy is updated whenever the
combat server is contacted through other bot functions (I mean to say that calling
this function will not update the local copy).
Finally your code should look like this
#include "aibots.h"
<your functions>
int main()
{
<declarations and initializations>
<some int variable> = init("My Bot");
.
.
.
}
Compiling the code
If your code is in C use either
cc -lnsl -lm -o <outputfile> <c file> aibots.c or
./makebot <c file> <outputfile>
If your code is in C++ use either
g++ <c++ file> aibots.c -lnsl -lm -o <outputfile> or
./makebot-c++ <c++ file> <outputfile>
Functions Summary
01 int init(char *name)
02 void move(int direction,int steps)
03 void stop(void)
04 void getinfo(int *x,int *y,int *ismoving,int *life,unsigned long *lastscan, unsigned long *gametime)
05 void myflagpos(int *x,int *y)
06 void hisflagpos(int *x,int *y)
07 int whohasmyflag()
08 int whohashisflag()
09 int fire(int dir,int range)
10 void scan(int dir,int *playerid,int *range)
11 int msgsend(int playerindex,char *msg)
12 void broadcast(char *msg)
13 int msgrecv(char *msg)
14 int passflagto(int botid)
15 int newmsgcount()
Introduction
| Driving program
| Tips
For bugs, queries and suggestions contact :
Arunkumar Subramanian
ee01b115@ee.iitm.ernet.in
(regarding the game engine and the text and graphics displays in Linux)
Sandeep V
ee01b119@ee.iitm.ernet.in
(regarding OS independence and Windows text display).