NAME

Game::Reversi::Rules - whose turn, when a turn is forfeited, and when it ends

VERSION

Version 0.01

SYNOPSIS

my ($turn, $forfeited) = Game::Reversi::Rules->next_turn($board, 'b');
my @moves = Game::Reversi::Rules->legal($board, $turn);

DESCRIPTION

Pure functions over a board. Nothing here holds state, prints, or knows what an event is.

The pass is not a move a player makes

WOF rule 2:

If on your turn you cannot outflank and flip at least one opposing disc, your turn is forfeited and your opponent moves again. However, if a move is available to you, you may not forfeit your turn.

The first sentence makes the pass automatic, so the engine performs it and "legal" never returns a one element list holding a pass the player has no choice about. The second makes a deliberate pass an error.

Together they have a consequence worth stating: because the engine forfeits for anybody who cannot move, a seat on turn always has a move. So a deliberate pass can only ever be answered with has_move. That is a property of the design, not a coincidence.

The end is one condition, not two

WOF rule 8: "When it is no longer possible for either player to move, the game is over", with the note that "It is possible for a game to end before all 64 squares are filled."

Wikipedia's rules section gives two conditions, a full board or neither side able to move, and its lead gives only the first, which is wrong as a standalone rule. A full board is a strict special case of neither side being able to move, so only the general condition is implemented. Writing both is how two conditions drift apart, and the one that is a special case is the one that rots.

METHODS

next_turn

Given the board after a move and the colour that made it, returns ($turn, $forfeited). $turn is undef when the game is over. $forfeited is the colour whose turn was taken away, or undef, so that a caller can say so: a pass nobody mentions looks like the board changing twice on its own.

in_opening

Whether discs are still being placed.

over

Whether the game is finished in this position, whoever is to move.

opening_turn

Who moves first in a position, given who has the first move by right. Handles a position handed in from outside where that colour has nothing to do.

The moves open to a colour, as Game::Reversi::Move objects. Placements during the opening, plays afterwards, never a pass.

AUTHOR

LNATION <email@lnation.org>

LICENSE AND COPYRIGHT

This software is Copyright (c) 2026 by LNATION <email@lnation.org>.

This is free software, licensed under the Artistic License 2.0.