NAME

Games::Sequential - framework for sequential games with object oriented interface

SYNOPSIS

use Games::Sequential;
my $game = Games::Sequential->new($initialpos, move => \&move );

$game->debug(1);

$game->move($move);
$game->undo;

DESCRIPTION

Games::Sequential provides a simple base class for sequential games. The module provides an undo mechanism, as it keeps track of the history of moves, in addition to methods to clone a game state with or without history.

Users will have to provide this module with a reference to a callback function to perform a move in the game they are implementing. This callback is:

move $position, $move

Create $newpos as copy of $position and apply $move to it. Return $newpos.

METHODS

Users must not modify the referred-to values of references returned by any of the below methods, except, of course, indirectly using the supplied callbacks mentioned above.

new [@list]

Create and return a new AlphaBeta object.

The function move can be given as an argument to this function. If so, there is no need to call the setfuncs() method. Similarly, if a valid starting position is given (as initialpos) there is no need to call init() on the returned object. The debug option can also be set here.

_init [@list]

Internal method

Initialize a AlphaBeta object.

setfuncs @list

Set (or change) callback functions. This method is required unless ->new() is invoked with MOVE as an argument.

debug [$value]

Return current debug level and, if invoked with an argument, set to new value.

peek_pos

Return reference to current position. Use this for drawing the board etc.

peek_move

Return reference to last applied move.

move $move

Apply $move to the current position, keeping track of history. A reference to the new position is returned, or undef on failure.

undo

Undo last move. A reference to the previous position is returned, or undef if there was no more moves to undo.

TODO

Implement missing methods, e.g.: clone(), snapshot(), save() & resume().

SEE ALSO

The author's website, describing this module and other projects: http://brautaset.org/projects/

AUTHOR

Stig Brautaset, <stig@brautaset.org>

COPYRIGHT AND LICENCE

Copyright (C) 2004 by Stig Brautaset

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.3 or, at your option, any later version of Perl 5 you may have available.