line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Games::LMSolve; |
2
|
|
|
|
|
|
|
$Games::LMSolve::VERSION = '0.14.1'; |
3
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
22
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
26
|
use 5.008; |
|
1
|
|
|
|
|
4
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
6
|
use Getopt::Long; |
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
17
|
|
9
|
1
|
|
|
1
|
|
781
|
use Pod::Usage; |
|
1
|
|
|
|
|
51797
|
|
|
1
|
|
|
|
|
537
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# You can think of this module as a Factory[1] for the solver classes. |
12
|
|
|
|
|
|
|
# It reads the -g/--game/--preset [variant name] command line option |
13
|
|
|
|
|
|
|
# and determines which class to instantiate based on it. |
14
|
|
|
|
|
|
|
# |
15
|
|
|
|
|
|
|
# Note that it does not touch the other command line options so the |
16
|
|
|
|
|
|
|
# GetOptions() called by the main() function of the class will be |
17
|
|
|
|
|
|
|
# able to process them. |
18
|
|
|
|
|
|
|
# |
19
|
|
|
|
|
|
|
# [1] - Refer to the book "Design Patterns" by Erich Gamma et. al. |
20
|
|
|
|
|
|
|
# |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub new |
24
|
|
|
|
|
|
|
{ |
25
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
my $self = {}; |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
bless $self, $class; |
30
|
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
$self->_initialize(@_); |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
return $self; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub _initialize |
37
|
|
|
|
|
|
|
{ |
38
|
0
|
|
|
0
|
|
|
my $self = shift; |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
my %args = @_; |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
$self->{'games_solvers'} = {}; |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
$self->register_all_solvers(); |
45
|
|
|
|
|
|
|
|
46
|
0
|
0
|
|
|
|
|
if ( exists( $args{'default_variant'} ) ) |
47
|
|
|
|
|
|
|
{ |
48
|
0
|
|
|
|
|
|
$self->set_default_variant( $args{'default_variant'} ); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
return 0; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub set_default_variant |
56
|
|
|
|
|
|
|
{ |
57
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
my $variant = shift; |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
$self->{'default_variant'} = $variant; |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
return 0; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub register_solvers |
68
|
|
|
|
|
|
|
{ |
69
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
my $games = shift; |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
$self->{'games_solvers'} = { %{ $self->{'games_solvers'} }, %$games }; |
|
0
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
return 0; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub register_all_solvers |
80
|
|
|
|
|
|
|
{ |
81
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
return 0; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub main |
88
|
|
|
|
|
|
|
{ |
89
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
my $variant = $self->{'default_variant'}; |
92
|
0
|
|
|
|
|
|
my $help = 0; |
93
|
0
|
|
|
|
|
|
my $man = 0; |
94
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
Getopt::Long::Configure('pass_through'); |
96
|
0
|
0
|
|
|
|
|
GetOptions( |
97
|
|
|
|
|
|
|
"g|game=s" => \$variant, |
98
|
|
|
|
|
|
|
'help|h|?' => \$help, |
99
|
|
|
|
|
|
|
'man' => \$man |
100
|
|
|
|
|
|
|
) or pod2usage(2); |
101
|
|
|
|
|
|
|
|
102
|
0
|
0
|
|
|
|
|
pod2usage(1) if $help; |
103
|
0
|
0
|
|
|
|
|
pod2usage( -exitstatus => 0, -verbose => 2 ) if $man; |
104
|
|
|
|
|
|
|
|
105
|
0
|
0
|
|
|
|
|
if ( !exists( $self->{'games_solvers'}->{$variant} ) ) |
106
|
|
|
|
|
|
|
{ |
107
|
0
|
|
|
|
|
|
die "Unknown game variant \"$variant\""; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
my $class = $self->{'games_solvers'}->{$variant}; |
111
|
0
|
|
|
|
|
|
my $game; |
112
|
0
|
0
|
|
|
|
|
if ( ref($class) eq "CODE" ) |
113
|
|
|
|
|
|
|
{ |
114
|
0
|
|
|
|
|
|
$game = $class->(); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
else |
117
|
|
|
|
|
|
|
{ |
118
|
0
|
|
|
|
|
|
$game = $class->new(); |
119
|
|
|
|
|
|
|
} |
120
|
0
|
|
|
|
|
|
$game->main(); |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
1; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
__END__ |