NAME

Games::Sequential::Position - base Position class for use with Games::Sequential & Games::AlphaBeta

SYNOPSIS

package Some::Game::Position;
use base Games::Sequential::Position;

sub apply { ... }

package main;
my $pos = Some::Game::Position->new;
my $game = Games::Sequential->new($pos);

DESCRIPTION

Games::Sequential::Position is a simple base class for a position-object for use with Games::Sequential. This class is provided only For convenience, and provides the ->copy() method. Users do not have to inherit this class to use Games::Sequential; it is only provided for convenience.

REQUIRED USER-DEFINED METHODS

Anyone inheriting this class for use with Games::Sequential must implement at least the ->apply() method. If you chose to not use this class, you must also implement a ->copy() method which makes a deep copy of the object.

The ->apply() method will probably look something along these lines (sans error checking):

sub apply {
  my ($self, $move) = @_;

  ... apply $move, creating next position ...

  return $self;
}

OPTIONAL USER-DEFINED METHODS

For use with Games::AlphaBeta three more methods must be implemented. These are:

findmoves()

Return an array of all moves possible for the current player at the current position. Don't forget to include null moves if the player is allowed to pass.

endpos()

True if the position is an ending position, i.e. either a draw or a win for one of the players.

evaluate()

Return the "fitness" value for the current player at the current position.

METHODS

These methods are supplied by this base class:

new [@list]

Create and return a new object. Any arguments is passed on to the overridable _init() method.

_init [@list]

Internal method

Initialize an object. This method is called by ->new(), so you do not have to override that. You probably want to override this though. You might want to call $self-SUPER::_init(@_);> from within your version of the method.

copy

Return a deep copy of the object.

SEE ALSO

The author's website, describing this 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.