Cartagena Computer Interface

Changes

16 October 2008 Another slight tweak. Introduced notation for the card played for an advance move.
25 September 2008 Slightly changed the interface description: different file format, and program now has 15 seconds to report a single action, rather than 30 seconds for all three actions.
4 April 2008 Initial version

The game will be played between two and six players.

Each player in Cartagena has up to three actions (advance or retreat moves) during their turn: your program will return just one of these actions.

Your program will be run afresh for each move it has to make. Your program will be fed the history of the game so far on standard input: this is likely to end with the previous actions taken during this turn. Your program will then have 15 seconds to report its next action on standard output.

The format of the input is as follows. The first line will have a single digit, giving the number of players. The next portion will state the layout of the board, from start to finish. Subsequent lines will give the moves played so far in the game (maximum of three consecutive actions by any player). Next will be a single line giving the number of the player whose turn is next. The final set of lines will be the cards in your hand (in an arbitrary order).

Postions are numbered consequetively from the start, with zero-based numbering. The cell is location 0. The boat is always the last position (number 37 in a standard game).

Players are numbered with one-based numbering: the first player to go is Player 1, the second is Player 2, and so on.

Each move will be in the format
<player number> <location moved from> <location moved to> <card played>
(with a single space between the fields). The <card played> field is always missing for retreat moves, is required for advance moves into the boat, and is optional for other advance moves.

It may be that a player takes fewer than their three allowed actions in their turn. There are no additional spaces or blank lines in the file.

Here is an example of a valid input file:

3
cell
skull
hat
keys
gun
bottle
dagger
hat
gun
keys
skull
bottle
dagger
dagger
gun
hat
bottle
skull
keys
hat
keys
bottle
gun
skull
keys
keys
skull
hat
bottle
gun
dagger
bottle
skull
gun
dagger
keys
hat
boat
1 0 4
1 0 3 keys
1 4 3
2 0 4
2 4 3
2 0 2
3 0 5
3 5 2
3 0 4
1 0 5 bottle
2
hat
skull
hat

(Note that in this example, player 1 elected to take only one of their three actions for their second turn. It is now player 2's turn.)

The output of your program will be the actions taken in your turn, in the same format as specified in the input file: one action per line, in the format
<player number> <location moved from> <location moved to> <card played> (<card played> is optional for advance moves that are not into the boat).

Player programs will run on a Linux machine (probably some version of Ubuntu Linux). Exact specification is unclear at the moment, but it may run on a twin-processor machine.

The player's program must be named runme; it may be a binary executable or a driver shell script that starts up the actual program. It will be invoked as

    ./runme

with the program's top-level directory as the current working directory; libraries and other support data may thus be accessed with the relative path name
    support/...

The program is run once for every move and then terminates; the current state will be passed to the program on standard input. Persistent inter-move state may be kept in the support/ directory if desired. When the program has chosen a move, it should print the move to standard output and exit. If the program has not done so after 30 seconds (real or "wall clock" time), the program will be terminated forcibly, and lose the game.

There should be no child processes alive after the top-level process exits; the program must ensure that all its child processes have exited before the top-level process exits itself.