From 073dca3a5d42204952eeeb0fcbefa753466efc2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Thu, 9 Nov 2023 15:33:11 +0100 Subject: FLNBotRules : support Subvert --- lib/colonial_twilight/fln_bot_rules.rb | 21 +++++++++++++++++++++ spec/fln_bot_rules_spec.rb | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/lib/colonial_twilight/fln_bot_rules.rb b/lib/colonial_twilight/fln_bot_rules.rb index 7093740..8173d10 100644 --- a/lib/colonial_twilight/fln_bot_rules.rb +++ b/lib/colonial_twilight/fln_bot_rules.rb @@ -168,6 +168,27 @@ module ColonialTwilight _filter(f, &:country?) end + # Subvert + + def may_subvert_1_in?(space, num) + # to remove last cubes + r = may_subvert_in?(space) && (space.french_cubes.zero? && space.algerian_cubes <= num) + dbg " may_subvert_1_in : #{space.name}", r + r + end + + def subvert_1_priority(spaces) + # Police -> Troop + _max(spaces, :algerian_police) + end + + def may_subvert_2_in?(space) + # to replace 1 Algerian Police + r = may_subvert_in?(space) && space.algerian_police.positive? + dbg " may_subvert_2_in : #{space.name}", r + r + 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 1e2fc27..328b316 100644 --- a/spec/fln_bot_rules_spec.rb +++ b/spec/fln_bot_rules_spec.rb @@ -513,6 +513,40 @@ describe ColonialTwilight::FLNBotRules do end end + describe 'Subvert' do + it 'may_subvert_1_in?' do + a = Sector.new + expect(@rules.may_subvert_1_in?(a, 2)).to be false + end + + it 'may_subvert_1_in?' do + a = Sector.new(fln_underground: 1, algerian_police: 1) + expect(@rules.may_subvert_1_in?(a, 2)).to be true + end + + it 'may_subvert_1_in?' do + a = Sector.new(fln_underground: 1, algerian_police: 3) + expect(@rules.may_subvert_1_in?(a, 2)).to be false + end + + it 'subvert_1_priority algerian police' do + a = Sector.new(fln_underground: 1, algerian_police: 1) + b = Sector.new(fln_underground: 1, algerian_police: 3) + c = Sector.new(fln_underground: 1, algerian_police: 2) + expect(@rules.subvert_1_priority([a, b, c])[0]).to be b + end + + it 'may_subvert_2_in?' do + a = Sector.new(fln_underground: 1) + expect(@rules.may_subvert_2_in?(a)).to be false + end + + it 'may_subvert_2_in?' do + a = Sector.new(fln_underground: 1, algerian_police: 1) + expect(@rules.may_subvert_2_in?(a)).to be true + end + end + describe '8.1.2 Procedure Guidelines' do it 'available_fln_bases?' do @board.available_fln_bases = 0 -- cgit v1.1-2-g2b99