euchre-live

Euchre web-app for the socially distant family
git clone git://git.alexkarle.com/euchre-live.git
Log | Files | Refs | README | LICENSE

commit 7a5ea00ceb65d1874d44758cdce2050f85bc9e7e (patch)
parent d7e52958fa63ca679d0c4929b7717b31d7d96ed5
Author: Alex Karle <alex@karle.co>
Date:   Wed, 25 Mar 2020 00:01:30 -0400

Euchre::Game: Clean up score_round API

I think it's cleaner to return the index of the winning team along with
how many points they scored (as opposed to points for each team, one of
which is always zero).

Diffstat:
Mlib/Euchre/Game.pm | 13++++++-------
Mt/Game.t | 15++++++++-------
2 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/lib/Euchre/Game.pm b/lib/Euchre/Game.pm @@ -76,6 +76,7 @@ sub trick_winner { # Given # tricks per player, who won? What score? # Use X to indicate sat-out. $callers either 0 or 1 +# Returns idx of team, points to give sub score_round { my ($callers, @tricks) = @_; @@ -90,25 +91,23 @@ sub score_round { } } - my @points = (0, 0); - $DB::single = 1; if ($totals[$callers] == 5) { if ($loner) { # Hot diggity dog! - $points[$callers] = 4; + return $callers, 4; } else { # Respectable - $points[$callers] = 2; + return $callers, 2; } } elsif($totals[$callers] > $totals[$setters]) { # Made your point... - $points[$callers] = 1; + return $callers, 1; } else { # We've been Euched, Bill! - $points[$setters] = 2; + return $setters, 2; } - return \@points; + die 'assert'; } 1; diff --git a/t/Game.t b/t/Game.t @@ -48,16 +48,17 @@ sub test_trick_winner { sub test_score_round { my @tests = ( - [[0, 1,2,1,1], [0, 2], 'Euched!'], - [[1, 2,1,1,1], [2, 0], 'Euched again!'], - [[1, 2,3,0,0], [0,1], 'Made your point'], - [[1, 0,3,0,2], [0,2], 'Got em all!'], - [[0, 5,0,'X',0], [4,0], 'Loneeeer!'], - [[0, 3,1,'X',1], [1,0], 'Failed loner'], + [[0, 1,2,1,1], [1, 2], 'Euched!'], + [[1, 2,1,1,1], [0, 2], 'Euched again!'], + [[1, 2,3,0,0], [1,1], 'Made your point'], + [[1, 0,3,0,2], [1,2], 'Got em all!'], + [[0, 5,0,'X',0], [0,4], 'Loneeeer!'], + [[0, 3,1,'X',1], [0,1], 'Failed loner'], ); for my $t (@tests) { - is_deeply(score_round(@{$t->[0]}), $t->[1], $t->[2]); + my ($winners, $points) = score_round(@{$t->[0]}); + is_deeply([$winners, $points], $t->[1], $t->[2]); } }