Games::Board::Grid - a grid-shaped gameboard


Games-Board documentation  | view source Contained in the Games-Board distribution.

Index


NAME

Top

Games::Board::Grid -- a grid-shaped gameboard

VERSION

Top

 $Id: /my/cs/projects/board/trunk/lib/Games/Board/Grid.pm 27799 2006-11-11T02:23:32.940873Z rjbs  $

SYNOPSIS

Top

  use Games::Board::Grid;

  my $chess = Games::Board->new(size => 8);

  my $rook = Games::Board::Piece->new(id => 'KR')->move(to => '7 7');

DESCRIPTION

Top

This module provides a base class for representing a board made up of spaces on a right-angled grid.

METHODS

Top

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.

init

This method sets up the spaces on the board.

size
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.)

index2id($loc)

This method performs the same translation as id2index, but in reverse.

space($id)

This method returns the space with the given $id. If no space with that id exists, undef is returned.

add_space(%param)

This method, provided by Games::Board, will croak immediately if called.

Games::Board::Grid::Space

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:

  $board->space('1 0')->dir([2,1]);

TODO

Top

Lots. First up: write a TODO list.

AUTHOR

Top

Ricardo SIGNES <rjbs@cpan.org>

COPYRIGHT

Top


Games-Board documentation  | view source Contained in the Games-Board distribution.