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:
... where PREFIX is actually your xpilot_ai installation directory, as described above.
Now try to run the program:
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. |
That 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:
This way you can specify the bot's command line arguments at the command line:
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.