File Coverage

lib/Catan/Event/Monopoly.pm
Criterion Covered Total %
statement 18 30 60.0
branch 0 6 0.0
condition 0 9 0.0
subroutine 6 8 75.0
pod 0 2 0.0
total 24 55 43.6


line stmt bran cond sub pod time code
1             package Catan::Event::Monopoly;
2             $Catan::Event::Monopoly::VERSION = '0.02';
3 2     2   10 use strict;
  2     1   4  
  2         57  
  1         923  
  1         2  
  1         23  
4 2     2   11 use warnings;
  2     1   5  
  2         55  
  1         5  
  1         2  
  1         26  
5 2     2   803 use Catan::Game::Trade;
  2     1   5  
  2         420  
  1         4  
  1         2  
  1         386  
6              
7 0     0 0   sub new { bless {}, shift }
8              
9             sub calculate
10             {
11 0     0 0   my ($self, $player_number, $code, $players, $bank) = @_;
12 0 0 0       die 'calculate requires a player number, resource code and players arrayref'
      0        
      0        
13             unless $player_number && $code && $players && ref $players eq 'ARRAY';
14              
15             # loop through all other players and trade away their resource to the player
16 0           my %resources_summary = ();
17 0           for my $losing_player (@$players)
18             {
19 0 0         next if $losing_player->number == $player_number;
20 0 0         if (my $amount = $losing_player->resources->{$code})
21             {
22 0           my $trade = Catan::Game::Trade->new($bank, $players, {
23             $player_number => { $code => $amount },
24             $losing_player->number => { $code => -$amount },
25             });
26 0           my $resources = $trade->execute;
27 0           for my $k (keys %$resources)
28             {
29 0           $resources_summary{$k}{$code} += $resources->{$k}{$code};
30             }
31             }
32             }
33 0           return \%resources_summary;
34             }
35             1;
36              
37             __END__