Why not adopt me?
NAME
Games::Goban - Board for playing go, renju, othello, etc.
VERSION
version 1.103
SYNOPSIS
use Games::Goban;
my $board = new Games::Goban (
size => 19,
game => "go",
white => "Seigen, Go",
black => "Minoru, Kitani",
referee => \&Games::Goban::Rules::Go,
);
$board->move("pd"); $board->move("dd");
print $board->as_sgf;
DESCRIPTION
This is a generic module for handling goban-based board games. Theoretically, it can be used to handle many of the other games which can use Smart Game Format (SGF) but I want to keep it reasonably restricted in order to keep it simple.
PERL VERSION
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.
METHODS
new(%options);
Creates and initializes a new goban. The options and their legal values (* marks defaults):
size Any integer between 5 and 26, default: 19
game *go, othello, renju, gomoku
white Any text, default: "Miss White"
black Any text, default: "Mr Black"
skip_i Truth value; whether 'i' should be skipped; false by default
referee Any subroutine, default: sub {1} # (All moves are valid)
The referee subroutine takes a board object and a piece object, and determines whether or not the move is legal. It also reports if the game is won.
move
$ok = $board->move($position)
Takes a move, creates a Games::Goban::Piece object, and attempts to place it on the board, subject to the constraints of the referee. If this is not successful, it returns 0
and sets $@
to be an error message explaining why the move could not be made. If successful, updates the board, updates the move number and the turn, and returns true.
pass
This method causes the current player to pass. At present, nothing happens for two subsequent passes.
get
$move = $board->get($position)
Gets the Games::Goban::Piece
object at the given location, if there is one. Locations are specified as per SGF - a 19x19 board starts from aa
in the top left corner, with ss
in the bottom right. (If the skip_i option was set while creating the board, tt
is the bottom right and there are no i
positions. This allows for traditional notation.)
size
$size = $board->size
Returns the size of the goban.
hoshi
@hoshi_points = $board->hoshi
Returns a list of hoshi points.
is_hoshi
$star = $board->is_hoshi('dp')
Returns true if the named position is a hoshi (star) point.
as_sgf
$sgf = $board->as_sgf;
Returns a representation of the board as an SGF (Smart Game Format) file.
as_text
print $board->as_text(coords => 1)
Returns a printable text picture of the board, similar to that printed by gnugo
. Black pieces are represented by X
, white pieces by O
, and the latest move is enclosed in parentheses. hoshi points are in their normal position for Go, and printed as an +
. Coordinates are not printed by default, but can be enabled as suggested in the synopsis.
register
my $key = $board->register(\&callback);
Register a callback to be called after every move is made. This is useful for analysis programs which wish to maintain statistics on the board state. The key
returned from this can be fed to...
notes
$board->notes($key)->{score} += 5;
notes
returns a hash reference which can be used by a callback to store local state about the board.
hash
$hash = $board->hash
Provides a unique hash of the board position. If the phrase "positional superko" means anything to you, you want to use this method. If not, move along, nothing to see here.
skip_i
This method returns true if the 'skip_i' argument to the constructor was true and the 'i' coordinant should be skipped. (Note that 'i' is never skipped when producing SGF output.)
Games::Goban::Piece
methods
Here are the methods which can be called on a Games::Goban::Piece
object, representing a piece on the board.
color
Returns "b" for a black piece and "w" for a white. colour
is also provided for Anglophones.
notes
Similar to the notes
method on the board class, this provides a private area for callbacks to scribble on.
position
Returns the position of this piece, as a two-character string. Incidentally, try to avoid taking references to Piece
objects, since this stops them being destroyed in a timely fashion. Use a position
and get
if you can get away with it, or take a weak reference if you're worried about the piece going away or being replaced by another one in that position.
move
Returns the move number on which this piece was played.
board
Returns the board object whence this piece came.
TODO
use Games::Goban::Board for game board
add
<$board-
pass>>possibly enable
<$board-
move('')>> to passproduce example referee
produce sample method for removing captured stones
SEE ALSO
Smart Game Format: http://www.red-bean.com/sgf/
Games::Go::SGF
The US Go Association: http://www.usgo.org/
AUTHORS
Simon Cozens
Ricardo SIGNES <cpan@semiotic.systems>
CONTRIBUTORS
Ricardo SIGNES <rjbs@codesimply.com>
Ricardo Signes <rjbs@semiotic.systems>
COPYRIGHT AND LICENSE
This software is copyright (c) 2002 by Simon Cozens.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.