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
NOTE - Version 4 of chicken scheme introduced a new module system and other changes that broke the existing bindings. The opportunity was used to create new bindings for Chicken scheme versions 4 and up, with an overhauled API. If you have code that uses the old bindings, using the new ones will not work without modifying your code. If you are starting a new project, the newer bindings, available on the downloads page, are recommended. Instructions and documentation for using the old bindings are kept for legacy code. Unless specified, all example code is written for the newer bindings.
This page has instructions for the chicken4 bindings. For chicken scheme versions 3.6 and below, see chicken3.
Chicken scheme v. 4 and up
To install the xpai for chicken scheme version 4 and up, download the xpai egg for version 4 and install it using chicken-install.
wget http://xpilot-ai.org/downloads/xpai-4.tar.gz
tar xvzf xpai-4.tar.gz
cd xpai-4
chicken-install
Usage
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)
Note: If you are worried about name clashes, you may prefix all of the functions from xpai with a string of your choice like so:
#;1> (require-library xpai)
; loading /usr/lib/chicken/1/xpai.so ...
#;2> (import (prefix xpai xp.))
; ....
#;3> xp.pos
#<procedure (xpai#pos . idx1174)>
See the section on modules on the Chicken wiki for more information.
Start xpilot, and connect to your local server:
#;2> (xpilot-bg "-join localhost")
Now back in the scheme interpreter type:
#;3> (x-pos)
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) (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))
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)
(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.