Foxes and Geese

Problem #239

Tags: special interactive games ascii c-0

Who solved this?

No translations... yet

Yet another "interactive" problem, so make sure you've seen instruction please. Find server address there and use GAME CODE foxgeese in it.

Game is perfectly known (under various names). Idea for a problem is borrowed directly from "Programming Games and Puzzles" by Jaques Arsac (fr) - my favorite old book which teaches programming without giving a single line of code.

Description by monsieur Arsac

When I was young, we played this game outdoors, using small stones for hens (geese) and two larger ones for foxes. We drew the grid with chalk on the pavement or with stick on the plain ground patch.

Here is how I represent the game on my computer's screen:

    - - -              - - -
    - - -              - d *
- - * - * - -      a * - - e - g
a b c d e f g      - b c - - f -
h i j k l m n      h - j k l m n
    o p q              o p q
    r s t              r s t

   initial            game in
   position           progress

Letters represent hens. Stars (asterisks) - two foxes. Hens could move 1 step forward (up), left or right (but not backwards or by diagonals). Foxes also can go 1 step, but both up or down, left or right.

Foxes could capture hens - as in checkers - if the hen is adjacent to fox in vertical or horizontal direction and the place immediately after it is empty. Fox jumps over the hen to that free space (and the hen is removed). Several hens could be captured by sequence of jumps.

The second (rightmost) picture above shows situation in which one of the foxes can capture hen "b", while the other can take both "e" and "f".

Foxes are obliged to capture, and if there are several ways of capturing, the longest should be performed. If there are several ways of equal maximal length - fox is free to choose any of them.

In my programmed version of the game computer plays foxes. You move hens. Players take turns, the hens move first.

Hens win if they fill 9 cells of the upper 3x3 square (the one with lower corners where foxes initially are). Also hens win if they block foxes.

Foxes win if they capture 12 of 20 hens, as remaining 8 are not enough to fill the square.

Initial position is shown in the leftmost drawing above.

This description could not be close to original as I myself use the version of book poorly translated to my native language. Sorry for possible inaccuracies.

Additional details

We use terms geese and hens interchangeably (as probably bit more popular).

So the server plays for foxes and you are to write code playing geese against it. To prevent endless game we restrict geese - if they don't win after 100-th move, game is considered lost by them.

Also here is subtle chance for geese getting blocked themselves without winning, we consider this situation as defeat for them (practically they can't make any valid move, while one of the foxes can still wander behind).

Game Interface

You make moves by sending token as usual, and the field geese describing your move. Description consists of two letters - first is a..t - the "name" of the bird to move, the second one of three u, l, r - for up, left or right respectively. For example bl means "goose b goes left".

Besides this to make the very first move you also should sent field start (with any value) - so the server initializes game for you. This can be used later to restart game in progress (say, if you feel situation is hopeless).

Server responds with field foxes describing move by one of them. It uses similar format with few additions:

For example Ydru means fox Y jumps down, then jumps right, then jumps up - taking three geese at once.

Also there are fields moves (just counter) and field - picture of current situation in base64 - they are just for your information and convenience.

If you lose or win the game, there is the field end (in the case of victory it contains secret to submit here).

Example

we send:                server says:

token: ....
start: 1
geese: du

                        moves: 1
                        foxes: Xu
                        field: ....

token: ....
geese: bu

                        moves: 2
                        foxes: Yll

token: ....
geese: el

Which leads to the following situation:

    - - -
    X - -
Y - - - - - -
a - c e - f g
h i j k l m n
    o p q
    r s t
You need to login to get test data and submit solution.