Using the Xpilot-AI Scheme Bindings
Xpilot-AI has bindings for
Chicken Scheme.
See the home page for installation instructions, and the
wiki for documentation.
xpai installation
To install the xpai you can use the chicken-setup utility
provided with chicken scheme.
chicken-setup http://xpilot-ai.org/downloads/xpai.egg
Usage
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:
#;1> (use xpai)
Start xpilot, and connect to your local server:
#;2> (xpilot "-join localhost")
Now back in the scheme interpreter type:
#;3> (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.
#;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:
(use xpai)
(xpilot "-join localhost")
(define (AImain)
(turn 15))
;; `xpilot' launches a background thread, so we need to have an
;; infinite loop to keep the program from terminating.
(repl)
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 -s
;; change the above to the correct path for your csi installation
(use xpai)
(define (AImain)
(AIself.turn 15))
;; 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)))
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:
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.
-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.