Navigation: Table of Contents, Index, next: BBDB Elisp Code, prev: Emacs Games

pRobot: Robots for Python

by Christian Rusche

Overview:

Introduction

pRobot is based on eRobot by Alexander Schröder. The original eRobot is written in Lisp. I liked the concept, but it was easier for me to transfer the code to Python than to learn Lisp. Some rules were changed, but I tried to maintain the main idea.

[screenshot]

pRobot is something like Pokémon for computer scientists. Each player creates a computer program, a so-called pRobot. Then all the pRobots are thrown into a virtual arena, the war-ground. Within that arena they can walk, reproduce, and fight. All actions are computed by the pRobots without communication with the player. The pRobot that stays alive is the winner of the game.

Tournaments

Up to 10 players can enter the contest. Each player starts with one pRobot. The war-ground is a rectangle with some obstacles. The pRobots are placed at random on the war-ground. Then one Robot after the other can perform its action. After 1000 such turns, or when the pRobots of only one player remain, the round ends and points are distributed:

After 10 rounds, the player with the most points is the winner. If a pRobot tries to change some variables of the war-ground or uses other methods not described in this document, the player is banned.

Commands

Each pRobot can perform three different commands: move, make and nothing. The commands move and make need a direction parameter, i. e. up, down, left or right. Combined directions like upper left are not allowed.

move

This command allows the pRobot to move on the war-ground. The result depends on the target field:

make

This command builds a pRobot on the target field. The 'memory' (instance variables) of the pRobot are not copied. The result depends on the target field:

Only 10 pRobots (including the first one) can be made in one round.

Bits and Bytes

The following chapters should show what is needed to program a pRobot, and which functionality is already provided by the pRobot environment.

Files

To play pRobot for Python you need pRobot and Python. There are three pRobot files:

The best way to get Python is www.python.org, where you can also download Tcl/Tk, which is needed to run pRobot. For Windows users the IDE PythonWin is recommended. I use version 1.5.2 of Python and version 8.0 of Tk.

Making a pRobot

To make a pRobot, you only have to program a class derived from the base class robot. The only class function that you are allowed to override is compute. This function is called by the warground. compute has to return 2 string values. The first return value can be 'move', 'make' or 'pass'. The second can be 'up', 'down', 'right', 'left' or 'pass'. Therefore the easiest pRobot is:

class stupid(robot):
    def compute(self):
        return "pass", "pass"

The robot class has some variables and functions that can be used by the pRobot:

The class clan has also some variables:

All these variables are private: no changes are allowed.

The API

The variables and functions shown in the chapter 'pRobot' would theoretically be sufficient to program a pRobot. The class robot has some functions that makes it easier to make an pRobot, however. These functions are all based only on the variables and functions already mentioned. Three types of functions are available.

Clan functions:

pRobot functions:

Other functions

All listed functions are members of the class robot.

Sample Implementation

The following sample shows a possible function:

class wolf(robot):
    def compute(self):
        if self.can_make() > 0:
            return "make",self.dir_random()
        else:
            if self.get_clan_target() not in self.get_robots():
                self.set_clan_target(self.get_closest_enemy())
            if self.get_clan_target() == None:
                return "pass", "pass"
            else: 
                return "move", self.get_clan_dir()

This wolf uses the 'make' command until the function self.can_make() returns 0, that is when make limit is reached. Then it checks if the clan target still exists. If there is a possible target, the wolf goes in this direction, if not - normally at the end of the game - it stands still.

Finally...

If you would like to play a round pRobot or if you have comments to make please, mail me (c.rusche@bsiag.com). Good API functions and samples for this page are always welcomed.

I would like to thank Alex for the inspiration and the support he gave me during the development of pRobot.


Navigation: Top, Table of Contents, Index, next: BBDB Elisp Code, prev: Emacs Games


http://www.geocities.com/kensanata/robots/index.html / Alex Schroeder <kensanata@yahoo.com> / updated: 2001-02-15 / significant changes: 2000-08-10

1