NAME
Games::Battleship::Grid - A Battleship grid class
SYNOPSIS
use Games::Battleship::Grid;
$grid = Games::Battleship::Grid->new(
fleet => \@fleet,
dimension => [$width, $height],
);
DESCRIPTION
A Games::Battleship::Grid
object represents a Battleship playing surface complete with fleet position references and computation.
Check out the powerful _segment_intersection
function in the source code of this module. :-)
PUBLIC METHODS
- new %ARGUMENTS
-
fleet => [$CRAFT_1, $CRAFT_2, ... $CRAFT_N]
Optional array reference of an unlimited number of
Games::Battleship::Craft
objects.If provided, the fleet will be placed on the grid with random but non-overlapping positions.
Naturally, it is required that the combined sizes of the ships be less than the area of the grid.
dimensions => [$WIDTH, $HEIGHT]
Optional array reference with the grid height and width values.
If not provided, the standard ten by ten playing surface is used.
PRIVATE FUNCTIONS
- _tail_coordinates @COORDINATES, $SPAN
-
($orientation, $x1, $y1) = _tail_coordinates($x0, $y0, $span);
Return a vector for the craft. That is, hand back the vertical or horizontal line segment orientation and the tail coordinates based on the head coodinates and the length of the segment (i.e. the craft).
- _segment_intersection @COORDINATES
-
$intersect = _segment_intersection( px0, py0, px1, py1, qx0, qy0, qx1, qy1 );
Return zero if there is no intersection (or touching or overlap).
Each pair of values define a coordinate and each pair of coordinates define a line segment.
TO DO
Allow diagonal craft placement.
Allow placement restriction rules (e.g. not on edges, not adjacent, etc.).
Allow some type of interactive craft repositioning.
Allow > 2D playing spaces.
SEE ALSO
Segment intersection:
http://www.meca.ucl.ac.be/~wu/FSA2716/Exercise1.htm
CVS
$Id: Grid.pm,v 1.12 2004/02/07 03:49:26 gene Exp $
AUTHOR
Gene Boggs <gene@cpan.org>
COPYRIGHT AND LICENSE
See Games::Battleship.