blib/lib/Game/Reversi/Rules.pm

filter: Statementstmt 100% 41 / 41 Branchbran 85.0% 17 / 20 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 9 / 9 Podpod 100% 5 / 5 totaltotal 93.7% 75 / 80 CC 12 SCAR 12.0
CC
12
Cov
94%
opening_turn
5.0
over
4.1
next_turn
4.0
CRAP 3.3
« blib/lib/Game/Reversi/Bot.pm ↑ Summary blib/lib/Game/Reversi/Scoring.pm »
1 package Game::Reversi::Rules;
2  
3 33 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 33 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 33 ▶use Game::Reversi::Board;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 33 ▶use Game::Reversi::Opening;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 33 our $VERSION = '0.05';
10  
11 22599 ▶sub next_turn {
Subroutine next_turn: called CC=4 SCAR=13.9
Pod documented
12 22599 my ($class, $board, $just_moved) = @_;
13 22599 my $B = 'Game::Reversi::Board';
14  
15 22599 ▶ return ($B->other($just_moved), undef) if $class->in_opening($board);
Branch: 1 branch
BranchTrueFalseTotal
if $class->in_opening($board) 319 22280 22599
16  
17 22280 my $them = $B->other($just_moved);
18 22280 ▶ return ($them, undef) if $B->has_move($board, $them);
Branch: 1 branch
BranchTrueFalseTotal
if $B->has_move($board, $them) 21677 603 22280
19  
20 603 ▶ return ($just_moved, $them) if $B->has_move($board, $just_moved);
Branch: 1 branch
BranchTrueFalseTotal
if $B->has_move($board, $just_moved) 240 363 603
21  
22 363 return (undef, $them);
23 }
24  
25 69633 ▶sub in_opening {
Subroutine in_opening: called CC=1 SCAR=0.0
Pod documented
26 69633 my ($class, $board) = @_;
27 69633 return Game::Reversi::Opening->in_opening($board);
28 }
29  
30 6 ▶sub over {
Subroutine over: called CC=4 SCAR=14.1
Pod documented
31 6 my ($class, $board) = @_;
32 6 my $B = 'Game::Reversi::Board';
33 6 ▶ return 0 if $class->in_opening($board);
Branch: 1 branch
BranchTrueFalseTotal
if $class->in_opening($board) 0 6 6
34 6 ▶ return ($B->has_move($board, 'b') || $B->has_move($board, 'w')) ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$B->has_move($board, 'b') || $B->has_move($board, 'w') ? : 1 5 6
Condition66%2/3
$B->has_move($board, "b") or $B->has_move($board, "w")
l!l&&r!l&&!r
105
MC/DC50%1/2
$B->has_move($board, "b") or $B->has_move($board, "w")
$B->has_move($board, "b") $B->has_move($board, "w")
Truth table66%2/3
A or B
A= $B->has_move($board, "b")B= $B->has_move($board, "w")
ABresult
1X1
011
000
35 }
36  
37 530 ▶sub opening_turn {
Subroutine opening_turn: called CC=5 SCAR=16.2
Pod documented
38 530 my ($class, $board, $first) = @_;
39 530 my $B = 'Game::Reversi::Board';
40 530 ▶ $first = Game::Reversi::Opening->first unless defined $first;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $first 0 530 530
41 530 ▶ return $first if $class->in_opening($board);
Branch: 1 branch
BranchTrueFalseTotal
if $class->in_opening($board) 139 391 530
42 391 ▶ return $first if $B->has_move($board, $first);
Branch: 1 branch
BranchTrueFalseTotal
if $B->has_move($board, $first) 390 1 391
43 1 my $them = $B->other($first);
44 1 ▶ return $them if $B->has_move($board, $them);
Branch: 1 branch
BranchTrueFalseTotal
if $B->has_move($board, $them) 0 1 1
45 1 return undef;
46 }
47  
48 22352 ▶sub legal {
Subroutine legal: called CC=2 SCAR=6.9
Pod documented
49 22352 my ($class, $board, $colour) = @_;
50 22352 ▶ return Game::Reversi::Opening->legal($board, $colour)
Branch: 1 branch
BranchTrueFalseTotal
if $class->in_opening($board) 381 21971 22352
51 if $class->in_opening($board);
52  
53 21971 require Game::Reversi::Move;
54 21971 my $B = 'Game::Reversi::Board';
55 return map {
56 21971 Game::Reversi::Move->play($_, $colour, $B->flips_for($board, $_, $colour))
57 } $B->legal_moves($board, $colour);
58 }
59  
60 33 1;
61  
62 __END__
« blib/lib/Game/Reversi/Bot.pm ↑ Summary blib/lib/Game/Reversi/Scoring.pm »