| 1 | package BalanceOfPower::Role::CrisisManager; | ||||||||||||||||||||||
| 2 | 11 | $BalanceOfPower::Role::CrisisManager::VERSION = '0.200000'; | |||||||||||||||||||||
| 3 | 11 | ▶ | use strict; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 4 | 11 | ▶ | use Moo::Role; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 5 | 11 | ▶ | use Term::ANSIColor; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 6 | |||||||||||||||||||||||
| 7 | 11 | ▶ | use BalanceOfPower::Constants ':all'; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 8 | 11 | ▶ | use BalanceOfPower::Utils qw(as_title); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 9 | |||||||||||||||||||||||
| 10 | 11 | requires 'get_all_crises'; | |||||||||||||||||||||
| 11 | 11 | requires 'get_hates'; | |||||||||||||||||||||
| 12 | 11 | requires 'crisis_exists'; | |||||||||||||||||||||
| 13 | 11 | requires 'war_exists'; | |||||||||||||||||||||
| 14 | 11 | requires 'broadcast_event'; | |||||||||||||||||||||
| 15 | 11 | requires 'add_crisis'; | |||||||||||||||||||||
| 16 | |||||||||||||||||||||||
| 17 | sub crisis_generator | ||||||||||||||||||||||
| 18 | { | ||||||||||||||||||||||
| 19 | 40 | ▶ | my $self = shift; | ||||||||||||||||||||
|
Subroutine
crisis_generator: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||
| 20 | 40 | my @crises = $self->get_all_crises(); | |||||||||||||||||||||
| 21 | 40 | my @hates = (); | |||||||||||||||||||||
| 22 | 40 | foreach my $h ($self->get_hates()) | |||||||||||||||||||||
| 23 | { | ||||||||||||||||||||||
| 24 | 84 | ▶ | push @hates, $h | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 25 | if(! $self->crisis_exists($h->node1, $h->node2)) | ||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||
| 27 | 40 | my $crises_to_use = \@crises; | |||||||||||||||||||||
| 28 | 40 | my $hates_to_use = \@hates; | |||||||||||||||||||||
| 29 | 40 | ▶ | for(my $i = 0; $i < CRISIS_GENERATION_TRIES; $i++) | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 30 | { | ||||||||||||||||||||||
| 31 | 200 | ($hates_to_use, $crises_to_use) = $self->crisis_generator_round($hates_to_use, $crises_to_use); | |||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||
| 33 | |||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||
| 35 | |||||||||||||||||||||||
| 36 | sub crisis_generator_round | ||||||||||||||||||||||
| 37 | { | ||||||||||||||||||||||
| 38 | 200 | ▶ | my $self = shift; | ||||||||||||||||||||
|
Subroutine
crisis_generator_round: called CC=17 SCAR=28.4
Pod
undocumented
| |||||||||||||||||||||||
| 39 | 200 | ▶ | my $hates_to_use = shift || [] ; | ||||||||||||||||||||
|
Condition50%1/2
shift() || []
MC/DC0%0/1
shift() || []
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||
| 40 | 200 | ▶ | my $crises_to_use = shift || []; | ||||||||||||||||||||
|
Condition50%1/2
shift() || []
MC/DC0%0/1
shift() || []
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||
| 41 | 200 | my @hates = $self->shuffle("Crisis generation: choosing hate", @{ $hates_to_use }); | |||||||||||||||||||||
| 42 | 200 | my @crises = $self->shuffle("Crisis generation: choosing crisis", @{ $crises_to_use}); | |||||||||||||||||||||
| 43 | 200 | my @original_hates = @hates; | |||||||||||||||||||||
| 44 | 200 | my @original_crises = @crises; | |||||||||||||||||||||
| 45 | |||||||||||||||||||||||
| 46 | 200 | my $picked_hate = undef; | |||||||||||||||||||||
| 47 | 200 | my $picked_crisis = undef; | |||||||||||||||||||||
| 48 | 200 | ▶ | if(@hates) | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 49 | { | ||||||||||||||||||||||
| 50 | 75 | $picked_hate = shift @hates; | |||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||
| 52 | 200 | ▶ | if(@crises) | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 53 | { | ||||||||||||||||||||||
| 54 | 50 | $picked_crisis = shift @crises; | |||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||
| 56 | |||||||||||||||||||||||
| 57 | |||||||||||||||||||||||
| 58 | 200 | my $action = $self->random(0, CRISIS_GENERATOR_NOACTION_TOKENS + 3, "Crisis action choose"); | |||||||||||||||||||||
| 59 | 200 | ▶ | if($action == 0) #NEW CRISIS | ||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||
| 60 | { | ||||||||||||||||||||||
| 61 | 27 | ▶ | return (\@original_hates, \@original_crises) if ! $picked_hate; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 62 | 14 | ▶ | if(! $self->war_exists($picked_hate->node1, $picked_hate->node2)) | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 63 | { | ||||||||||||||||||||||
| 64 | 14 | $self->create_or_escalate_crisis($picked_hate->node1, $picked_hate->node2); | |||||||||||||||||||||
| 65 | 14 | return (\@hates, \@original_crises); | |||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||
| 68 | elsif($action == 1) #ESCALATE | ||||||||||||||||||||||
| 69 | { | ||||||||||||||||||||||
| 70 | 17 | ▶ | return (\@original_hates, \@original_crises) if ! $picked_crisis; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 71 | 5 | ▶ | if(! $self->war_exists($picked_crisis->node1, $picked_crisis->node2)) | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 72 | { | ||||||||||||||||||||||
| 73 | 5 | $self->create_or_escalate_crisis($picked_crisis->node1, $picked_crisis->node2); | |||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||
| 75 | 5 | return (\@original_hates, \@crises); | |||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||
| 77 | elsif($action == 2) #COOL DOWN | ||||||||||||||||||||||
| 78 | { | ||||||||||||||||||||||
| 79 | 18 | ▶ | return (\@original_hates, \@original_crises) if ! $picked_crisis; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 80 | 5 | ▶ | if(! $self->war_exists($picked_crisis->node1, $picked_crisis->node2)) | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 81 | { | ||||||||||||||||||||||
| 82 | 5 | $self->cool_down($picked_crisis->node1, $picked_crisis->node2); | |||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||
| 84 | 5 | return (\@original_hates, \@crises); | |||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||
| 86 | elsif($action == 3) #ELIMINATE | ||||||||||||||||||||||
| 87 | { | ||||||||||||||||||||||
| 88 | 21 | ▶ | return (\@original_hates, \@original_crises) if ! $picked_crisis; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 89 | 5 | ▶ | if(! $self->war_exists($picked_crisis->node1, $picked_crisis->node2)) | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 90 | { | ||||||||||||||||||||||
| 91 | 4 | $self->delete_crisis($picked_crisis->node1, $picked_crisis->node2); | |||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||
| 93 | 5 | return (\@original_hates, \@crises); | |||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||
| 95 | else | ||||||||||||||||||||||
| 96 | { | ||||||||||||||||||||||
| 97 | 117 | return (\@original_hates, \@original_crises); | |||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||
| 100 | sub create_or_escalate_crisis | ||||||||||||||||||||||
| 101 | { | ||||||||||||||||||||||
| 102 | 19 | ▶ | my $self = shift; | ||||||||||||||||||||
|
Subroutine
create_or_escalate_crisis: called CC=6 SCAR=18.0
Pod
undocumented
| |||||||||||||||||||||||
| 103 | 19 | ▶ | my $node1 = shift || ""; | ||||||||||||||||||||
|
Condition50%1/2
shift() || ''
MC/DC0%0/1
shift() || ''
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||
| 104 | 19 | ▶ | my $node2 = shift || ""; | ||||||||||||||||||||
|
Condition50%1/2
shift() || ''
MC/DC0%0/1
shift() || ''
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||
| 105 | 19 | ▶ | if(my $crisis = $self->crisis_exists($node1, $node2)) | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 106 | { | ||||||||||||||||||||||
| 107 | 5 | ▶ | if(! $crisis->is_max_crisis) | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 108 | { | ||||||||||||||||||||||
| 109 | 4 | $crisis->escalate_crisis(); | |||||||||||||||||||||
| 110 | 4 | my $event = "CRISIS BETWEEN $node1 AND $node2 ESCALATES"; | |||||||||||||||||||||
| 111 | 4 | ▶ | if($crisis->is_max_crisis) | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 112 | { | ||||||||||||||||||||||
| 113 | 1 | $event .= " TO MAX LEVEL"; | |||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||
| 115 | 4 | $self->broadcast_event($event, $node1, $node2); | |||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||
| 118 | else | ||||||||||||||||||||||
| 119 | { | ||||||||||||||||||||||
| 120 | 14 | $self->add_crisis($node1, $node2); | |||||||||||||||||||||
| 121 | 14 | $self->broadcast_event("CRISIS BETWEEN $node1 AND $node2 STARTED", $node1, $node2); | |||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||
| 124 | sub cool_down | ||||||||||||||||||||||
| 125 | { | ||||||||||||||||||||||
| 126 | 5 | ▶ | my $self = shift; | ||||||||||||||||||||
|
Subroutine
cool_down: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||
| 127 | 5 | my $node1 = shift; | |||||||||||||||||||||
| 128 | 5 | my $node2 = shift; | |||||||||||||||||||||
| 129 | 5 | ▶ | if(my $crisis = $self->crisis_exists($node1, $node2)) | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 130 | { | ||||||||||||||||||||||
| 131 | 5 | $crisis->cooldown_crisis(); | |||||||||||||||||||||
| 132 | 5 | ▶ | if(! $crisis->is_crisis()) | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 133 | { | ||||||||||||||||||||||
| 134 | 4 | my $event = "CRISIS BETWEEN $node1 AND $node2 ENDED"; | |||||||||||||||||||||
| 135 | 4 | $self->broadcast_event($event, $node1, $node2); | |||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||
| 137 | else | ||||||||||||||||||||||
| 138 | { | ||||||||||||||||||||||
| 139 | 1 | $self->broadcast_event("CRISIS BETWEEN $node1 AND $node2 COOLED DOWN", $node1, $node2); | |||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||
| 143 | |||||||||||||||||||||||
| 144 | sub print_all_crises | ||||||||||||||||||||||
| 145 | { | ||||||||||||||||||||||
| 146 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||
|
Subroutine
print_all_crises: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||||||||||||||
| 147 | 1 | my $n = shift; | |||||||||||||||||||||
| 148 | 1 | my $out; | |||||||||||||||||||||
| 149 | 1 | $out .= as_title("CRISES\n===\n"); | |||||||||||||||||||||
| 150 | 1 | foreach my $b ($self->get_all_crises()) | |||||||||||||||||||||
| 151 | { | ||||||||||||||||||||||
| 152 | 1 | ▶ | if($self->war_exists($b->node1, $b->node2)) | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 153 | { | ||||||||||||||||||||||
| 154 | 1 | $out .= color("red bold") . $b->print_crisis() . color("reset") . "\n"; | |||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||
| 156 | else | ||||||||||||||||||||||
| 157 | { | ||||||||||||||||||||||
| 158 | 0 | $out .= $b->print_crisis() . "\n"; | |||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||
| 161 | 1 | return $out; | |||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||
| 163 | |||||||||||||||||||||||
| 164 | 11 | 1; | |||||||||||||||||||||
| 165 | |||||||||||||||||||||||