Using the Xpilot_AI C Library

First, start a server on your machine. See the xpserver tutorial for help

Now, create a file named "testbot.c", and type or paste the following into it:
#include "xpilot_ai.h"

int main(void) {
  AI_xpilot_setargs("-join localhost -name testbot");
  AI_xpilot_launch();

return 1;
}

void AImain(void) {
  AIself_turn(15);

  return;
}
Now save the file and try to compile it. To compile it, all that is needed is your c file, testbot.c, the xpilot_ai library, and the xpilot_ai.h include file. If you've installed xpilot_ai as root, the command to compile should just be:
gcc -o testbot testbot.c -lxpilot_ai
If you installed Xpilot-AI to some other non-default directory, then you may need to specify to the compiler where to look for the xpilot_ai library and the xpilot_ai.h include file. If during installation you ran the "configure" script with the option "--prefix=PREFIX", then the library file is in PREFIX/lib and the include file in PREFIX/include. Here is the command you should use to compile the testbot program:
gcc -o testbot testbot.c -lxpilot_ai -LPREFIX/lib -IPREFIX/include
... where PREFIX is actually your xpilot_ai installation directory, as described above.

Now try to run the program:
./testbot
If all goes well, the program should open up an xpilot window that is connected to your local server. Your bot should be spinning around in place.

Let's take a look at the testbot.c source code:
#include "xpilot_ai.h" includes header file that declares all the xpilot_ai functions
int main(void) {The "main" function, which is called when the program first starts. Use this to set initial settings and join a game.
AI_xpilot_setargs("-join localhost -name testbot"); Sets what would normally be command line arguments to the xpilot client. In particular, we are joining the server we started on localhost and giving the ship the name "testbot".
AI_xpilot_launch(); Launches the actual xpilot client. The function keeps running until the game is quit.
void AImain(void) { The xpilot client calls "AImain" every frame of gameplay. By redefining it here, we can take control of the ship.
AIself_turn(15); This turns the ship 15 degrees.
This bot is pretty unintelligent, but look at the complete Xpilot-AI C Library Reference to see all the information you can gather about the environment in order to intelligently control your ship. You can also make new functions and libraries to use with the xpilot_ai library to do such things as evolution, neural networks, and fuzzy logic.

A good idea is to use the command line arguments for your bot and set them directly as the xpilot client's arguments. Here is a little example:

int main (int argc, char **argv) {
  AI_xpilot_setargs(argv[1]);
  AI_xpilot_launch();
  return 1;
}
This way you can specify the bot's command line arguments at the command line:
./testbot "-join localhost -name testbot"
Joins same as before
./testbot "-join localhost -port 1337"
Joins localhost on port 1337. This way you can have multiple clients/server combos on one machine.
You can also join your ships to the internet to play against other bots and other real players. The bots only seem to work on the slower framerate servers (like under 20 FPS).

Here is a list of valuable xpilot client options which you can use in the command args. For a complete list, look at a copy of the Xpilot Manpage. You can use any of those options with Xpilot-AI.

-port integer
Join server on certain port. Also looks for servers on that port if you do a "local" search.
-name string
Name of the player.
-team integer
Team to try to join once connected to a server.
-display :integer
X windows display number on which to run Xpilot. You can run a video framebuffer with the command Xvfb and then connect to that screen with this option (takes less CPU). For example, run the command Xvfb :1 -screen 0 1024x768x8 -auth noauth, which will start a screen on :1. Then use the option "-display :1" to run the xpilot client on it.