summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2023-10-27 14:09:33 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2023-10-27 14:09:33 +0200
commit7311f07e16fc73c06d2ac601995c0955d83ac83c (patch)
tree1383b4abe24aa05fd6e1445876ecce9a39f508f6
parent14cc1f5de9ad44887a913b3638a9403c661f11a7 (diff)
downloadcolonial-twilight-7311f07e16fc73c06d2ac601995c0955d83ac83c.zip
colonial-twilight-7311f07e16fc73c06d2ac601995c0955d83ac83c.tar.gz
FLNBotRules spec : simplify ({ ... }) into ( ... )
-rw-r--r--lib/colonial_twilight/fln_bot_rules.rb2
-rw-r--r--spec/fln_bot_rules_spec.rb190
2 files changed, 96 insertions, 96 deletions
diff --git a/lib/colonial_twilight/fln_bot_rules.rb b/lib/colonial_twilight/fln_bot_rules.rb
index eb06af6..625d31e 100644
--- a/lib/colonial_twilight/fln_bot_rules.rb
+++ b/lib/colonial_twilight/fln_bot_rules.rb
@@ -180,7 +180,7 @@ module ColonialTwilight
s = spaces.sample
n -= h[s] = (g = _removable_guerrillas(s)) >= n ? n : g
end
- h
+ h.reject { |_k, v| v.zero? }
end
# 1) place: outofplay -> available | bases -> guerrillas if choice
diff --git a/spec/fln_bot_rules_spec.rb b/spec/fln_bot_rules_spec.rb
index c21d339..fed7b24 100644
--- a/spec/fln_bot_rules_spec.rb
+++ b/spec/fln_bot_rules_spec.rb
@@ -74,22 +74,22 @@ describe ColonialTwilight::FLNBotRules do
describe 'Terror' do
it 'terror1? 1 pop 2 underground' do
- @rules.set({ pop: 1, fln_bases: 1, fln_underground: 2 })
+ @rules.set(pop: 1, fln_bases: 1, fln_underground: 2)
expect(@rules.terror1?).to be true
end
it 'terror1? 1 pop 1 underground' do
- @rules.set({ pop: 1, fln_bases: 1, fln_underground: 1 })
+ @rules.set(pop: 1, fln_bases: 1, fln_underground: 1)
expect(@rules.terror1?).to be false
end
it 'terror1? 0 pop 1 underground' do
- @rules.set({ pop: 0, fln_bases: 1, fln_underground: 1 })
+ @rules.set(pop: 0, fln_bases: 1, fln_underground: 1)
expect(@rules.terror1?).to be true
end
it 'terror1? 0 pop 0 underground' do
- @rules.set({ pop: 0, fln_bases: 1, fln_underground: 0 })
+ @rules.set(pop: 0, fln_bases: 1, fln_underground: 0)
expect(@rules.terror1?).to be false
end
@@ -115,68 +115,68 @@ describe ColonialTwilight::FLNBotRules do
end
it 'rally1? may rally_1' do
- @rules.set({ fln_active: 1, fln_underground: 2 })
+ @rules.set(fln_active: 1, fln_underground: 2)
expect(@rules.rally1?).to be true
end
it 'rally1? may rally_2' do
- @rules.set({ fln_active: 2, fln_underground: 2 })
+ @rules.set(fln_active: 2, fln_underground: 2)
expect(@rules.rally1?).to be true
end
it 'rally1? may rally_1 but no bases' do
- @rules.set({ fln_active: 1, fln_underground: 2 })
+ @rules.set(fln_active: 1, fln_underground: 2)
@board.available_fln_bases = 0
expect(@rules.rally1?).to be false
end
it 'rally1? may rally_2 but no bases' do
- @rules.set({ fln_active: 2, fln_underground: 2 })
+ @rules.set(fln_active: 2, fln_underground: 2)
@board.available_fln_bases = 0
expect(@rules.rally1?).to be false
end
it 'rally2? enough fln at bases' do
- @rules.set({ fln_bases: 2, fln_underground: 3 })
+ @rules.set(fln_bases: 2, fln_underground: 3)
expect(@rules.rally2?).to be false
end
it 'rally2? false' do
- @rules.set({ fln_bases: 2, fln_underground: 2 })
+ @rules.set(fln_bases: 2, fln_underground: 2)
expect(@rules.rally2?).to be true
end
end
describe 'Rally Specific' do
it 'may_rally_1_in? not enough fln guerrillas' do
- a = Sector.new({ fln_active: 1, fln_underground: 1 })
+ a = Sector.new(fln_active: 1, fln_underground: 1)
expect(@rules.may_rally_1_in?(a)).to be false
end
it 'may_rally_1_in? 3+ guerrillas' do
- a = Sector.new({ fln_active: 1, fln_underground: 2 })
+ a = Sector.new(fln_active: 1, fln_underground: 2)
expect(@rules.may_rally_1_in?(a)).to be true
end
it 'may_rally_1_in? 3+ guerrillas no limited op' do
- a = Sector.new({ fln_active: 1, fln_underground: 2 })
+ a = Sector.new(fln_active: 1, fln_underground: 2)
@rules.limited_op_only = false
expect(@rules.may_rally_1_in?(a)).to be true
end
it 'may_rally_1_in? 3+ guerrillas but gov cubes' do
- a = Sector.new({ fln_active: 1, fln_underground: 2, gov_cubes: 1 })
+ a = Sector.new(fln_active: 1, fln_underground: 2, gov_cubes: 1)
@rules.limited_op_only = false
expect(@rules.may_rally_1_in?(a)).to be false
end
it 'may_rally_2_in? not enough fln guerrillas' do
- a = Sector.new({ fln_active: 2, fln_underground: 1 })
+ a = Sector.new(fln_active: 2, fln_underground: 1)
expect(@rules.may_rally_2_in?(a)).to be false
end
it 'may_rally_2_in? 4+ guerrillas' do
- a = Sector.new({ fln_active: 2, fln_underground: 2 })
+ a = Sector.new(fln_active: 2, fln_underground: 2)
expect(@rules.may_rally_2_in?(a)).to be true
end
@@ -186,131 +186,131 @@ describe ColonialTwilight::FLNBotRules do
end
it 'may_rally_3_in? base and pop 0' do
- a = Sector.new({ fln_bases: 1 })
+ a = Sector.new(fln_bases: 1)
expect(@rules.may_rally_3_in?(a)).to be true
end
it 'may_rally_3_in? base and pop 0 but has fln underground' do
- a = Sector.new({ fln_bases: 1, fln_underground: 1 })
+ a = Sector.new(fln_bases: 1, fln_underground: 1)
expect(@rules.may_rally_3_in?(a)).to be false
end
it 'may_rally_3_in? base and country but not independent' do
- a = Sector.new({ fln_bases: 1, pop: 1, name: 'country', independent: false })
+ a = Sector.new(fln_bases: 1, pop: 1, name: 'country', independent: false)
expect(@rules.may_rally_3_in?(a)).to be false
end
it 'may_rally_3_in? base and country' do
- a = Sector.new({ fln_bases: 1, pop: 1, name: 'country', independent: true })
+ a = Sector.new(fln_bases: 1, pop: 1, name: 'country', independent: true)
expect(@rules.may_rally_3_in?(a)).to be true
end
it 'may_rally_3_in? base and country but has fln underground' do
- a = Sector.new({ fln_bases: 1, pop: 1, name: 'country', independent: true, fln_underground: 1 })
+ a = Sector.new(fln_bases: 1, pop: 1, name: 'country', independent: true, fln_underground: 1)
expect(@rules.may_rally_3_in?(a)).to be false
end
it 'may_rally_3_in? base and pop' do
- a = Sector.new({ fln_bases: 1, pop: 1, fln_underground: 1 })
+ a = Sector.new(fln_bases: 1, pop: 1, fln_underground: 1)
expect(@rules.may_rally_3_in?(a)).to be true
end
it 'may_rally_3_in? base and pop but too many fln underground ' do
- a = Sector.new({ fln_bases: 1, pop: 1, fln_underground: 2 })
+ a = Sector.new(fln_bases: 1, pop: 1, fln_underground: 2)
expect(@rules.may_rally_3_in?(a)).to be false
end
it 'rally_3_priority Algeria' do
a = Sector.new
- b = Sector.new({ name: 'country' })
+ b = Sector.new(name: 'country')
expect(@rules.rally_3_priority([a, b])[0]).to be a
end
it 'rally_3_priority with GOV cubes' do
a = Sector.new
- b = Sector.new({ gov_cubes: 1 })
+ b = Sector.new(gov_cubes: 1)
expect(@rules.rally_3_priority([a, b])[0]).to be b
end
it 'rally_3_priority pop 1+' do
- a = Sector.new({ pop: 1 })
- b = Sector.new({ gov_cubes: 1, pop: 1 })
- c = Sector.new({ gov_cubes: 1 })
+ a = Sector.new(pop: 1)
+ b = Sector.new(gov_cubes: 1, pop: 1)
+ c = Sector.new(gov_cubes: 1)
expect(@rules.rally_3_priority([a, b, c])[0]).to be b
end
it 'rally_3_priority least fln_underground' do
- a = Sector.new({ pop: 1 })
- b = Sector.new({ gov_cubes: 1, pop: 1 })
- c = Sector.new({ gov_cubes: 1, pop: 1, fln_underground: 1 })
+ a = Sector.new(pop: 1)
+ b = Sector.new(gov_cubes: 1, pop: 1)
+ c = Sector.new(gov_cubes: 1, pop: 1, fln_underground: 1)
expect(@rules.rally_3_priority([a, b, c])[0]).to be b
end
it 'may_rally_5_in? city' do
- a = Sector.new({ name: 'city', support: true })
+ a = Sector.new(name: 'city', support: true)
expect(@rules.may_rally_5_in?(a)).to be false
end
it 'may_rally_5_in? fln underground' do
- a = Sector.new({ support: true, fln_underground: 1 })
+ a = Sector.new(support: true, fln_underground: 1)
expect(@rules.may_rally_5_in?(a)).to be false
end
it 'may_rally_5_in? no support' do
- a = Sector.new({ support: false })
+ a = Sector.new(support: false)
expect(@rules.may_rally_5_in?(a)).to be false
end
it 'may_rally_5_in? good' do
- a = Sector.new({ support: true })
+ a = Sector.new(support: true)
expect(@rules.may_rally_5_in?(a)).to be true
end
it 'rally_5_priority most pop' do
- a = Sector.new({ pop: 1 })
- b = Sector.new({ pop: 2 })
+ a = Sector.new(pop: 1)
+ b = Sector.new(pop: 2)
expect(@rules.rally_5_priority([a, b])[0]).to be b
end
it 'may_rally_6_in? pop 1' do
- a = Sector.new({ pop: 1 })
+ a = Sector.new(pop: 1)
expect(@rules.may_rally_6_in?(a, false)).to be false
end
it 'may_rally_6_in? pop 2+ but no base, no control after' do
- a = Sector.new({ pop: 2, gov_cubes: 1 })
+ a = Sector.new(pop: 2, gov_cubes: 1)
@board.available_fln_underground = 1
expect(@rules.may_rally_6_in?(a, false)).to be false
end
it 'may_rally_6_in? pop 2+ and base' do
- a = Sector.new({ pop: 2, gov_cubes: 6, fln_bases: 1 })
+ a = Sector.new(pop: 2, gov_cubes: 6, fln_bases: 1)
expect(@rules.may_rally_6_in?(a, false)).to be true
end
it 'may_rally_6_in? pop 2+ and control' do
- a = Sector.new({ pop: 2, gov_cubes: 1, fln_active: 1 })
+ a = Sector.new(pop: 2, gov_cubes: 1, fln_active: 1)
@board.available_fln_underground = 1
expect(@rules.may_rally_6_in?(a, false)).to be true
end
it 'rally_6_priority population' do
- a = Sector.new({ pop: 2 })
- b = Sector.new({ pop: 1 })
+ a = Sector.new(pop: 2)
+ b = Sector.new(pop: 1)
expect(@rules.rally_6_priority([a, b])[0]).to be a
end
it 'rally_6_priority min terror' do
- a = Sector.new({ pop: 1, terror: 2 })
- b = Sector.new({ pop: 2, terror: 1 })
- c = Sector.new({ pop: 2, terror: 2 })
+ a = Sector.new(pop: 1, terror: 2)
+ b = Sector.new(pop: 2, terror: 1)
+ c = Sector.new(pop: 2, terror: 2)
expect(@rules.rally_6_priority([a, b, c])[0]).to be b
end
it 'rally_6_priority support' do
- a = Sector.new({ pop: 2, terror: 1, support: false })
- b = Sector.new({ pop: 2, terror: 1, support: true })
- c = Sector.new({ pop: 2, terror: 2, support: true })
+ a = Sector.new(pop: 2, terror: 1, support: false)
+ b = Sector.new(pop: 2, terror: 1, support: true)
+ c = Sector.new(pop: 2, terror: 2, support: true)
expect(@rules.rally_6_priority([a, b, c])[0]).to be b
end
@@ -320,48 +320,48 @@ describe ColonialTwilight::FLNBotRules do
end
it 'may_rally_7_in? not in city at support' do
- a = Sector.new({ name: 'city', support: true })
+ a = Sector.new(name: 'city', support: true)
expect(@rules.may_rally_7_in?(a)).to be false
end
it 'may_rally_7_in? not in not independent country' do
- a = Sector.new({ name: 'country', independent: false })
+ a = Sector.new(name: 'country', independent: false)
expect(@rules.may_rally_7_in?(a)).to be false
end
it 'rally_7_priority population' do
- a = Sector.new({ pop: 2 })
- b = Sector.new({ pop: 1 })
- c = Sector.new({ pop: 1 })
+ a = Sector.new(pop: 2)
+ b = Sector.new(pop: 1)
+ c = Sector.new(pop: 1)
expect(@rules.rally_7_priority([a, b, c])[0]).to be a
end
it 'rally_7_priority gain FLN control' do
- a = Sector.new({ gov_cubes: 2 })
- b = Sector.new({ gov_cubes: 1, fln_active: 1 })
- c = Sector.new({ gov_cubes: 1 })
+ a = Sector.new(gov_cubes: 2)
+ b = Sector.new(gov_cubes: 1, fln_active: 1)
+ c = Sector.new(gov_cubes: 1)
@board.available_fln_underground = 1
expect(@rules.rally_7_priority([a, b, c])[0]).to be b
end
it 'rally_7_priority remove GOV control' do
- a = Sector.new({ gov_cubes: 3 })
- b = Sector.new({ gov_cubes: 1 })
- c = Sector.new({ gov_cubes: 2 })
+ a = Sector.new(gov_cubes: 3)
+ b = Sector.new(gov_cubes: 1)
+ c = Sector.new(gov_cubes: 2)
@board.available_fln_underground = 1
expect(@rules.rally_7_priority([a, b, c])[0]).to be b
end
it 'rally_7_priority city?' do
- a = Sector.new({ name: 'city' })
+ a = Sector.new(name: 'city')
b = Sector.new
expect(@rules.rally_7_priority([a, b])[0]).to be a
end
it 'rally_7_priority least terror' do
a = Sector.new
- b = Sector.new({ name: 'city', terror: 1 })
- c = Sector.new({ name: 'city', terror: 2 })
+ b = Sector.new(name: 'city', terror: 1)
+ c = Sector.new(name: 'city', terror: 2)
expect(@rules.rally_7_priority([a, b, c])[0]).to be b
end
@@ -371,32 +371,32 @@ describe ColonialTwilight::FLNBotRules do
end
it 'may_rally_8_in? fln guerrillas but base' do
- a = Sector.new({ fln_active: 1, fln_bases: 1 })
+ a = Sector.new(fln_active: 1, fln_bases: 1)
expect(@rules.may_rally_8_in?(a)).to be false
end
it 'may_rally_8_in? fln guerrillas and 0 base' do
- a = Sector.new({ fln_underground: 1 })
+ a = Sector.new(fln_underground: 1)
expect(@rules.may_rally_8_in?(a)).to be true
end
it 'rally_8_priority Algeria' do
a = Sector.new
- b = Sector.new({ name: 'country' })
+ b = Sector.new(name: 'country')
expect(@rules.rally_8_priority([a, b])[0]).to be a
end
it 'rally_8_priority most guerrillas' do
a = Sector.new
- b = Sector.new({ fln_active: 2, fln_underground: 1 })
- c = Sector.new({ fln_active: 1, fln_underground: 1 })
+ b = Sector.new(fln_active: 2, fln_underground: 1)
+ c = Sector.new(fln_active: 1, fln_underground: 1)
expect(@rules.rally_8_priority([a, b, c])[0]).to be b
end
it 'rally_8_priority no cubes' do
a = Sector.new
- b = Sector.new({ fln_active: 1, fln_underground: 1 })
- c = Sector.new({ fln_active: 1, fln_underground: 1, gov_cubes: 1 })
+ b = Sector.new(fln_active: 1, fln_underground: 1)
+ c = Sector.new(fln_active: 1, fln_underground: 1, gov_cubes: 1)
expect(@rules.rally_8_priority([a, b, c])[0]).to be b
end
end
@@ -413,49 +413,49 @@ describe ColonialTwilight::FLNBotRules do
end
it 'may_add_base_in?' do
- a = Sector.new({ fln_active: 3 })
+ a = Sector.new(fln_active: 3)
expect(@rules.may_add_base_in?(a)).to be true
end
it 'may_add_base_in? not enough fln' do
- a = Sector.new({ fln_active: 2 })
+ a = Sector.new(fln_active: 2)
expect(@rules.may_add_base_in?(a)).to be false
end
it 'may_add_base_in? but has base' do
- a = Sector.new({ fln_bases: 1, fln_active: 3 })
+ a = Sector.new(fln_bases: 1, fln_active: 3)
expect(@rules.may_add_base_in?(a)).to be false
end
it 'may_add_base_in? country ' do
- a = Sector.new({ name: 'country', fln_bases: 2, fln_active: 3 })
+ a = Sector.new(name: 'country', fln_bases: 2, fln_active: 3)
expect(@rules.may_add_base_in?(a)).to be true
end
it 'may_add_base_in? country but limit' do
- a = Sector.new({ name: 'country', fln_bases: 3, fln_active: 3 })
+ a = Sector.new(name: 'country', fln_bases: 3, fln_active: 3)
expect(@rules.may_add_base_in?(a)).to be false
end
it 'max_placable_guerrillas_in? 1' do
- a = Sector.new({ pop: 2 })
+ a = Sector.new(pop: 2)
expect(@rules.max_placable_guerrillas_in?(a)).to eq(1)
end
it 'max_placable_guerrillas_in? pop + base' do
- a = Sector.new({ pop: 2, fln_bases: 1 })
+ a = Sector.new(pop: 2, fln_bases: 1)
expect(@rules.max_placable_guerrillas_in?(a)).to eq(3)
end
it 'max_placable_guerrillas_in? max pop + 1' do
- a = Sector.new({ pop: 2, fln_bases: 1, fln_active: 1, fln_underground: 1 })
+ a = Sector.new(pop: 2, fln_bases: 1, fln_active: 1, fln_underground: 1)
expect(@rules.max_placable_guerrillas_in?(a)).to eq(1)
end
it 'place_guerrillas_in' do
- a = Sector.new({ pop: 2, fln_bases: 1 })
+ a = Sector.new(pop: 2, fln_bases: 1)
@board.available_fln_underground = 1
- @board.spaces << Sector.new({ name: 'a', fln_bases: 1, fln_active: 2, fln_underground: 1 })
+ @board.spaces << Sector.new(name: 'a', fln_bases: 1, fln_active: 2, fln_underground: 1)
h = @rules.place_guerrillas_in(a)
expect(@rules.max_placable_guerrillas_in?(a)).to eq(3)
expect(h[:available]).to eq(1)
@@ -463,31 +463,31 @@ describe ColonialTwilight::FLNBotRules do
end
it '_removable_guerrillas active' do
- a = Sector.new({ fln_active: 2, fln_underground: 3 })
+ a = Sector.new(fln_active: 2, fln_underground: 3)
expect(@rules._removable_guerrillas(a)).to eq(2)
end
it '_removable_guerrillas leave 2 at support' do
- a = Sector.new({ support: true, fln_active: 3 })
+ a = Sector.new(support: true, fln_active: 3)
expect(@rules._removable_guerrillas(a)).to eq(1)
end
it '_removable guerrillas leave 2 at bases' do
- a = Sector.new({ fln_bases: 1, fln_active: 3, fln_underground: 1 })
+ a = Sector.new(fln_bases: 1, fln_active: 3, fln_underground: 1)
expect(@rules._removable_guerrillas(a)).to eq(2)
end
it 'place_guerrillas support' do
- a = Sector.new({ support: false })
- b = Sector.new({ support: true })
- c = Sector.new({ support: false })
+ a = Sector.new(support: false)
+ b = Sector.new(support: true)
+ c = Sector.new(support: false)
expect(@rules.place_guerrillas([a, b, c])[0]).to be b
end
it 'place_guerrillas support and fln_active' do
- a = Sector.new({ support: false })
- b = Sector.new({ support: true, fln_active: 1 })
- c = Sector.new({ support: true })
+ a = Sector.new(support: false)
+ b = Sector.new(support: true, fln_active: 1)
+ c = Sector.new(support: true)
expect(@rules.place_guerrillas([a, b, c])[0]).to be b
end
@@ -498,15 +498,15 @@ describe ColonialTwilight::FLNBotRules do
end
it '_remove_guerrillas_priority most guerrillas' do
- a = Sector.new({ fln_active: 2, fln_underground: 1 })
- b = Sector.new({ fln_active: 2, fln_underground: 2 })
- c = Sector.new({ fln_active: 1, fln_underground: 2 })
- d = Sector.new({ fln_active: 3, fln_underground: 2 })
+ a = Sector.new(fln_active: 2, fln_underground: 1)
+ b = Sector.new(fln_active: 2, fln_underground: 2)
+ c = Sector.new(fln_active: 1, fln_underground: 2)
+ d = Sector.new(fln_active: 3, fln_underground: 2)
expect(@rules._remove_guerrillas_priority([a, b, c, d], { d => true })[0]).to be b
end
it 'remove_from all' do
- a = Sector.new({ fln_active: 2, fln_underground: 1, fln_bases: 1 })
+ a = Sector.new(fln_active: 2, fln_underground: 1, fln_bases: 1)
h = @rules.remove_from(a, 6)
expect(h[:fln_underground]).to be 1
expect(h[:fln_active]).to be 2
@@ -514,7 +514,7 @@ describe ColonialTwilight::FLNBotRules do
end
it 'remove_from a few' do
- a = Sector.new({ fln_active: 1, fln_underground: 1 })
+ a = Sector.new(fln_active: 1, fln_underground: 1)
h = @rules.remove_from(a, 2)
expect(h[:fln_underground]).to be 1
expect(h[:fln_active]).to be 1