NAME AI::Evolve::Befunge::Physics::ttt - a tic tac toe game
SYNOPSIS
my $ttt = AI::Evolve::Befunge::Physics->new('ttt');
DESCRIPTION
This is an implementation of the "ttt" game ruleset. It is implemented as a plugin for the AI::Evolve::Befunge Physics system; essentially an AI creature exists in a "tic tac toe" universe, and plays by its rules.
CONSTRUCTOR
Use AI::Evolve::Befunge::Physics->new() to get a ttt object; there is no constructor in this module for you to call directly.
METHODS
setup_board
$ttt->setup_board($board);
Initialize the board to its default state. For tic tac toe, this looks like:
...
...
...
valid_move
my $valid = $ttt->valid_move($board, $player, $pos);
Returns 1 if the move is valid, 0 otherwise. In tic tac toe, all places on the board are valid unless the spot is already taken with an existing piece.
won
my $winner = $ttt->won($board);
If the game has been won, returns the player who won. Returns 0 otherwise.
over
my $over = $ttt->over($board);
Returns 1 if no more moves are valid from either player, and returns 0 otherwise.
score
my $score = $ttt->score($board, $player, $number_of_moves);
Return a relative score of how the player performed in a game. Higher numbers are better.
can_pass
my $can_pass = $ttt->can_pass($board, $player);
Always returns 0; tic tac toe rules do not allow passes under any circumstances.
make_move
$next_player = $ttt->make_move($board, $player, $pos)
if $ttt->valid_move($board, $player, $pos);
Makes the given move, updates the board with the newly placed piece.