NAME
Games::Pentago - Represent and play Pentago games and its variants.
SYNOPSIS
# Using the gameplay loop
use Games::Pentago;
my $pentago = Games::Pentago->new;
$pentago->play;
# A 4-player variant
my $pentagoXL = Games::Pentago->new(
board_size => 3,
players => ['X','O','#','%']
);
$pentagoXL->play;
DESCRIPTION
Pentago is a two-player abstract strategy game invented by Tomas Flodén. The game is played on a 6×6 board divided into four 3×3 sub-boards (or quadrants). Taking turns, the two players place a marble of their color onto an unoccupied space on the board, and then rotate one of the sub-boards by 90 degrees either clockwise or counter-clockwise. A player wins by getting five of their marbles in a vertical, horizontal or diagonal row. If all 36 spaces on the board are occupied without a row of five being formed then the game is a draw.
A Games::Pentago object represents a game of Pentago or a variant.
For specifying direction, use the constants Games::Pentago::CW
and Games::Pentago::CCW
. Sub-boards are enumerated with integers starting at 0 in the upper-left corner.
METHODS
Construction
- new()
-
Constructs a new Pentago game. If you want a variant of Pentago, you can change the default values by passing arguments on the form (key,value). Possible keys are:
sub_board_size Side length of a sub-board (default 3). board_size Number of sub-boards on one side (default 2). row_length Number of marbles in a row required to win (default 5). players Reference to an array of the players' symbols. empty_symbol Symbol for empty squares (default '.').
Object methods
- move()
-
Makes a move, i.e. puts a marble belonging to the current player, rotates a sub-board and makes the next player the current player. Takes four arguments: the X and Y coordinates, subboard and direction.
- rotate()
-
Rotates a sub-board. Takes the sub-board and the direction (
Games::Pentago::CW
orGames::Pentago::CCW
) as arguments. - next_player()
-
Makes the next player the current player. Takes no arguments.
- player()
-
Returns the symbol of the current player. Takes no arguments.
- valid_square()
-
Returns true if the given square is on the board. Takes X and Y as arguments.
- at()
-
Returns the symbol at a square. Takes X and Y as arguments.
- empty()
-
Returns true if a square is empty. Takes X and Y as arguments.
- set()
-
Puts a symbol on an a square. Takes X, Y and the symbol as arguments. The symbol must correspond to a player.
- str()
-
Returns a string describing the game position. Optionally takes a combination of flags as an argument.
DISP_NO_AXES Do not write the axes and borders. DISP_NO_SPACES Do not put spaces between columns. DISP_NO_NEWLINES Remove all newlines.
Sample output, without flags:
0 1 2 3 4 5 +------------ 0| . . . . X . 1| . . O O . . 2| . . X . . . 3| . O . . . . 4| X . O . . . 5| . X . . . .
- print()
-
Prints the output of
str
. Takes the same flags asstr
. - winners()
-
Returns a list of the players who have the required number of marbles in a row.
- play()
-
Enters a play loop that reads from standard input and lets you play the game.
AUTHOR
Tim Nordenfur, <tim at gurka.se>
BUGS
Please report any bugs or feature requests to bug-games-pentago at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Games-Pentago. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
SUPPORT
You can find documentation for this module with the perldoc command.
perldoc Games::Pentago
You can also look for information at:
RT: CPAN's request tracker
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
Search CPAN
ACKNOWLEDGEMENTS
Pentago was found by Tomas Flodén.
Parts of the introducing text were taken from the Wikipedia article on Pentago.
LICENSE AND COPYRIGHT
Copyright 2010 Tim Nordenfur.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 56:
Non-ASCII character seen before =encoding in 'Flodén.'. Assuming UTF-8