summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/colonial_twilight/fln_bot_rules.rb6
-rw-r--r--spec/fln_bot_rules_spec.rb55
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