diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2023-12-04 14:37:27 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2023-12-04 14:37:27 +0100 |
commit | c4086c04aa81379a045e5c7b1c0efe09ff38bb75 (patch) | |
tree | d547961de60b621d9532538011ded85c78a955c7 | |
parent | 420487be4001873a7168db25fc6a52f4fe6fabcd (diff) | |
download | colonial-twilight-c4086c04aa81379a045e5c7b1c0efe09ff38bb75.zip colonial-twilight-c4086c04aa81379a045e5c7b1c0efe09ff38bb75.tar.gz |
FLNBotRules : add is_rallied block to rally_9_priority
-rw-r--r-- | lib/colonial_twilight/fln_bot_rules.rb | 6 | ||||
-rw-r--r-- | spec/fln_bot_rules_spec.rb | 55 |
2 files changed, 52 insertions, 9 deletions
diff --git a/lib/colonial_twilight/fln_bot_rules.rb b/lib/colonial_twilight/fln_bot_rules.rb index 463ea8c..a5e5540 100644 --- a/lib/colonial_twilight/fln_bot_rules.rb +++ b/lib/colonial_twilight/fln_bot_rules.rb @@ -150,9 +150,9 @@ module ColonialTwilight r end - def rally_9_priority(spaces, resources) - f = _filter(spaces) { |s| s.support? && (resources.zero? || resources > s.terror) } - _filter(f) { |s| s.neutral? && (resources.zero? || resources > s.terror) } + def rally_9_priority(spaces, resources, &is_rallied) + f = _filter(spaces) { |s| s.support? && (resources.zero? || (resources - (is_rallied.call(s) ? 0 : 1)) > s.terror) } + _filter(f) { |s| s.neutral? && (resources.zero? || (resources - (is_rallied.call(s) ? 0 : 1)) > s.terror) } end # Extort diff --git a/spec/fln_bot_rules_spec.rb b/spec/fln_bot_rules_spec.rb index 2d46f0b..dc071cb 100644 --- a/spec/fln_bot_rules_spec.rb +++ b/spec/fln_bot_rules_spec.rb @@ -450,25 +450,68 @@ describe ColonialTwilight::FLNBotRules do expect(@rules.may_rally_9_in?(a)).to be true end - it 'rally_9_priority support' do + it 'rally_9_priority support rallied' do a = Sector.new(terror: 1, oppose: true) b = Sector.new(terror: 3, support: true) c = Sector.new(terror: 2, support: true) - expect(@rules.rally_9_priority([a, b, c], 3)[0]).to be c + l = @rules.rally_9_priority([a, b, c], 3) { true } + expect(l[0]).to be c end - it 'rally_9_priority neutral' do + it 'rally_9_priority support not rallied' do + a = Sector.new(terror: 1, oppose: true) + b = Sector.new(terror: 2, support: true) + c = Sector.new(terror: 1, support: true) + l = @rules.rally_9_priority([a, b, c], 3) { false } + expect(l[0]).to be c + end + + it 'rally_9_priority neutral rallied' do a = Sector.new(terror: 1, oppose: true) b = Sector.new(terror: 3, neutral: true) c = Sector.new(terror: 2, neutral: true) - expect(@rules.rally_9_priority([a, b, c], 3)[0]).to be c + l = @rules.rally_9_priority([a, b, c], 3) { true } + expect(l[0]).to be c + end + + it 'rally_9_priority neutral not rallied' do + a = Sector.new(terror: 1, oppose: true) + b = Sector.new(terror: 2, neutral: true) + c = Sector.new(terror: 1, neutral: true) + l = @rules.rally_9_priority([a, b, c], 3) { false } + expect(l[0]).to be c + end + + it 'rally_9_priority infinite resources rallied' do + a = Sector.new(terror: 1, oppose: true) + b = Sector.new(terror: 3, support: true) + c = Sector.new(terror: 2, support: true) + l = @rules.rally_9_priority([a, b, c], 0) { true } + expect(l.size).to eq 2 + end + + it 'rally_9_priority infinite resources not rallied' do + a = Sector.new(terror: 1, oppose: true) + b = Sector.new(terror: 3, support: true) + c = Sector.new(terror: 2, support: true) + l = @rules.rally_9_priority([a, b, c], 0) { false } + expect(l.size).to eq 2 + end + + it 'rally_9_priority infinite resources rallied' do + a = Sector.new(terror: 1, oppose: true) + b = Sector.new(terror: 3, support: true) + c = Sector.new(terror: 2, support: true) + l = @rules.rally_9_priority([a, b, c], 0) { true } + expect(l.size).to eq 2 end - it 'rally_9_priority infinite resources' do + it 'rally_9_priority infinite resources not rallied' do a = Sector.new(terror: 1, oppose: true) b = Sector.new(terror: 3, support: true) c = Sector.new(terror: 2, support: true) - expect(@rules.rally_9_priority([a, b, c], 0).size).to be 2 + l = @rules.rally_9_priority([a, b, c], 0) { false } + expect(l.size).to eq 2 end end |