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 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 11 ▶use Game::Reversi::Board;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 11 ▶use Game::Reversi::Opening;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 11 our $VERSION = '0.03';
10  
11 21850 ▶sub next_turn {
Subroutine next_turn: called CC=4 SCAR=13.9
Pod documented
12 21850 my ($class, $board, $just_moved) = @_;
13 21850 my $B = 'Game::Reversi::Board';
14  
15 21850 ▶ return ($B->other($just_moved), undef) if $class->in_opening($board);
Branch: 1 branch
BranchTrueFalseTotal
if $class->in_opening($board) 234 21616 21850
16  
17 21616 my $them = $B->other($just_moved);
18 21616 ▶ return ($them, undef) if $B->has_move($board, $them);
Branch: 1 branch
BranchTrueFalseTotal
if $B->has_move($board, $them) 21037 579 21616
19  
20 579 ▶ return ($just_moved, $them) if $B->has_move($board, $just_moved);
Branch: 1 branch
BranchTrueFalseTotal
if $B->has_move($board, $just_moved) 220 359 579
21  
22 359 return (undef, $them);
23 }
24  
25 67434 ▶sub in_opening {
Subroutine in_opening: called CC=1 SCAR=0.0
Pod documented
26 67434 my ($class, $board) = @_;
27 67434 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 451 ▶sub opening_turn {
Subroutine opening_turn: called CC=5 SCAR=16.2
Pod documented
38 451 my ($class, $board, $first) = @_;
39 451 my $B = 'Game::Reversi::Board';
40 451 ▶ $first = Game::Reversi::Opening->first unless defined $first;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $first 0 451 451
41 451 ▶ return $first if $class->in_opening($board);
Branch: 1 branch
BranchTrueFalseTotal
if $class->in_opening($board) 109 342 451
42 342 ▶ return $first if $B->has_move($board, $first);
Branch: 1 branch
BranchTrueFalseTotal
if $B->has_move($board, $first) 341 1 342
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 21987 ▶sub legal {
Subroutine legal: called CC=2 SCAR=6.9
Pod documented
49 21987 my ($class, $board, $colour) = @_;
50 21987 ▶ return Game::Reversi::Opening->legal($board, $colour)
Branch: 1 branch
BranchTrueFalseTotal
if $class->in_opening($board) 336 21651 21987
51 if $class->in_opening($board);
52  
53 21651 require Game::Reversi::Move;
54 21651 my $B = 'Game::Reversi::Board';
55 return map {
56 21651 Game::Reversi::Move->play($_, $colour, $B->flips_for($board, $_, $colour))
57 } $B->legal_moves($board, $colour);
58 }
59  
60 11 1;
61  
62 __END__
« Reversi/Bot.pm ↑ Summary Reversi/Scoring.pm »