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
« Reversi/Bot.pm ↑ Summary Reversi/Scoring.pm »
1 package Game::Reversi::Rules;
2  
3 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 15 ▶use Game::Reversi::Board;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 15 ▶use Game::Reversi::Opening;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 15 our $VERSION = '0.04';
10  
11 22545 ▶sub next_turn {
Subroutine next_turn: called CC=4 SCAR=13.9
Pod documented
12 22545 my ($class, $board, $just_moved) = @_;
13 22545 my $B = 'Game::Reversi::Board';
14  
15 22545 ▶ return ($B->other($just_moved), undef) if $class->in_opening($board);
Branch: 1 branch
BranchTrueFalseTotal
if $class->in_opening($board) 319 22226 22545
16  
17 22226 my $them = $B->other($just_moved);
18 22226 ▶ return ($them, undef) if $B->has_move($board, $them);
Branch: 1 branch
BranchTrueFalseTotal
if $B->has_move($board, $them) 21623 603 22226
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 69410 ▶sub in_opening {
Subroutine in_opening: called CC=1 SCAR=0.0
Pod documented
26 69410 my ($class, $board) = @_;
27 69410 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 510 ▶sub opening_turn {
Subroutine opening_turn: called CC=5 SCAR=16.2
Pod documented
38 510 my ($class, $board, $first) = @_;
39 510 my $B = 'Game::Reversi::Board';
40 510 ▶ $first = Game::Reversi::Opening->first unless defined $first;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $first 0 510 510
41 510 ▶ return $first if $class->in_opening($board);
Branch: 1 branch
BranchTrueFalseTotal
if $class->in_opening($board) 139 371 510
42 371 ▶ return $first if $B->has_move($board, $first);
Branch: 1 branch
BranchTrueFalseTotal
if $B->has_move($board, $first) 370 1 371
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 22302 ▶sub legal {
Subroutine legal: called CC=2 SCAR=6.9
Pod documented
49 22302 my ($class, $board, $colour) = @_;
50 22302 ▶ return Game::Reversi::Opening->legal($board, $colour)
Branch: 1 branch
BranchTrueFalseTotal
if $class->in_opening($board) 381 21921 22302
51 if $class->in_opening($board);
52  
53 21921 require Game::Reversi::Move;
54 21921 my $B = 'Game::Reversi::Board';
55 return map {
56 21921 Game::Reversi::Move->play($_, $colour, $B->flips_for($board, $_, $colour))
57 } $B->legal_moves($board, $colour);
58 }
59  
60 15 1;
61  
62 __END__
« Reversi/Bot.pm ↑ Summary Reversi/Scoring.pm »