Using the Xpilot-AI Scheme Bindings
Xpilot-AI has bindings for
See the home page for installation instructions, and the
wiki for documentation.
To install the xpai you can use the chicken-setup utility
provided with chicken scheme.
First, start a server on your machine. See the xpserver tutorial for help.
Now, open up the chicken scheme interpreter "csi":
Load the "xpai" extension:
#;1> (use xpai)
Start xpilot, and connect to your local server:
#;2> (xpilot "-join localhost")
Now back in the scheme interpreter type:
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.
#;4> (define (AImain) (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:
Now you just need to run it in csi:
(xpilot "-join localhost")
;; `xpilot' launches a background thread, so we need to have an
;; infinite loop to keep the program from terminating.
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 -s
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. Now change the properties to
be an executable:
;; change the above to the correct path for your csi installation
;; If we run xpilot in the background, the script will terminate
;; immediately. So we use the "xpilot" function to run until the
;; window is closed.
(if (null? (command-line-arguments))
(xpilot "-join localhost -name test")
(apply xpilot (command-line-arguments)))
chmod 755 test
Now run it:
./test "-join localhost -name Jim"
Xpilot should launch, connect to localhost, and the ship should be
named "Jim" and start 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.
Join server on certain port. Also looks for servers on that port if you do a "local" search.
Name of the player.
Team to try to join once connected to a server.
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.