Using xpai

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

Now, open up the chicken scheme interpreter "csi":
csi -quiet
Load the "xpai" extension:
> (use xpai)
Start xpilot, connected to your local server:
> (xpilot "-join localhost")
Now back in the scheme interpreter type:
> (AIself.x?)
You should get back the x coordinate of the self ship (you don't have to do this every time).
Xpilot-AI calls a function named "AImain" every frame. To control the ship we redefine that function, and tell the ship what to do every frame.
> (define AImain (lambda () (AIself.turn 15)))
Now look at your ship in xpilot. It should be turning 15 degrees counterclockwise every frame. Of course, you can do more complicated behaviors with the ship, and even use machine learning such as genetic algorithms, fuzzy logic, and neural networks. See the xpai Reference for a list of all the available functions.

If you want to put this in a file, you could make a scheme file test.ss:
(use xpai) (xpilot "-join localhost") (define AImain (lambda () (AIself.turn 15)))

Now you just need to run it in csi:

csi test.ss
Or, you may want to make a script file that can be run from the command line, perhaps so you can change the player's name and the server. Here is a sample script named "test":
#! /usr/local/bin/csi -script (use xpai) (xpilot (string-append "-join " (car (command-line-arguments)) " -name " (cadr (command-line-arguments)))) (define AImain (lambda () (AIself.turn 15))) (define endless-sleep-loop (lambda () (thread-sleep! 1) (endless-sleep-loop))) (endless-sleep-loop)

The top line tells the unix shell what program to use to run the script. You may need to change your path on the top line, depending on where csi is installed on your machine. csi running a script will just exit when all the scheme code has finished executing, so we must add an "endless-sleep-loop" to keep the program running. Now change the properties to be an executable:

chmod 755 test

Now run it:

./test localhost jim

Xpilot should launch, connect to localhost, and the ship should be named "Jim" and should be spinning.

Here is a list of valuable xpilot client options which you can use in the command args, the string input to the "xpilot" function. 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.