In this lab, we'll learn how to program a team of robots in the Guntactyx game, and by so doing, we will see how sensory and motor functions work in a basic reactive animat (or bot, as they are called in Guntactyx). If you are working from home make sure you can find the Guntactyx folder and operate the game before going any further. Refer to the
GUN-TACTYX-readme.htm and GUN-TACTYX-manual.htm files in the Guntactyx folder throughout this exercise.
Guntactyx is a programming game, which means that you can write scripts to control the behaviour of a team of bots. Up to four teams can play different kinds of games, including fighting, racing and a soccer match. Scripts are written in a C-like language called Small. You can use any kind of text editor to create and modify Small scripts (but choose one which does not insert special characters into the text eg. Notepad, not Word.)
Script files are saved into the \bots directory with the extension .sma.
Find this directory and open the file recruit.sma to see what such a script would must look like. The code is usually organised as one or more top-level functions: fight(), soccer() and possibly race(), as well as any service functions which these call. At the bottom of a script is the main() function, which is always called first when any Small script is executed. All this does is transfer control to one of the top-level functions. You switch between these modes from the options panel (press '0' from the main panel) by pressing the K key.
The code syntax is similar to a simple C program, but some with some differences. One main difference is that variables are not typed but tagged, which makes a difference to the way variables are declared (uses the keyword 'new') and used. Also, you don't need to terminate a line with a semicolon (but you may do so). There is no real object-oriented code here - functions are simply called in order beginning with main(). from For details of how to write Small programs, read the Guntactyx manual Part 1.
A very important part of any reactive AI program is the set of perceptual inputs and motor outputs in the world . In virtual game environments like Guntactyx, these correspond to get properties and action functions in the API (Part 3 of the manual). As your read through these functions to learn what sensors and actuators are available to your bots, pay particular attention to those that were used in the recruit bot.
Another thing a reactive AI program needs is a method or algorithm to map perceptions onto actions ie a way of deciding which sensed situations release which behaviours.
Sometimes non-perceptual internal variables such as time also release behaviours. The method or algorithm should also arbitrate in the case of a conflict: if two conditions call for opposite actions, it must resolve this (see Champandard, p. 43). The simplest method is some kind of lookup table which simply specifies some code for each sensed condition of interest. Arbitration depends on how this is implemented. When an if-elseif structure is
used, as with recruit, the first matched percept-action pair will get control of the bot.
When you run the game, at least two scripts will be running: one controlling each of the teams you have chosen by toggling the A, B, C and D keys. For our purposes, it is better to keep the number of teams to 2 (T key), and the number of robots in each team around 2 to 4 (N key), depending on the processing power of your machine. This keeps things from getting too complicated to observe and also stops play from going into slow motion if your processor isn't that fast. For fights it is also a good idea to set the goal to 'Enemy
Team Terminated' (G key) and set Timeout to '3600' (O key) so play doesn't end too quickly, giving you time to observe. You can save your options by pressing the X key before quitting from the options panel.
Questions
1. Explain in detail how the recruit bot deals with obstacles. How does the sight() function work? When an obstacle is sensed, exactly how is the direction to turn calculated?
2. Alter the script to allow the recruit team to hear an enemy gunshot and react when no enemy is seen. A gunshot sound could be defined by a logical OR between the concepts of enemy and gun (see manual section 3.3):
new const ENEMY_GUN = ITEM_ENEMY|ITEM_GUN
You will need a new perceptual function to detect the sound. Don't forget to declare any variables the function needs. The reaction can be any observable motion or speech, but an appropriate act might be to turn toward the direction of the sound. Save this improved bot as recruit2.sma.
3. From a scientific point of view, how would you measure the performance of one of these bots? The game displays several score statistics for a game, including shots fired, number of kills and energy consumed. What are the strengths and weaknesses of these scores for our purposes? Could these be combined by a formula into a single number describing 'quality of bot behaviour', or would such a number be misleading? Create an evaluation method which will give one or two numbers indicating true bot performance.
4. Is your modified bot deterministic in practice? How do you know? If so, a single trial could properly measure its behaviour. If not, you should repeat the trial at least 10 times and average the measurement(s) , since any one trial might not be representative. What score do you obtain?