Games::Board::Grid - a grid-shaped gameboard
my $chess = Games::Board->new(size => 8);
my $rook = Games::Board::Piece->new(id => 'KR')->move(to => '7 7');
This module provides a base class for representing a board made up of spaces on a right-angled grid.
This module should work on any version of perl still receiving updates from the Perl 5 Porters. This means it should work on any version of perl released in the last two to three years. (That is, if the most recently released version is v5.40, then this module should work on both v5.40 and v5.38.)
Although it may work on older versions of perl, no guarantee is made that the minimum required version will not be increased. The version may be increased for any reason, and there is no promise that patches will be accepted to lower the minimum required perl.
my $board = Games::Board::Grid->new(size => $size);
This method constructs a new game board and returns it. As constructed it has no spaces or pieces on it. The size argument may be an integer, to produce a square board, or an arrayref containing two integers, to produce a rectangular board.
This method sets up the spaces on the board.
my $index = $board->id2index($id);
This method returns the grid location of an identified space, in the format [$x, $y]. In Games::Board::Grid, the index [x,y] becomes the id 'x y'. Yeah, it's ugly, but it works.
Reimplementing this method on a subclass can allow the use of idiomatic space identifiers on a grid. (See, for example, the chess-custom.t test in this distribution.)
my $id = $board->index2id($index);
This method performs the same translation as id2index, but in reverse.
my $space = $board->space($id);
This method returns the space with the given $id. If no space with that id exists, undef is returned.
This method, provided by Games::Board, will croak immediately if called.
The spaces on a grid board are blessed into this class. It acts like a Games::Board::Space object, but directions are given as arrayrefs with x- and y-offsets. For example, a knight's move might be represented as:
Ricardo SIGNES <email@example.com>
This software is copyright (c) 2003 by Ricardo SIGNES.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Games::Board, copy and paste the appropriate command in to your terminal.
perl -MCPAN -e shell
For more information on module installation, please visit the detailed CPAN module installation guide.