AUTOWAR - a game for programmers

In this game you do not control objects immediately by yourself. You program your army of robots before a battle. When a battle is started, you can only watch, if you program your robots good or bad.

Combat area

Combat area is a square 40x40 (or 30x30, 20x20, 15x15, 10x10) without walls (moving over a bound to the other side of a square is possible). At the same time up to 4 robot teams are taking part colored with different colors. A game is started when a single robot of each team is placed on the desk.

Program structure

A program for a robot (actually, for entire army of your robots) cosists of text lines like following:
label: COMMAND[operation][number][label] ...

where:
   
label - any identifier (only small letters). Must start the line, if present.
   
number - used in some operations for comparison and assignment
   
operation - ariphmetic operation '+' or '-', comparison operation '<' or '>' or assignment operation '='. Operation can be present only in some commands, when  a variable or pseudo-variable is located left from the operation.
   
COMMAND - a command (capital letters only, and only the first character is taken into account). See a list of commands below.
   It is possible to use character '.' to separate different parts of the command from each other.

It is possible to write comments in any line starting it from a character '*'.

Commands are separated by spaces. A label can be present in any command, but it can be omitted. If the are no label present, a condition is not analysed, and always next command is executing.

Each command requires 1 time step, or 1/2, 1/4, or 1/10 of time step to execute. A command, which requires 1 time step, must be executed during the whole 1 step. Such are moving and attack commands. For a single step, up to 4 commands, requiring 1/4 of time step, could be executed, or up to 10 commands, requiring 1/10 of time step. If time step is not yet elapsed, but a command found which requires a whole time step, or least of a current step is enough to execute it, then executing a program for a robot is stopped, and such command will be executed on the next time step.

Energy units amount defines a period when a robot is living. When amount of energy becomes 100, robot is reproduced while moving forward, and energy is divided between a parent robot and its child (which is appearing on a position where its parent just left). A child program is started from the beginning, but all its internal states (variables, messages memory) are inherited. When amount of energy becomes 200, accumulating of further energy is stopped.

Commands:

Movements. After a movement command execution, following command is executed, if robot moved successfully. Otherwise, a jump to a label is performed (if it present).
FORWARD - move forward.    1 time step. Success: +2 energy units. Failure: -1 energy unit.

    When moving forward successful, and amount of energy becomes 100, a robot is reproduced. Its child remain on a cell, where a robot was located at the start of movement. It has 50 energy units initially (and amount of energy of its parent decreased onto 50 units). All registers for child robot has initially the same values as for its parent. Since this, it is possible to inherit some tactics, passing it through registers X, Y, Z. For a child robot, program execution is started from the first command, call stack also is not copied (it is empty initially).

Rotations. After a rotation jump to a label is occur if a cell in front of the robot is not empty. Energy is not changed.
LEFT            1/2 time step
RIGHT           1/2 time step
BACK - rotate 180 degrees      1 time step
WHERE - rotate to the left or right randomly, or to the side of the last heard message source. 1 time step (any case).
Attack. Failure (and jump to a label if any) is an attack of allied robot, or if a cell been attacked is empty.
ATTACKlabel - attack a robot in a front cell. 1 time step. Success: +E energy units, -E energy units. E depends on direction of an attacked robot. An attack to the back is most efficient (E=20), an attack to the right or left side is less efficient (E=10), and attack to the front gives E=5 only. In case of failure (attacked cell is empty, or allied robot is attacked): -2 energy units, with jump to a label.
Pause.
PAUSElabel - 1 time step. +2 energy units. A jump to a label, if an anemy appear in a front cell (as in the command IFENEMY).
Contacts with allied robots. Using command S[END], a message can be send to the all robots at the given distance, and it is stored in a register of the last received message. Using command H[EAR] robots can read the last received message.
SENDnumber.label - send a message. 1/4 time step. -1 energy unit. In differ to the most other commands, a label is used not to change execution, but as a message which is sending to allied robots. Since other robots (of the same army) have the same program, it can use received label to jump to it (command HEAR). A number can be used as a parameter to change a distance, on which a message is received by allied robots. If a distance is not specified, or 0 specified, distance 4 is used. The robot which is sending a message, is not receiving it itself.
HEARlabel - hear last message received. 1/4 time step. Energy units are not affected. If success, a subprogram called starting from a received label. If failure (no messages received) a jump to a label occur (if any specified). For a message received, source coordinates are stored, to use it in command WHERE to turn to a side of message source, and in command DISTANCE (also pseudo-register DISTANCE is available) to analyse a distance to the message source.
TRANSFERnumber.label - transfer specified amount of energy to allied robot in front cell. 1 time step. If failure (there are no robots in front cell, or enemy there) energy decreased to 1/10 (but not less then 1 unit) of energy specified, with a jump to a label.
To store current coordinates, a command ORIENT can be used also.
ORIENTlabel - store current coordinates as well it would be got using command HEAR. 1/4 time step. Later coordinates stored can be used in commands DISTANCE and WHERE e.g. to return to a point. Jump to a label if a cell front to the robot is not empty.
Program execution controlling. Such commands require just 1/10 of time step to execute.
GOTOlabel - jump to a label specified.
CALLlabel - call a subprogram, started with a label specified.
QUIT - return from a subprogram.
KILLnumber - pop a specified amount of return points from call stack. If a number is not specified, or 0 specified, 1 return address is popped. Failure (and jump to a label) if no return points in stack.
Comparing some values with given one or counting enemies or allies. All such commands require 1/4 time step.
DISTANCEnumber.label - if a distance to the source of the last message heard (coordinatess stored using ORIENT) is less then number, jump to a label. Also possible variants: D<number.label and D>number.label
ENERGYnumber.label - if energy units less then number, jump to a label. Following variants also are possible: E<number.label and E>number.label
MYARMYnumber.label - if amount of allies in four neighbour cells less then number, jump to a label. Also M<number.label, M>number.label are possible
NUMBERnumber.label - if amount of enemies in four neighbour cells less then number specified, jump to a label. Also N<number.label, N>number.label are possible (the last form much more useful in most cases).
IFENEMYlabel - if an enemy in a cell front to a robot, jump to the label.
Working with registers. There are only three registers X, Y and Z. This is enough to make simple loops, store states, etc.
Command format:

