Quick Details

The git repository is listed on The UCC git page as "progcomp2012.git"

We will use the same mailing list as last year (progcomp).

There is a #progcomp irc channel on the ucc irc server where you can ask questions or help with setting things up.


This site explains what Stratego is.

I have never played this game. But it sounds cool. So naturally I decided to make a competition based on it.

My original idea was to force people to write AI for Astral, but then I realised that that was a terrible idea.

There is in fact, already a World Stratego Championship. However, you have to use Metaforge. Using stdin/stdout will probably make it slightly easier for us. And its better to work out how to do these things ourselves.

Programming Competition

Create an AI to play Stratego.

Yes, I know people are inherently lazy and won't be bothered to do this. But so far in setting this up I have learn quite a lot about inter-process communication, so thats good.

Programs are written independently and interface through stdin/stdout with a manager program, which queries them on setup and moves.

The Manager Program

The manager program takes two executable paths, one to each of the AI programs to pit against each other.

It first requests each program to print the setup of its pieces to stdout. Then the programs take turns (Red, then blue, etc) to move one piece.

The first program is Red (top of the board), the second is Blue (bottom of the board).

The manager program now has switches to enable/disable graphics and set the move speed of the match.

Use "-g" to enable graphics (by default disabled) and "-t TIMEOUT" to set the move speed (default 0 (as fast as possible)).

This program now has a manual page

Messaging Protocol and Rules

The rules are now also available in the manual page of the manager program



The manager program prints one line in the following format to each program:


At the moment BOARD_WIDTH and BOARD_HEIGHT are always 14. The arguments are followed by a newline.

OPPONENT will be the identity of the opposing AI program.


The AI program queried must print four (4) lines containing its initial setup. Each character represents a unit or empty space. The characters are as follows:

Warning: I have changed the characters from mostly letters to mostly digits, indicating the actual worth of a piece

Name Character Number Notes
Marshal 1 1 Dies if attacked by the Spy
General 2 1
Colonel 3 2
Major 4 3
Captain 5 4
Lietenant 6 4
Sergeant 7 4
Miner 8 5 Defuses Bombs and survives.
Scout 9 8 May move any number of times in a single direction.
Spy s 1 If the Spy attacks the Marshal, the Marshal is destroyed.
Bomb B 6 Immobile. Destroys both self and any unit that attacks the Bomb.
Flag F 1 Immobile. Capture the opponent's flag to win.
Unoccupied .
Obstacle *

The AI program can't place any obstacles, and must at least place the Flag for its setup to be valid.

RED will always occupy the top four rows of the board, and BLUE occupies the bottom four rows.

All pieces except the Scout, Bomb and Flag can move 1 square horizontally or vertically (not diagonally).

When two pieces of different ranks encounter each other, the piece with the highest rank (lowest numbered rank!) is the victor, unless a special rule applies.

When two pieces of equal rank encounter each other, the victor is randomly chosen

Pieces of the same colour may not pass through the same squares



RED starts the game. The manager queries RED to make the first move by printing:


Followed by a WIDTH*HEIGHT grid. '*' or '#' characters are used to indicate positions of unknown (BLUE/RED) enemy units.


The AI program must respond with a single line of the following form:


Where X and Y represent valid co-ordinates, upon which there is a piece of the AI program's colour.

DIRECTION must be either "UP", "DOWN", "LEFT", or "RIGHT", and is, obviously, the way the piece is supposed to move

MULTIPLIER is optional, and should only be given if the AI program is moving a Scout. Scouts may move multiple times in the same direction if possible.


The manager program will indicate the result of a move by responding with:


Where X, Y, DIRECTION and MULTIPLIER are as above.

OUTCOME signals the result of the turn, and will be one of the following:

OUTCOME Description
OK The piece was successfully moved, nothing eventful happened
FLAG The piece moved onto the opposing Flag; the game will end shortly
KILLS RANK1 RANK2 The piece landed on a square occupied by an enemy, and destroyed it, moving into the square
DIES RANK1 RANK2 The piece landed on a square occupied by an enemy, and was destroyed. The piece is removed from the board.
BOTHDIE RANK1 RANK2 The piece landed on a square occupied by an enemy, and both pieces were destroyed.
ILLEGAL The moving player attempted to make an illegal move, and has hence lost the game. The game will end shortly.

If printed, RANK1 and RANK2 indicate the ranks of the moved piece and the defending piece (the piece who occupied the destination square) respectively.

Originally RANK1 and RANK2 were never printed, but when I actually tried to write an AI myself I got very annoyed at this restriction... indicating it was probably a bad idea :P

Additional Turns

The Outcome of each turn is printed to both AI programs.

The state of the board is then printed to BLUE, who makes a move, then the process repeats.


This is a description of the signals the AI programs recieve, in order:

  1. Previous turn's outcome (other player's move) OR "START" if it is the first turn
  2. A BOARD_WIDTH*BOARD_HEIGHT grid indicating the board state, with the AI program's own pieces revealed
  3. After the AI program makes a move, the outcome is printed to it, and the other program, which continues from step 1

I am considering removing Step 2, since all information needed for an AI to keep the board state is contained in the initial board state and then the movement result messages

End Game


At the end of the game, the manager program outputs the following:


To the winning AI program, and


To the losing program.

Both programs then have 2 seconds to exit succesfully, or the manager will kill them.

Invalid Responses and Timeouts

If any program fails to respond correctly, or gives an invalid move, or does not respond within 1 second, it will lose by default.

In this case, the message


will be sent to the malfunctioning program, and


to the other program

Both programs then have 2 seconds to exit succesfully, or the manager will kill them.

Modifications/Clarifications to Rules

Refer to This site for the original rules again

Currently, the pieces taking part in the combat are not revealed; only the outcome of the combat is revealed. In a human game, the pieces would normally be revealed. I am planning to reveal the pieces, since not revealing pieces significantly reduces the value of low ranked pieces (normally used for working out enemy piece values).

It is up to the AI program to keep track of pieces. The manager program will only reveal the identity of the AI program's own pieces; the other player's pieces will be marked with * or # characters.

In a traditional game, two pieces of equal value will both be destroyed in combat. Currently, only one piece is destroyed and the outcome is randomly chosen.

Example Programs

"Dummy" AI

Dummy randomly moves pieces. It attempts to not make illegal moves (although sometimes it still does).

"Forfax" AI

Forfax iterates through all possible moves and allocates a score between 0 and 1 to each move based on how desirable the move is. It then selects the highest scoring move.

Forfax is pretty terrible, but can beat the Dummy AI most of the time.

It is possible Forfax can be greatly improved by altering the scoring algorithms.

Since we don't want the Sample AIs to beat every entrance, I'm not really going to try and improve Forfax unless I get bored.

If you are writing an AI in C++, Forfax already contains a lot of useful functions.

Longterm Scoring

I haven't started a system for pairing AI's and keeping track of scores and winners etc yet

I'll probably have a bash script that chooses who will play, and stores all the scores in files. I've done this before for a BrainF*** based "survival of the fittest" style thing, so I can probably recycle it

I believe it will make things more interesting if programs are allowed to keep state of who they have played, and the various tactics used.

Its kind of hard to implement this... at the moment programs are killed every time a game finishes

Perhaps it will be easier if each program is allowed access to one directory, where it can create and read files?

This would allow me to keep the manager program which actually plays the games seperate from the program for scoring and matching of opponents

There'd probably be security issues with that though.