File Coverage

blib/lib/Games/AlphaBeta/Position.pm
Criterion Covered Total %
statement 13 15 86.6
branch n/a
condition n/a
subroutine 5 7 71.4
pod 3 3 100.0
total 21 25 84.0


line stmt bran cond sub pod time code
1             package Games::AlphaBeta::Position;
2 2     2   11 use base qw(Games::Sequential::Position);
  2         3  
  2         974  
3              
4 2     2   12 use strict;
  2         4  
  2         64  
5 2     2   12 use warnings;
  2         12  
  2         60  
6              
7 2     2   10 use Carp;
  2         4  
  2         332  
8              
9             our $VERSION = '0.1.2';
10              
11             =head1 NAME
12              
13             Games::AlphaBeta::Position - base Position class for use with Games::AlphaBeta
14              
15             =head1 SYNOPSIS
16              
17             package My::GamePos;
18             use base qw(Games::AlphaBeta::Position);
19              
20             sub apply { ... }
21             sub endpos { ... } # optional
22             sub evaluate { ... }
23             sub findmoves { ... }
24              
25             package main;
26             my $pos = My::GamePos->new;
27             my $game = Games::AlphaBeta->new($pos);
28              
29              
30             =head1 DESCRIPTION
31              
32             Games::AlphaBeta::Position is a base class for position-classes
33             that can be used with L. It inherits most of
34             its methods from L; make sure you
35             read its documentation.
36              
37             This class is provided for convenience. You don't need this class
38             in order to use L. It is, however, also
39             possible to make use of this class on its own.
40              
41             =head1 INHERITED METHODS
42              
43             The following methods are inherited from
44             L:
45              
46             =over
47              
48             =item new
49              
50             =item init
51              
52             =item copy
53              
54             =item player
55              
56             =back
57              
58             =head1 VIRTUAL METHODS
59              
60             Modules inheriting this class must implement the following
61             methods (in addition to C and anything else required by
62             L): C &
63             C.
64              
65             =over 4
66              
67             =item findmoves()
68              
69             Return an array of all moves possible for the current player at
70             the current position. Don't forget to return a null move if the
71             player is allowed to pass; an empty array returned here denotes
72             an ending position in the game.
73              
74             =cut
75              
76             sub findmoves {
77 0     0 1 0 croak "Called pure virtual method 'findmoves'\n";
78             }
79              
80             =item evaluate()
81              
82             Return the "fitness" value for the current player at the current
83             position.
84              
85             =cut
86              
87             sub evaluate {
88 0     0 1 0 croak "Called pure virtual method 'evaluate'\n";
89             }
90              
91              
92             =back
93              
94              
95             =head1 METHODS
96              
97             The following methods are provided by this class.
98              
99             =over 4
100              
101             =item endpos
102              
103             True if the position is an ending position, i.e. either a draw or
104             a win for one of the players.
105              
106             Note: Not all games need this method, so the default
107             implementation provided by this modules always returns false.
108              
109             =cut
110              
111 2793     2793 1 19585 sub endpos { return undef; }
112              
113             1; # ensure using this module works
114             __END__