XoperationVlabel
YoperationVlabel
ZoperationVlabel

where:
V - letter X, Y, Z or number. Also pseudo-variables are allowed here: D (DISTANCE), E (ENERGY), N (NUMBER), M (MYARMY)
operations:
    + (add right to left)
    - (subtract right from left)
    = (assign right to left)
    < (compare left with right, jump if left is less)
    > (jump if left is greater then right)

in case of operations +, -,  = jump occur to the label if result value less then 0.

Or a short form:

Xnumber.label
Ynumber.label
Znumber.label

- comparing with given number, jump to the label, if a register value is less then a number.

A sample of program. This is a complicated a bit program, which uses message sending and receiving to call allies in case of troubles. While attacking amount of energy analysed to decide if to escape or continue attacks. Een before going to help to message sender, robot is analysing its energy level.

* start moving forward, if a barrier, look further
start: W.lab1 F.lab1 F.lab1 F.lab1 F.lab1 F.lab1 W.lab1
       * go forward while possible

* a barrier. Analyse 3 times, what it is
lab1: X=3

* if after 3 rotates and tests if it is an enemy nothing found,
* try to continue moving
lab2: X-1.start
lab3: I.enemy1 W.lab2
E.20.start
* if an energy is too low, do not help others
H * hear messages
G.start * nothing, let's go forward

* Attacking
enemy1: X=E * store energy amount before attack
    I.enemy2 G.start * is enemy forward?
enemy2:
A.start A.start A.start
* attack 3 times
S.search * if enemy is not yet dead, call allies
E<X.runaway X=E * if energy smaller then before an attack, try to escape
G.enemy1 * continue attacking

* escape
runaway: X=2 * 2 attempts to escape
run1: X-1.lab3 * if failure, continue the fight
L.run1 F.run1 G.start * seems escaped. let's go far away

* search who called us:
search: W.lab3
X=D X-2
* -2, because it is sufficient to go near
s1: N>0.enemy0 * if enemy found (even other) stop to attack it
s2: F.lab3 X-1.lab1 G.s1 * continue searching

* found enemy while searching a caller
enemy0: I.enemy1 L I.enemy1 L I.enemy1 L I.enemy1
G.s2
* he gone away - return to a way

Recommendations. High intellect not yet a garantee of a success. Simple numerical superiority can determine who win. Communicating is useful. But if too cost, it can lead to fail. Use step-by-step mode to understand which parts of your program work bad.


History.

The first version of the AutoWar were created by me in 1995, but were not published wide. In such version, command system is different a bit (I just could not remember commands of AutoWar-I), a program is rewritten for Windows.

The most useful change is a capability to debug robot program. Clicking a robot, you select it, and all executed commands and register values are displayed for it on each step. Press key ( || ) to pause executing, ( >. ) to do single step or ( -> ) to continue battle. Speed also can be changed.

(ะก) by Vladimir Kladov, 1995, 2003.