The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME AI::Evolve::Befunge::Physics::othello - an othello game

SYNOPSIS

    my $physics = AI::Evolve::Befunge::Physics->new('othello');

DESCRIPTION

This is an implementation of the "othello" board game ruleset. This game is also known to some as "reversi". It is implemented as a plugin for the AI::Evolve::Befunge Physics system; essentially an AI creature exists in an "othello" universe, and plays by its rules.

CONSTRUCTOR

Use AI::Evolve::Befunge::Physics->new() to get an othello object; there is no constructor in this module for you to call directly.

METHODS

setup_board

    $othello->setup_board($board);

Initialize the board to its default state. For othello, this looks like:

    ........
    ........
    ........
    ...xo...
    ...ox...
    ........
    ........
    ........

in_bounds

    die("out of bounds") unless $othello->in_bounds($vec);

Returns 1 if the vector is within the playspace, and 0 otherwise.

try_move_vector

    my $score = $othello->try_move_vector($board, $player, $pos, $dir);

Determines how many flippable enemy pieces exist in the given direction. This is a lowlevel routine, meant to be called by the valid_move() and make_move() methods, below.

valid_move

    $next_player = $othello->make_move($board, $player, $pos)
        if $othello->valid_move($board, $player, $pos);

If the move is valid, returns the number of pieces which would be flipped by moving in the given position. Returns 0 otherwise.

won

    my $winner = $othello->won($board);

If the game has been won, returns the player who won. Returns 0 otherwise.

over

    my $over = $othello->over($board);

Returns 1 if no more moves are valid from either player, and returns 0 otherwise.

score

    my $score = $othello->score($board, $player, $number_of_moves);

Returns the number of pieces on the board owned by the given player.

can_pass

    my $can_pass = $othello->can_pass($board, $player);

Returns 1 if the player can pass, and 0 otherwise. For the othello rule set, passing is only allowed if no valid moves are available.

make_move

    $othello->make_move($board, $player, $pos);

Makes the indicated move, updates the board with the new piece and flips enemy pieces as necessary.