GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Games::AlphaBeta(3) User Contributed Perl Documentation Games::AlphaBeta(3)

Games::AlphaBeta - game-tree search with object oriented interface

    package My::GamePos;
    use base qw(Games::AlphaBeta::Position);

    # initialise starting position
    sub _init { ... }

    # Methods required by Games::AlphaBeta
    sub apply { ... }
    sub endpos { ... }          # optional
    sub evaluate { ... }
    sub findmoves { ... }

    # Draw a position in the game (optional)
    sub draw { ... }

    package main;
    my $pos = My::GamePos->new;
    my $game = Games::AlphaBeta->new($pos);

    while ($game->abmove) {
        print draw($game->peek_pos);
    }

Games::AlphaBeta provides a generic implementation of the AlphaBeta game-tree search algorithm (also known as MiniMax search with alpha beta pruning). This algorithm can be used to find the best move at a particular position in any two-player, zero-sum game with perfect information. Examples of such games include Chess, Othello, Connect4, Go, Tic-Tac-Toe and many, many other boardgames.

Users must pass an object representing the initial state of the game as the first argument to "new()". This object must provide the following methods: "copy()", "apply()", "endpos()", "evaluate()" and "findmoves()". This is explained more carefully in Games::AlphaBeta::Position which is a base class you can use to implement your position object.

The following methods are inherited from Games::Sequential:
new
debug
peek_pos
peek_move
move
undo

_init [@list]
Internal method.

Initialize an AlphaBeta object.

ply [$value]
Return current default search depth and, if invoked with an argument, set to new value.
abmove [$ply]
Perform the best move found after an AlphaBeta game-tree search to depth $ply. If $ply is not specified, the default depth is used (see "ply()"). The best move found is performed and a reference to the resulting position is returned on success, and undef is returned on failure.

Note that this function can take a long time if $ply is high, particularly if the game in question has many possible moves at each position.

If "debug()" is set, some basic debugging is printed as the search progresses.

_alphabeta $pos $alpha $beta $ply
Internal method.

The valid range of values "evaluate()" can return is hardcoded to -99_999 - +99_999 at the moment. Probably should provide methods to get/set these.

Implement the missing iterative deepening alphabeta routine.

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

Stig Brautaset, <stig@brautaset.org>

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.

2022-04-09 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.