| 1 | package Game::Cribbage; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | our $VERSION = "0.16"; | |||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Object::Proto::Sugar -types; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Game::Cribbage::Board; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | has board => ( | ||||||||||||||||||||||||||||
| 9 | is => 'rw', | ||||||||||||||||||||||||||||
| 10 | isa => Object | ||||||||||||||||||||||||||||
| 11 | 2 | ); | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | has [qw/dealer crib_set/] => ( | ||||||||||||||||||||||||||||
| 14 | is => 'rw', | ||||||||||||||||||||||||||||
| 15 | isa => Bool, | ||||||||||||||||||||||||||||
| 16 | default => 0 | ||||||||||||||||||||||||||||
| 17 | 2 | ); | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | has starter_card => ( | ||||||||||||||||||||||||||||
| 20 | is => 'rw' | ||||||||||||||||||||||||||||
| 21 | 2 | ); | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 0 | ▶ | sub start { | ||||||||||||||||||||||||||
|
Subroutine
start: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 24 | 0 | my ($self, %params) = @_; | |||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 0 | $self->clear_screen; | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 0 | $self->print_header("Welcome to terminal Cribbage"); | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 0 | $self->print_footer("Insert name: "); | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 0 | my $name = <STDIN>; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 0 | chomp($name); | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 0 | my $board = Game::Cribbage::Board->new(); | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | $board->add_player(name => 'Bot'); | |||||||||||||||||||||||||||
| 39 | 0 | $board->add_player(name => $name); | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | $board->start_game(); | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 0 | $self->board($board); | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | $self->init_game(); | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 0 | ▶ | sub init_game { | ||||||||||||||||||||||||||
|
Subroutine
init_game: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 49 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 0 | $self->clear_screen; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 0 | $self->reset_cursor(); | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 0 | $self->split_cards(); | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 0 | $self->init_draw(); | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | sub init_draw { | ||||||||||||||||||||||||||
|
Subroutine
init_draw: not called CC=11 SCAR=48.8
Pod
documented
| |||||||||||||||||||||||||||||
| 61 | 0 | my ($self, $switch) = @_; | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 0 | $self->crib_set(0); | |||||||||||||||||||||||||||
| 64 | 0 | $self->starter_card(undef); | |||||||||||||||||||||||||||
| 65 | 0 | ▶ | $self->dealer(!$self->dealer) if $switch; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 0 | my $winner; | |||||||||||||||||||||||||||
| 68 | 0 | ▶ | if ($self->board->score->player1->{current} > 120) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 69 | 0 | $winner = 'player1'; | |||||||||||||||||||||||||||
| 70 | } elsif ($self->board->score->player2->{current} > 120) { | ||||||||||||||||||||||||||||
| 71 | 0 | $winner = 'player2'; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | 0 | ▶ | return $self->winner($winner) if $winner; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | $self->draw_cards(); | |||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | $self->discard_cards(); | |||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | $self->starter(); | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 0 | ▶ | while (!$winner) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | 0 | $self->clear_screen(); | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 0 | $self->print_header(q|It is your turn to play a card, type go if you're unable to play.|); | |||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 0 | my $ok = eval { $self->play_hand(); }; | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 0 | ▶ | unless ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | 0 | ▶ | if ($self->board->score->player1->{current} > 120) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 90 | 0 | $winner = 'player1'; | |||||||||||||||||||||||||||
| 91 | 0 | next; | |||||||||||||||||||||||||||
| 92 | } elsif ($self->board->score->player2->{current} > 120) { | ||||||||||||||||||||||||||||
| 93 | 0 | $winner = 'player2'; | |||||||||||||||||||||||||||
| 94 | 0 | next; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 0 | my $hands = $self->board->get_hands; | |||||||||||||||||||||||||||
| 99 | 0 | ▶ | unless (grep { !$_->used } @{$hands->player2->cards}, @{$hands->player1->cards}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | 0 | eval { | |||||||||||||||||||||||||||
| 101 | 0 | $self->end_hands(); | |||||||||||||||||||||||||||
| 102 | }; | ||||||||||||||||||||||||||||
| 103 | 0 | return $self->init_draw(1); | |||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 0 | ▶ | if ($self->board->no_player_can_play) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | 0 | eval { $self->board->next_play(); }; | |||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | 0 | $self->winner($winner); | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 0 | ▶ | sub end_hands { | ||||||||||||||||||||||||||
|
Subroutine
end_hands: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 115 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 0 | $self->board->end_play(); | |||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 0 | my $hands = $self->board->get_hands; | |||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 0 | $self->board->end_hands(); | |||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 0 | $self->crib_set(0); | |||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 0 | $self->clear_screen(); | |||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 0 | my $last = $self->board->last_round_hands(); | |||||||||||||||||||||||||||
| 128 | 0 | my $player1_score = $last->player1->score->total_score; | |||||||||||||||||||||||||||
| 129 | 0 | my $player2_score = $last->player2->score->total_score; | |||||||||||||||||||||||||||
| 130 | 0 | ▶ | my $crib_player = $self->dealer ? $self->board->players->[-1]->name : 'Bot'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | 0 | ▶ | my $player = $self->dealer ? 'player2' : 'player1'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 132 | 0 | my $crib_score = $last->$player->crib_score->total_score; | |||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | 0 | $self->print_header(sprintf "Bot scored: %s - %s scored: %s - %s crib scored: %s", | |||||||||||||||||||||||||||
| 135 | $player1_score, | ||||||||||||||||||||||||||||
| 136 | $self->board->players->[-1]->name, | ||||||||||||||||||||||||||||
| 137 | $player2_score, | ||||||||||||||||||||||||||||
| 138 | $crib_player, | ||||||||||||||||||||||||||||
| 139 | $crib_score | ||||||||||||||||||||||||||||
| 140 | ); | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 0 | $self->draw_scores(); | |||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 0 | $self->render_player_cards($hands->player1->cards, 3, 20, 1); | |||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | 0 | $crib_player = $hands->crib_player; | |||||||||||||||||||||||||||
| 147 | 0 | $self->render_player_cards($hands->$crib_player->crib, 15, 20, 1); | |||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | 0 | $self->render_player_cards($hands->player2->cards, 26, 20, 1); | |||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||
| 151 | 0 | $self->print_footer(q|Press enter to continue|); | |||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | <STDIN> | ||||||||||||||||||||||||||||
| 154 | 0 | } | |||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 0 | ▶ | sub play_hand { | ||||||||||||||||||||||||||
|
Subroutine
play_hand: not called CC=18 SCAR=58.3
Pod
documented
| |||||||||||||||||||||||||||||
| 157 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | 0 | my $hands = $self->board->get_hands; | |||||||||||||||||||||||||||
| 160 | 0 | ▶ | if ($self->board->next_to_play->player eq 'player1') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 161 | 0 | my $card = $self->board->best_run_play('player1'); | |||||||||||||||||||||||||||
| 162 | 0 | ▶ | if ($card->can('go') && $card->go) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$card->can("go") and $card->go
MC/DC0%0/2
$card->can("go") and $card->go
$card->can("go")
$card->go
Truth table0%0/3
A and B
A= $card->can("go")B= $card->go
| |||||||||||||||||||||||||||||
| 163 | 0 | $self->board->cannot_play('player1'); | |||||||||||||||||||||||||||
| 164 | 0 | $self->draw_go(6, 2); | |||||||||||||||||||||||||||
| 165 | } else { | ||||||||||||||||||||||||||||
| 166 | 0 | $self->board->play_card('player1', $card); | |||||||||||||||||||||||||||
| 167 | 0 | ▶ | if ($self->board->current_play_score == 31) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 168 | 0 | $self->board->next_play(); | |||||||||||||||||||||||||||
| 169 | 0 | return; | |||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 0 | ▶ | if ($self->board->score->player1->{current} > 120) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 173 | 0 | return; | |||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | 0 | ▶ | if ($self->board->player_cannot_play('player2')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 179 | 0 | ▶ | if (!$self->board->player_cannot_play('player1')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 180 | 0 | $self->board->set_next_to_play('player1'); | |||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||
| 182 | 0 | return; | |||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | 0 | $_[0]->draw_scores(); | |||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | 0 | $self->render_opponent_cards(scalar grep { !$_->used } @{$hands->player1->cards}); | |||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | 0 | $self->render_run_play(); | |||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||
| 191 | 0 | $self->render_player_cards($hands->player2->cards, 26, 20); | |||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | 0 | $self->print_footer(q|Pick a card: |); | |||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | 0 | my $number = <STDIN>; | |||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||
| 197 | 0 | chomp($number); | |||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | 0 | ▶ | if ($number =~ m/go/i) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 200 | 0 | my @can = $self->board->cannot_play('player2'); | |||||||||||||||||||||||||||
| 201 | 0 | ▶ | if (scalar @can && ref $can[0]) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
scalar @can and ref $can[0]
MC/DC0%0/2
scalar @can and ref $can[0]
scalar @can
ref $can[0]
Truth table0%0/3
A and B
A= scalar @canB= ref $can[0]
| |||||||||||||||||||||||||||||
| 202 | 0 | return; | |||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||
| 204 | 0 | $self->draw_go(30); | |||||||||||||||||||||||||||
| 205 | 0 | return; | |||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | 0 | ▶ | if ($number eq 'b') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 209 | 0 | my $card = $self->board->best_run_play('player2'); | |||||||||||||||||||||||||||
| 210 | 0 | ▶ | if ($card->can('go') && $card->go) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$card->can("go") and $card->go
MC/DC0%0/2
$card->can("go") and $card->go
$card->can("go")
$card->go
Truth table0%0/3
A and B
A= $card->can("go")B= $card->go
| |||||||||||||||||||||||||||||
| 211 | 0 | $self->board->cannot_play('player2'); | |||||||||||||||||||||||||||
| 212 | 0 | $self->draw_go(6, 2); | |||||||||||||||||||||||||||
| 213 | } else { | ||||||||||||||||||||||||||||
| 214 | 0 | $self->board->play_card('player2', $card); | |||||||||||||||||||||||||||
| 215 | 0 | ▶ | if ($self->board->current_play_score == 31) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 216 | 0 | $self->board->next_play(); | |||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||
| 219 | 0 | return; | |||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||
| 222 | 0 | ▶ | if ($number !~ m/^\d+$/ || $number > scalar @{$hands->player2->cards}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $number =~ /^\d+$/ or $number > scalar @{$hands->player2->cards;}
MC/DC0%0/2
not $number =~ /^\d+$/ or $number > scalar @{$hands->player2->cards;}
not $number =~ /^\d+$/
$number > scalar @{$hands->player2->cards;}
Truth table0%0/3
not(A) or B
A= not $number =~ /^\d+$/B= $number > scalar @{$hands->player2->cards;}
| |||||||||||||||||||||||||||||
| 223 | 0 | return; | |||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | 0 | my $card = $self->board->get_card('player2', $number - 1); | |||||||||||||||||||||||||||
| 227 | 0 | $self->board->play_card('player2', $card); | |||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | 0 | ▶ | if ($self->board->current_play_score == 31) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 230 | 0 | $self->board->next_play(); | |||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | 0 | return 1; | |||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||
| 236 | 0 | ▶ | sub split_cards { | ||||||||||||||||||||||||||
|
Subroutine
split_cards: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||
| 237 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | 0 | $self->print_header(q|Split cards lowest goes first|); | |||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | 0 | $self->show_face_down_split(52); | |||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | 0 | $self->print_footer(q|Pick a number: |); | |||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | 0 | my $number = <STDIN>; | |||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | 0 | ▶ | if ($number !~ m/^\d+$/ || $number > 52) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $number =~ /^\d+$/ or $number > 52
MC/DC0%0/2
not $number =~ /^\d+$/ or $number > 52
not $number =~ /^\d+$/
$number > 52
Truth table0%0/3
not(A) or B
A= not $number =~ /^\d+$/B= $number > 52
| |||||||||||||||||||||||||||||
| 248 | 0 | $self->clear_screen(); | |||||||||||||||||||||||||||
| 249 | 0 | $self->split_cards(); | |||||||||||||||||||||||||||
| 250 | 0 | return; | |||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | 0 | my $low = $self->board->deck->get($number - 1); | |||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | 0 | my $rand = int(rand(52)); | |||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | 0 | ▶ | while ($number == $rand) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 258 | 0 | $rand = int(rand(52)); | |||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | 0 | my $bot = $self->board->deck->get($rand - 1); | |||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||
| 263 | 0 | $self->clear_screen(); | |||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | 0 | ▶ | my $dealer = $low->value < $bot->value ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | 0 | ▶ | $self->print_header(q|Low cards picked, | . ($dealer ? "you are the dealer" : "they are the dealer")); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||
| 269 | 0 | $self->render_card($bot, 2, 45); | |||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||
| 271 | 0 | $self->render_card($low, 27, 45); | |||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||
| 273 | 0 | ▶ | $self->board->set_crib_player($dealer ? 'player2' : 'player1'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||
| 275 | 0 | $self->print_footer(q|Press enter to continue|); | |||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||
| 277 | 0 | $self->dealer($dealer); | |||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||
| 279 | <STDIN> | ||||||||||||||||||||||||||||
| 280 | 0 | } | |||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||
| 282 | 1 | ▶ | sub draw_cards { | ||||||||||||||||||||||||||
|
Subroutine
draw_cards: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 283 | 1 | my ($self) = @_; | |||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||
| 285 | 1 | $self->board->draw_hands(); | |||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||
| 288 | 0 | ▶ | sub discard_cards { | ||||||||||||||||||||||||||
|
Subroutine
discard_cards: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 289 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||
| 291 | 0 | $self->clear_screen(); | |||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||
| 293 | 0 | $self->print_header(q|Discard two cards to the crib, seperate the indexes with a space.|); | |||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||
| 295 | 0 | my $hands = $self->board->get_hands; | |||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||
| 297 | 0 | $self->render_opponent_cards(6); | |||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||
| 299 | 0 | $self->render_player_cards($hands->player2->cards, 26, 5); | |||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||
| 301 | 0 | $self->print_footer(q|Discard cards: |); | |||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||
| 303 | 0 | my $cards_index = <STDIN>; | |||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | 0 | chomp($cards_index); | |||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||
| 307 | 0 | my @cards; | |||||||||||||||||||||||||||
| 308 | 0 | ▶ | if ($cards_index =~ m/b/i) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 309 | 0 | my @worst = $self->board->identify_worst_cards('player2'); | |||||||||||||||||||||||||||
| 310 | 0 | @cards = @{$worst[0]}; | |||||||||||||||||||||||||||
| 311 | } else { | ||||||||||||||||||||||||||||
| 312 | @cards = map { | ||||||||||||||||||||||||||||
| 313 | 0 | $self->board->get_card('player2', $_ - 1); | |||||||||||||||||||||||||||
| 314 | 0 | ▶ | } grep { $_ =~ m/^\d+$/ && $_ <= 6 } split " ", $cards_index; | ||||||||||||||||||||||||||
|
Condition0%0/3
$_ =~ /^\d+$/ && $_ <= 6
MC/DC0%0/2
$_ =~ /^\d+$/ && $_ <= 6
$_ =~ /^\d+$/
$_ <= 6
Truth table0%0/3
A && B
A= $_ =~ /^\d+$/B= $_ <= 6
| |||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||
| 317 | 0 | ▶ | unless (scalar @cards == 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 318 | 0 | $self->discard_cards(); | |||||||||||||||||||||||||||
| 319 | 0 | return; | |||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||
| 322 | 0 | $self->board->crib_player_cards('player2', \@cards); | |||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||
| 324 | 0 | my @bot = $self->board->identify_worst_cards('player1'); | |||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||
| 326 | 0 | $self->board->crib_player_cards('player1', $bot[0]); | |||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||
| 328 | 0 | $self->crib_set(1); | |||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||
| 331 | 0 | ▶ | sub starter { | ||||||||||||||||||||||||||
|
Subroutine
starter: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 332 | 0 | my ($self) = @_; | |||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||
| 334 | 0 | $self->clear_screen(); | |||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||
| 336 | 0 | my $count = scalar @{$self->board->deck->deck}; | |||||||||||||||||||||||||||
| 337 | 0 | ▶ | if ($self->dealer) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 338 | 0 | my $card = $self->board->deck->get(int(rand(39))); | |||||||||||||||||||||||||||
| 339 | 0 | $self->starter_card($card); | |||||||||||||||||||||||||||
| 340 | 0 | $self->board->add_starter_card('player1', $card); | |||||||||||||||||||||||||||
| 341 | 0 | return; | |||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||
| 344 | 0 | $self->print_header(q|Split deck for starter card.|); | |||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||
| 346 | 0 | $self->show_face_down_split(40, 13); | |||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||
| 348 | 0 | $self->print_footer(q|Split deck: |); | |||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||
| 350 | 0 | my $number = <STDIN>; | |||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||
| 352 | 0 | chomp($number); | |||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||
| 354 | 0 | ▶ | if ($number !~ m/^\d+$/ || $number > 52) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $number =~ /^\d+$/ or $number > 52
MC/DC0%0/2
not $number =~ /^\d+$/ or $number > 52
not $number =~ /^\d+$/
$number > 52
Truth table0%0/3
not(A) or B
A= not $number =~ /^\d+$/B= $number > 52
| |||||||||||||||||||||||||||||
| 355 | 0 | $self->clear_screen(); | |||||||||||||||||||||||||||
| 356 | 0 | $self->starter(); | |||||||||||||||||||||||||||
| 357 | 0 | return; | |||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||
| 360 | 0 | my $card = $self->board->deck->get($number); | |||||||||||||||||||||||||||
| 361 | 0 | $self->starter_card($card); | |||||||||||||||||||||||||||
| 362 | 0 | my $scored = $self->board->add_starter_card('player2', $card); | |||||||||||||||||||||||||||
| 363 | 0 | return; | |||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||
| 366 | 23 | ▶ | sub render_card { | ||||||||||||||||||||||||||
|
Subroutine
render_card: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 367 | 23 | my ($self, $card, $row, $col) = @_; | |||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||
| 369 | 23 | $self->set_cursor_vertical($row); | |||||||||||||||||||||||||||
| 370 | 23 | $self->set_cursor_horizontal($col); | |||||||||||||||||||||||||||
| 371 | 23 | ▶ | my $color = $card->suit =~ m/H|D/ ? 91 : 90; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||
| 373 | 23 | my %suits = ( | |||||||||||||||||||||||||||
| 374 | H => '♥', | ||||||||||||||||||||||||||||
| 375 | D => '♦', | ||||||||||||||||||||||||||||
| 376 | C => '♣', | ||||||||||||||||||||||||||||
| 377 | S => '♠' | ||||||||||||||||||||||||||||
| 378 | ); | ||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||
| 380 | my @card = ( | ||||||||||||||||||||||||||||
| 381 | "┌─────────┐", | ||||||||||||||||||||||||||||
| 382 | sprintf("│%s. . . .│", $card->symbol =~ m/10/ ? $card->symbol : $card->symbol . " "), | ||||||||||||||||||||||||||||
| 383 | "│. . . . .│", | ||||||||||||||||||||||||||||
| 384 | "│. . . . .│", | ||||||||||||||||||||||||||||
| 385 | 23 | ▶ | sprintf("│. . %s . .│", $suits{$card->suit}), | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 386 | "│. . . . .│", | ||||||||||||||||||||||||||||
| 387 | "│. . . . .│", | ||||||||||||||||||||||||||||
| 388 | sprintf("│. . . .%s│", $card->symbol =~ m/10/ ? $card->symbol : " " . $card->symbol), | ||||||||||||||||||||||||||||
| 389 | "└─────────┘" | ||||||||||||||||||||||||||||
| 390 | ); | ||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||
| 392 | 23 | for (@card) { | |||||||||||||||||||||||||||
| 393 | 207 | $self->say($_, 1, 0, $color); | |||||||||||||||||||||||||||
| 394 | 207 | $self->set_cursor_horizontal($col); | |||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||
| 399 | 2 | ▶ | sub render_opponent_cards { | ||||||||||||||||||||||||||
|
Subroutine
render_opponent_cards: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 400 | 2 | my ($self, $num) = @_; | |||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||
| 402 | 2 | ▶ | return unless $num; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||
| 404 | 1 | $self->set_cursor_vertical(2); | |||||||||||||||||||||||||||
| 405 | 1 | $self->set_cursor_horizontal((100 - ($num * 4)) / 2); | |||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||
| 407 | 1 | my $string = "┌──" x ($num - 1); | |||||||||||||||||||||||||||
| 408 | 1 | $self->say($string); | |||||||||||||||||||||||||||
| 409 | 1 | $self->say("┌─────────┐", 1, 1); | |||||||||||||||||||||||||||
| 410 | 1 | $self->set_cursor_horizontal((100 - ($num * 4)) / 2); | |||||||||||||||||||||||||||
| 411 | 1 | for (0..6) { | |||||||||||||||||||||||||||
| 412 | 7 | $string = "│. " x ($num - 1); | |||||||||||||||||||||||||||
| 413 | 7 | $self->say($string); | |||||||||||||||||||||||||||
| 414 | 7 | $self->say("│. . . . .│", 1, 1); | |||||||||||||||||||||||||||
| 415 | 7 | $self->set_cursor_horizontal((100 - ($num * 4)) / 2); | |||||||||||||||||||||||||||
| 416 | } | ||||||||||||||||||||||||||||
| 417 | 1 | $string = "└──" x ($num - 1); | |||||||||||||||||||||||||||
| 418 | 1 | $self->say($string); | |||||||||||||||||||||||||||
| 419 | 1 | $self->say("└─────────┘", 1, 1); | |||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||
| 422 | 2 | ▶ | sub render_player_cards { | ||||||||||||||||||||||||||
|
Subroutine
render_player_cards: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 423 | 2 | my ($self, $cards, $top, $left, $all) = @_; | |||||||||||||||||||||||||||
| 424 | 2 | my $i = 1; | |||||||||||||||||||||||||||
| 425 | 2 | for (@{$cards}) { | |||||||||||||||||||||||||||
| 426 | 6 | ▶ | if (!$all && $_->used) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $all and $_->used
MC/DC100%2/2
not $all and $_->used
not $all
$_->used
Truth table100%3/3
not(A) and B
A= not $allB= $_->used
| |||||||||||||||||||||||||||||
| 427 | 1 | $i++; | |||||||||||||||||||||||||||
| 428 | 1 | next; | |||||||||||||||||||||||||||
| 429 | } | ||||||||||||||||||||||||||||
| 430 | 5 | $left += 11; | |||||||||||||||||||||||||||
| 431 | 5 | $self->set_cursor_vertical($top); | |||||||||||||||||||||||||||
| 432 | 5 | $self->set_cursor_horizontal($left + 5); | |||||||||||||||||||||||||||
| 433 | 5 | $self->say($i++); | |||||||||||||||||||||||||||
| 434 | 5 | $self->render_card($_, $top + 1, $left); | |||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||
| 438 | 2 | ▶ | sub render_run_play { | ||||||||||||||||||||||||||
|
Subroutine
render_run_play: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 439 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||
| 441 | 2 | my $cards = $self->board->current_play->cards; | |||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||
| 443 | 2 | ▶ | return unless (scalar @{$cards}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||
| 445 | 1 | my $left = 25; | |||||||||||||||||||||||||||
| 446 | 1 | for (@{$cards}) { | |||||||||||||||||||||||||||
| 447 | 1 | $self->render_card($_->card, 15, $left); | |||||||||||||||||||||||||||
| 448 | 1 | $left += 10; | |||||||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||
| 452 | |||||||||||||||||||||||||||||
| 453 | 0 | ▶ | sub show_face_down_split { | ||||||||||||||||||||||||||
|
Subroutine
show_face_down_split: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||
| 454 | 0 | my ($self, $num, $vertical) = @_; | |||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||
| 456 | 0 | ▶ | $self->set_cursor_vertical($vertical || 10); | ||||||||||||||||||||||||||
|
Condition0%0/2
$vertical || 10
MC/DC0%0/1
$vertical || 10
$vertical
Truth table0%0/2
A
A= $vertical
| |||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||
| 458 | 0 | my $width = ($num / 2) - 1; | |||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||
| 460 | 0 | for my $it (0 .. 1) { | |||||||||||||||||||||||||||
| 461 | 0 | my $string = "┌──" x $width; | |||||||||||||||||||||||||||
| 462 | 0 | $self->say($string); | |||||||||||||||||||||||||||
| 463 | 0 | $self->say("┌─────────┐", 1, 1); | |||||||||||||||||||||||||||
| 464 | 0 | $string = ""; | |||||||||||||||||||||||||||
| 465 | 0 | for (1 .. $width) { | |||||||||||||||||||||||||||
| 466 | 0 | ▶ | my $v = $it ? 26 + $_ : $_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 467 | 0 | ▶ | $string .= sprintf("│%s", (!$it && $_ < 10 ? "$v " : $v)); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $it and $_ < 10
MC/DC0%0/2
not $it and $_ < 10
not $it
$_ < 10
Truth table0%0/3
not(A) and B
A= not $itB= $_ < 10
| |||||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||
| 469 | 0 | $self->say($string); | |||||||||||||||||||||||||||
| 470 | 0 | ▶ | $self->say(sprintf("│%s. . . .│", $it ? ($width + 1) * 2 : $width + 1), 1, 1); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 471 | 0 | for (0..4) { | |||||||||||||||||||||||||||
| 472 | 0 | $string = "│. " x $width; | |||||||||||||||||||||||||||
| 473 | 0 | $self->say($string); | |||||||||||||||||||||||||||
| 474 | 0 | $self->say("│. . . . .│", 1, 1); | |||||||||||||||||||||||||||
| 475 | } | ||||||||||||||||||||||||||||
| 476 | 0 | $string = "│. " x $width; | |||||||||||||||||||||||||||
| 477 | 0 | $self->say($string); | |||||||||||||||||||||||||||
| 478 | 0 | ▶ | $self->say(sprintf("│. . . .%s│", $it ? ($width + 1) * 2 : $width + 1), 1, 1); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 479 | 0 | my $string = "└──" x $width; | |||||||||||||||||||||||||||
| 480 | 0 | $self->say($string); | |||||||||||||||||||||||||||
| 481 | 0 | $self->say("└─────────┘", 1, 1); | |||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||
| 483 | } | ||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||
| 485 | 0 | ▶ | sub draw_background { | ||||||||||||||||||||||||||
|
Subroutine
draw_background: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 486 | 0 | for (0 .. 35) { | |||||||||||||||||||||||||||
| 487 | 0 | print "\e[102;1m"; | |||||||||||||||||||||||||||
| 488 | 0 | print pack("A100", " "); | |||||||||||||||||||||||||||
| 489 | 0 | print "\n"; | |||||||||||||||||||||||||||
| 490 | 0 | print "\e[0"; | |||||||||||||||||||||||||||
| 491 | } | ||||||||||||||||||||||||||||
| 492 | 0 | $_[0]->draw_dealer(); | |||||||||||||||||||||||||||
| 493 | #$_[0]->draw_scores(); | ||||||||||||||||||||||||||||
| 494 | 0 | $_[0]->draw_crib(); | |||||||||||||||||||||||||||
| 495 | 0 | $_[0]->draw_starter(); | |||||||||||||||||||||||||||
| 496 | 0 | $_[0]->reset_cursor(); | |||||||||||||||||||||||||||
| 497 | } | ||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||
| 499 | 2 | ▶ | sub draw_starter { | ||||||||||||||||||||||||||
|
Subroutine
draw_starter: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 500 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||
| 502 | 2 | ▶ | return unless $self->starter_card; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||
| 504 | 1 | $self->render_card($self->starter_card, 15, 2); | |||||||||||||||||||||||||||
| 505 | } | ||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||
| 508 | 3 | ▶ | sub draw_crib { | ||||||||||||||||||||||||||
|
Subroutine
draw_crib: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 509 | 3 | my ($self) = shift; | |||||||||||||||||||||||||||
| 510 | 3 | my $dealer = $self->dealer; | |||||||||||||||||||||||||||
| 511 | 3 | ▶ | return unless defined $dealer; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 512 | 3 | ▶ | return unless $self->crib_set; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 513 | 2 | my @card = ( | |||||||||||||||||||||||||||
| 514 | "┌─────────┐", | ||||||||||||||||||||||||||||
| 515 | "│. . . . .│", | ||||||||||||||||||||||||||||
| 516 | "│. . . . .│", | ||||||||||||||||||||||||||||
| 517 | "│. . . . .│", | ||||||||||||||||||||||||||||
| 518 | "│. . . . .│", | ||||||||||||||||||||||||||||
| 519 | "│. . . . .│", | ||||||||||||||||||||||||||||
| 520 | "│. . . . .│", | ||||||||||||||||||||||||||||
| 521 | "│. . . . .│", | ||||||||||||||||||||||||||||
| 522 | "└─────────┘" | ||||||||||||||||||||||||||||
| 523 | ); | ||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||
| 525 | 2 | ▶ | if ($dealer) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 526 | 1 | $self->set_cursor_vertical(27); | |||||||||||||||||||||||||||
| 527 | } else { | ||||||||||||||||||||||||||||
| 528 | 1 | $self->set_cursor_vertical(3); | |||||||||||||||||||||||||||
| 529 | } | ||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||
| 531 | 2 | for (@card) { | |||||||||||||||||||||||||||
| 532 | 18 | $self->set_cursor_horizontal(10); | |||||||||||||||||||||||||||
| 533 | 18 | $self->say($_, 1, 0); | |||||||||||||||||||||||||||
| 534 | } | ||||||||||||||||||||||||||||
| 535 | } | ||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||
| 537 | 1 | ▶ | sub draw_go { | ||||||||||||||||||||||||||
|
Subroutine
draw_go: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 538 | 1 | my ($self, $top, $left) = @_; | |||||||||||||||||||||||||||
| 539 | 1 | my $message = ' GO '; | |||||||||||||||||||||||||||
| 540 | 1 | $self->set_cursor_vertical($top); | |||||||||||||||||||||||||||
| 541 | 1 | $self->say($message, 0, 0, 31, 40); | |||||||||||||||||||||||||||
| 542 | } | ||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||
| 545 | 3 | ▶ | sub draw_dealer { | ||||||||||||||||||||||||||
|
Subroutine
draw_dealer: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 546 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||
| 548 | 3 | my $dealer = $self->dealer; | |||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||
| 550 | 3 | ▶ | return unless defined $dealer; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 551 | 3 | my $message = ' Dealer '; | |||||||||||||||||||||||||||
| 552 | 3 | ▶ | if ($dealer) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 553 | 1 | $self->set_cursor_vertical(34); | |||||||||||||||||||||||||||
| 554 | 1 | $self->say($message, 0, 0, 31, 40); | |||||||||||||||||||||||||||
| 555 | } else { | ||||||||||||||||||||||||||||
| 556 | 2 | $self->set_cursor_vertical(3); | |||||||||||||||||||||||||||
| 557 | 2 | $self->say($message, 0, 0, 31, 40); | |||||||||||||||||||||||||||
| 558 | } | ||||||||||||||||||||||||||||
| 559 | } | ||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||
| 561 | 3 | ▶ | sub draw_scores { | ||||||||||||||||||||||||||
|
Subroutine
draw_scores: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 562 | 3 | my ($self) = @_; | |||||||||||||||||||||||||||
| 563 | 3 | my $message; | |||||||||||||||||||||||||||
| 564 | 3 | ▶ | return unless $self->board; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 565 | 2 | ▶ | if ($self->board && $self->board->current_play_score) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->board and $self->board->current_play_score
MC/DC50%1/2
$self->board and $self->board->current_play_score
$self->board
$self->board->current_play_score
Truth table66%2/3
A and B
A= $self->boardB= $self->board->current_play_score
| |||||||||||||||||||||||||||||
| 566 | 1 | $message = pack("A2", $self->board->current_play_score); | |||||||||||||||||||||||||||
| 567 | 1 | $self->set_cursor_vertical(14); | |||||||||||||||||||||||||||
| 568 | 1 | $self->set_cursor_horizontal(49); | |||||||||||||||||||||||||||
| 569 | 1 | $self->say($message, 0, 0, 31, 40); | |||||||||||||||||||||||||||
| 570 | } | ||||||||||||||||||||||||||||
| 571 | 2 | $message = ' Score: ' . $self->board->score->player2->{current} . ' '; | |||||||||||||||||||||||||||
| 572 | 2 | $self->set_cursor_vertical(34); | |||||||||||||||||||||||||||
| 573 | 2 | $self->set_cursor_horizontal(100 - (length($message) + 1)); | |||||||||||||||||||||||||||
| 574 | 2 | $self->say($message, 0, 0, 31, 40); | |||||||||||||||||||||||||||
| 575 | 2 | $message = ' Score: ' . $self->board->score->player1->{current} . ' '; | |||||||||||||||||||||||||||
| 576 | 2 | $self->set_cursor_vertical(3); | |||||||||||||||||||||||||||
| 577 | 2 | $self->set_cursor_horizontal(100 - (length($message) + 1)); | |||||||||||||||||||||||||||
| 578 | 2 | $self->say($message, 0, 0, 31, 40); | |||||||||||||||||||||||||||
| 579 | } | ||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||
| 581 | 0 | ▶ | sub winner { | ||||||||||||||||||||||||||
|
Subroutine
winner: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 582 | 0 | print "\e[0m\e[2J\e[0;1H"; | |||||||||||||||||||||||||||
| 583 | 0 | for (0 .. 35) { | |||||||||||||||||||||||||||
| 584 | 0 | print "\e[102;1m"; | |||||||||||||||||||||||||||
| 585 | 0 | print pack("A100", " "); | |||||||||||||||||||||||||||
| 586 | 0 | print "\n"; | |||||||||||||||||||||||||||
| 587 | 0 | print "\e[0"; | |||||||||||||||||||||||||||
| 588 | } | ||||||||||||||||||||||||||||
| 589 | 0 | $_[0]->set_cursor_vertical(17); | |||||||||||||||||||||||||||
| 590 | 0 | my $player = $_[0]->board->players->[1]; | |||||||||||||||||||||||||||
| 591 | 0 | ▶ | $_[0]->say($_[1] eq 'player2' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 592 | ? sprintf(q|Congratualations %s, you won the game!|, $player->name) | ||||||||||||||||||||||||||||
| 593 | : sprintf(q|Unlucky %s, you lost this time!|, $player->name) | ||||||||||||||||||||||||||||
| 594 | ); | ||||||||||||||||||||||||||||
| 595 | <STDIN> | ||||||||||||||||||||||||||||
| 596 | 0 | } | |||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||
| 599 | 0 | ▶ | sub clear_screen { | ||||||||||||||||||||||||||
|
Subroutine
clear_screen: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 600 | 0 | print "\e[0m\e[2J\e[0;1H"; | |||||||||||||||||||||||||||
| 601 | 0 | $_[0]->draw_background(); | |||||||||||||||||||||||||||
| 602 | } | ||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||
| 604 | 1 | ▶ | sub reset_cursor { | ||||||||||||||||||||||||||
|
Subroutine
reset_cursor: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 605 | 1 | print "\e[;2H"; | |||||||||||||||||||||||||||
| 606 | } | ||||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||
| 608 | 41 | ▶ | sub set_cursor_vertical { | ||||||||||||||||||||||||||
|
Subroutine
set_cursor_vertical: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 609 | 41 | print "\e[$_[1];2H"; | |||||||||||||||||||||||||||
| 610 | } | ||||||||||||||||||||||||||||
| 611 | |||||||||||||||||||||||||||||
| 612 | 278 | ▶ | sub set_cursor_horizontal { | ||||||||||||||||||||||||||
|
Subroutine
set_cursor_horizontal: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 613 | 278 | print "\e[$_[1]G"; | |||||||||||||||||||||||||||
| 614 | } | ||||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||
| 616 | 259 | ▶ | sub say { | ||||||||||||||||||||||||||
|
Subroutine
say: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 617 | 259 | my ($self, $msg, $nl, $indent, $color, $back) = @_; | |||||||||||||||||||||||||||
| 618 | 259 | ▶ | $color ||= 90; | ||||||||||||||||||||||||||
|
Condition100%2/2
$color ||= 90
MC/DC100%1/1
$color ||= 90
$color
Truth table100%2/2
A
A= $color
| |||||||||||||||||||||||||||||
| 619 | 259 | ▶ | $back ||= 102; | ||||||||||||||||||||||||||
|
Condition100%2/2
$back ||= 102
MC/DC100%1/1
$back ||= 102
$back
Truth table100%2/2
A
A= $back
| |||||||||||||||||||||||||||||
| 620 | 259 | print "\e[$color;1;1m\e[$back;1m"; | |||||||||||||||||||||||||||
| 621 | 259 | print $msg; | |||||||||||||||||||||||||||
| 622 | 259 | ▶ | print "\n" if $nl; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 623 | 259 | ▶ | $self->set_cursor_horizontal(2) if $indent; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 624 | 259 | print "\e[0"; | |||||||||||||||||||||||||||
| 625 | 259 | 1; | |||||||||||||||||||||||||||
| 626 | } | ||||||||||||||||||||||||||||
| 627 | |||||||||||||||||||||||||||||
| 628 | 0 | ▶ | sub print_header { | ||||||||||||||||||||||||||
|
Subroutine
print_header: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 629 | 0 | my ($self, $message) = @_; | |||||||||||||||||||||||||||
| 630 | 0 | $self->set_cursor_vertical(0); | |||||||||||||||||||||||||||
| 631 | 0 | $self->set_cursor_horizontal(0); | |||||||||||||||||||||||||||
| 632 | 0 | print "\e[40;1m"; | |||||||||||||||||||||||||||
| 633 | 0 | print pack("A100", " "); | |||||||||||||||||||||||||||
| 634 | 0 | $self->set_cursor_horizontal(2); | |||||||||||||||||||||||||||
| 635 | 0 | $self->say($message, 0, 0, 31, 40); | |||||||||||||||||||||||||||
| 636 | } | ||||||||||||||||||||||||||||
| 637 | |||||||||||||||||||||||||||||
| 638 | 0 | ▶ | sub print_footer { | ||||||||||||||||||||||||||
|
Subroutine
print_footer: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 639 | 0 | my ($self, $message) = @_; | |||||||||||||||||||||||||||
| 640 | 0 | $self->set_cursor_vertical(36); | |||||||||||||||||||||||||||
| 641 | 0 | $self->set_cursor_horizontal(0); | |||||||||||||||||||||||||||
| 642 | 0 | print "\e[40;1m"; | |||||||||||||||||||||||||||
| 643 | 0 | print pack("A100", " "); | |||||||||||||||||||||||||||
| 644 | 0 | $self->set_cursor_horizontal(2); | |||||||||||||||||||||||||||
| 645 | 0 | $self->say($message, 0, 0, 31, 40); | |||||||||||||||||||||||||||
| 646 | 0 | $self->set_cursor_horizontal(length($message) + 2); | |||||||||||||||||||||||||||
| 647 | } | ||||||||||||||||||||||||||||
| 648 | |||||||||||||||||||||||||||||
| 649 | |||||||||||||||||||||||||||||
| 650 | 2 | 1; | |||||||||||||||||||||||||||
| 651 | |||||||||||||||||||||||||||||
| 652 | __END__ | ||||||||||||||||||||||||||||