NAME
Games::Go::Cinderblock::State - A game state representation
SYNOPSIS
my $rulemap = Games::Go::Cinderblock::Rulemap::Rect->new(
w => 5,
h => 3,
);
my $board = [
[qw/0 w 0 b 0],
[qw/w w 0 b b],
[qw/0 w 0 b 0]
];
my $state = Games::Go::Cinderblock::State->new(
rulemap => $rulemap,
board => $board,
turn => 'b',
);
# b expertly fills in an eye
my $move_result = $state->attempt_move(
color => 'b',
node => [2,4],
);
$state = $move_result->resulting_state;
say "Current turn: ' . $state->turn;
# Current turn: w
DESCRIPTION
Unless you want bad things to happen, do not modify the state directly while using it as the basis of a scorable. States are generally immutable, but you do have the power to change them directly. Don't, though.
Use attempt_move, instead. In the future, move attempts will have special categories for passes & other tricky shenanigans.
METHODS
attempt_move
Usage: my $move_result = $state->attempt_move(node=>$node,color=>$color
Return a MoveResult, which contains a resulting state if the move attempt is successful.
scorable
Returns a new Games::Go::Cinderblock::Scorable with this state as its basis.
floodfill
# a chain of black stones, starting at [10,10].
my $chain = $state->floodfill( sub{$_ eq 'b'}, [10,10]);
Usage: my $nodeset = $state->floodfill($condition, $progenitor)
This returns a nodeset of connected nodes where the condition evaluates to true, beginning at a progenitor node.
To get a chain of white stones starting at $node $state->floodfill( $sub{ $_ eq 'w' }, $node);
To get a region of empty space, starting at $node $state->floodfill( $sub{ ! $_ }, $node);
grep_nodeset
my $not_larger_nodeset = $state->grep_nodeset(sub{$_ =~ /[wb]/}, $nodeset)
Another awkward functional thing.