diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2023-11-07 11:08:01 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2023-11-07 11:08:01 +0100 |
commit | 45df0be14323eaaa140f56b930f3d56d8239a902 (patch) | |
tree | 81d8d6886f8cab213bb0ae7fa188ceccb5f06e9b | |
parent | 166034e674396af49f1977ef5853b4f3d3b6e202 (diff) | |
download | colonial-twilight-45df0be14323eaaa140f56b930f3d56d8239a902.zip colonial-twilight-45df0be14323eaaa140f56b930f3d56d8239a902.tar.gz |
FLNBotRules : add #may_extort_0_in? and #extort_priority
-rw-r--r-- | lib/colonial_twilight/fln_bot_rules.rb | 14 | ||||
-rw-r--r-- | spec/fln_bot_rules_spec.rb | 58 |
2 files changed, 72 insertions, 0 deletions
diff --git a/lib/colonial_twilight/fln_bot_rules.rb b/lib/colonial_twilight/fln_bot_rules.rb index f5e02d9..77ee6d7 100644 --- a/lib/colonial_twilight/fln_bot_rules.rb +++ b/lib/colonial_twilight/fln_bot_rules.rb @@ -144,6 +144,20 @@ module ColonialTwilight _filter(f) { |s| s.gov_cubes.zero? } end + # Extort + + def may_extort_0_in?(space) + r = may_extort_in?(space) && space.fln_underground > (space.fln_bases.zero? ? 0 : 1) + dbg " may_extort_0_in : #{space.name}", r + r + end + + def extort_priority(spaces) + # 2+ guerrillas, 3+ if gov cubes and fln base -> Country -> anywhere if still at 0 + f = _filter(spaces) { |s| s.guerrillas > (s.gov_cubes.positive? && s.fln_bases.positive? ? 2 : 1) } + _filter(f, &:country?) + end + # 8.1.2 - Procedure Guidelines def _filter(spaces, &block) diff --git a/spec/fln_bot_rules_spec.rb b/spec/fln_bot_rules_spec.rb index 78148c8..9e200f4 100644 --- a/spec/fln_bot_rules_spec.rb +++ b/spec/fln_bot_rules_spec.rb @@ -413,6 +413,64 @@ describe ColonialTwilight::FLNBotRules do end end + describe 'Extort' do + it 'may_extort_0_in?' do + a = Sector.new + expect(@rules.may_extort_0_in?(a)).to be false + end + + it 'may_extort_0_in? pop' do + a = Sector.new(pop: 1) + expect(@rules.may_extort_0_in?(a)).to be false + end + + it 'may_extort_0_in? pop and underground' do + a = Sector.new(pop: 1, fln_underground: 1) + expect(@rules.may_extort_0_in?(a)).to be true + end + + it 'may_extort_0_in? pop and guerrillas but active' do + a = Sector.new(pop: 1, fln_active: 1) + expect(@rules.may_extort_0_in?(a)).to be false + end + + it 'may_extort_0_in? pop and underground but no control' do + a = Sector.new(pop: 1, fln_underground: 1, gov_cubes: 2) + expect(@rules.may_extort_0_in?(a)).to be false + end + + it 'may_extort_0_in? pop and underground but base' do + a = Sector.new(pop: 1, fln_underground: 1, fln_bases: 1) + expect(@rules.may_extort_0_in?(a)).to be false + end + + it 'may_extort_0_in? pop, base and enough underground' do + a = Sector.new(pop: 1, fln_underground: 2, fln_bases: 1, gov_cubes: 2) + expect(@rules.may_extort_0_in?(a)).to be true + end + + it 'extort_priority 2+' do + a = Sector.new(fln_underground: 1) + b = Sector.new(fln_underground: 2) + c = Sector.new(fln_underground: 1) + expect(@rules.extort_priority([a, b, c])[0]).to be b + end + + it 'extort_priority 3+ if fln bases and gov cubes' do + a = Sector.new(fln_underground: 2, fln_bases: 1, gov_cubes: 1) + b = Sector.new(fln_underground: 3, fln_bases: 1, gov_cubes: 1) + c = Sector.new(fln_underground: 2, fln_bases: 1, gov_cubes: 1) + expect(@rules.extort_priority([a, b, c])[0]).to be b + end + + it 'extort_priority country' do + a = Sector.new(fln_underground: 2, fln_bases: 1, gov_cubes: 1) + b = Sector.new(fln_underground: 3, fln_bases: 1, gov_cubes: 1, type: :country) + c = Sector.new(fln_underground: 3, fln_bases: 1, gov_cubes: 1) + expect(@rules.extort_priority([a, b, c])[0]).to be b + end + end + describe '8.1.2 Procedure Guidelines' do it 'available_fln_bases?' do @board.available_fln_bases = 0 |