my $physics = AI::Evolve::Befunge::Physics->new('othello');
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.
Use AI::Evolve::Befunge::Physics->new() to get an othello object; there is no constructor in this module for you to call directly.
$othello->setup_board($board);
Initialize the board to its default state. For othello, this looks like:
........ ........ ........ ...xo... ...ox... ........ ........ ........
die("out of bounds") unless $othello->in_bounds($vec);
Returns 1 if the vector is within the playspace, and 0 otherwise.
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.
$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.
my $winner = $othello->won($board);
If the game has been won, returns the player who won. Returns 0 otherwise.
my $over = $othello->over($board);
Returns 1 if no more moves are valid from either player, and returns 0 otherwise.
my $score = $othello->score($board, $player, $number_of_moves);
Returns the number of pieces on the board owned by the given player.
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.
$othello->make_move($board, $player, $pos);
Makes the indicated move, updates the board with the new piece and flips enemy pieces as necessary.
To install AI::Evolve::Befunge, copy and paste the appropriate command in to your terminal.
cpanm
cpanm AI::Evolve::Befunge
CPAN shell
perl -MCPAN -e shell install AI::Evolve::Befunge
For more information on module installation, please visit the detailed CPAN module installation guide.