blib/lib/Games/AlphaBeta/Position.pm

filter: Statementstmt 88.2% 15 / 17 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 71.4% 5 / 7 Podpod 100% 3 / 3 totaltotal 85.1% 23 / 27 CC 1 SCAR 2.5
CC
1
Cov
88%
findmoves
2.0
evaluate
2.0
BEGIN
1.0
CRAP 1.3
« blib/lib/Games/Sequential/Position.pm ↑ Summary bin/othello-demo »
1 package Games::AlphaBeta::Position;
2 3 ▶use base qw(Games::Sequential::Position);
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 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<Games::AlphaBeta>. It inherits most of
34 its methods from L<Games::Sequential::Position>; 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<Games::AlphaBeta>. 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<Games::Sequential::Position>:
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<apply()> and anything else required by
62 L<Games::Sequential::Position>): C<evaluate()> &amp;
63 C<findmoves()>.
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 0 ▶sub findmoves {
Subroutine findmoves: not called CC=1 SCAR=6.9
Pod documented
77 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 0 ▶sub evaluate {
Subroutine evaluate: not called CC=1 SCAR=6.9
Pod documented
88 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 5586 ▶sub endpos { return undef; }
Subroutine endpos: called CC=1 SCAR=0.0
Pod documented
112  
113 3 1; # ensure using this module works
114 __END__
« blib/lib/Games/Sequential/Position.pm ↑ Summary bin/othello-demo »