The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.


Games::Affenspiel - Play the Affenspiel game


    # automatical random play script
    use Games::Affenspiel::Board;

    my $board = Games::Affenspiel::Board->new;

    for (1 .. 5000) {
        my ($bar, $gap_position, $direction) = $board->choose_random_move;
        print "Move bar $bar in direction $direction to $gap_position\n";


Games::Affenspiel is a set of Perl classes implementing the Affenspiel game play.


This package is intended to provide a basis for interactive (not yet) and automatic playing and manipulating of Affenspiel games.

Current built-in board configurations:

    0) 4x5; one 2x2, four 1x1, four 1x2, one 2x1 bars, two gaps
    1) 4x5; one 2x2 bar, 16 gaps (just a test board)
    2) 4x5; one 2x2, four 1x1, two 1x2, three 2x1 bars, two gaps

Currently installed scripts (run with --help):

    * affenspiel-random-moves
    * affenspiel-random-solve
    * affenspiel-solve

The Rules of Affenspiel


The regular Affenspiel board is comprised of 20 cells, 4 rows (numbered 1 to 4) of 5 columns (numbered 1 to 5). The cell position is written in (y, x) notation.

The original board has two gaps and following bars: one 2x2, four 1x1, four 1x2, one 2x1. The position of the left-top corner of the bar is taken as the position of the bar.

Initial board

In the initial state, the 2x2 square bar is in position (1, 2),

    | <> |

The goal

In the final (solved) state, the 2x2 square bar is in position (4, 2)), Here is an example final board (there are many solutions):

    | /\O|
    | []O|


Each piece may be moved to left/right/up/down inside the board if there are enough gap(s) in that direction. No bar rotation is allowed.





Mikhael Goikhman <>

1 POD Error

The following errors were encountered while parsing the POD:

Around line 124:

'=end' without a target?