diff options
-rw-r--r-- | lib/colonial_twilight/fln_bot_rules.rb | 39 | ||||
-rw-r--r-- | spec/fln_bot_rules_spec.rb | 133 |
2 files changed, 172 insertions, 0 deletions
diff --git a/lib/colonial_twilight/fln_bot_rules.rb b/lib/colonial_twilight/fln_bot_rules.rb index 1df9209..818f0bf 100644 --- a/lib/colonial_twilight/fln_bot_rules.rb +++ b/lib/colonial_twilight/fln_bot_rules.rb @@ -189,6 +189,35 @@ module ColonialTwilight r end + # Terror + + def may_terror_1_in?(space) + # to remove support, do not active last underground at bases + r = may_terror_in?(space) && space.support? && space.fln_underground > (space.fln_bases.positive? ? 1 : 0) + dbg " may_terror_1_in : #{space.name}", r + r + end + + def terror_1_priority(spaces) + # highest population + _max(spaces, :pop) + end + + def may_terror_2_in?(space, de_gaule: false) + # neutral and no terror and pacifiable, do not active last underground at bases + r = may_terror_in?(space) && space.neutral? && !space.terror? && _pacifiable(space, de_gaule) && + space.fln_underground > (space.fln_bases.positive? ? 1 : 0) + dbg " may_terror_2_in : #{space.name}", r + r + end + + def _pacifiable(space, de_gaule) + # in a city or sector with gov base OR + # if Recall de Gaulle in a sector with troops and police and gov control + (!space.country? && space.gov_bases.positive?) || + (de_gaule && space.sector? && space.troops.positive? && space.police.positive? && space.gov_control?) + end + # 8.1.2 - Procedure Guidelines def _filter(spaces, &block) @@ -219,6 +248,16 @@ module ColonialTwilight space.guerrillas > 2 && (space.fln_bases < (space.country? ? space.max_bases : 1)) end + def placeable_guerrillas?(board = @board) + return true if board.available_fln_underground.positive? + + board.spaces.map(&method(:_removable_guerrillas)).inject(0, :+).positive? + end + + def placeable_guerrillas(board = @board) + board.available_fln_underground + board.spaces.map(&method(:_removable_guerrillas)).inject(0, :+) + end + def max_placable_guerrillas_in?(space) max_placable_guerrillas(space).clamp(0, space.fln_bases.positive? ? (space.pop + 1 - space.guerrillas) : 666) end diff --git a/spec/fln_bot_rules_spec.rb b/spec/fln_bot_rules_spec.rb index a5fc00d..25ded7c 100644 --- a/spec/fln_bot_rules_spec.rb +++ b/spec/fln_bot_rules_spec.rb @@ -1,9 +1,11 @@ # frozen_string_literal: true +require './lib/colonial_twilight/fln_rules' require './lib/colonial_twilight/fln_bot_rules' require './spec/mock_board' class FLNRulesImpl + include ColonialTwilight::FLNRules include ColonialTwilight::FLNBotRules attr_reader :board attr_writer :debug, :limited_op_only, :first_eligible, :will_be_next_first_eligible @@ -547,7 +549,138 @@ describe ColonialTwilight::FLNBotRules do end end + describe 'Terror' do + it 'may_terror_1_in?' do + a = Sector.new(pop: 1, fln_underground: 1, support: true) + expect(@rules.may_terror_1_in?(a)).to be true + end + + it 'may_terror_1_in? no pop' do + a = Sector.new(fln_underground: 1, support: true) + expect(@rules.may_terror_1_in?(a)).to be false + end + + it 'may_terror_1_in? no support' do + a = Sector.new(pop: 1, fln_underground: 1) + expect(@rules.may_terror_1_in?(a)).to be false + end + + it 'may_terror_1_in? no underground' do + a = Sector.new(pop: 1, support: true) + expect(@rules.may_terror_1_in?(a)).to be false + end + + it 'may_terror_1_in? base and not enough underground' do + a = Sector.new(pop: 1, fln_bases: 1, fln_underground: 1, support: true) + expect(@rules.may_terror_1_in?(a)).to be false + end + + it 'may_terror_1_in? base and enough underground' do + a = Sector.new(pop: 1, fln_bases: 1, fln_underground: 2, support: true) + expect(@rules.may_terror_1_in?(a)).to be true + end + + it 'terror_1_priority most pop' do + a = Sector.new(pop: 1) + b = Sector.new(pop: 2) + expect(@rules.terror_1_priority([a, b])[0]).to be b + end + + it 'may_terro_2_in?' do + a = Sector.new(pop: 1, fln_underground: 1, neutral: true, gov_bases: 1) + expect(@rules.may_terror_2_in?(a)).to be true + end + + it 'may_terro_2_in? default' do + a = Sector.new(pop: 1, fln_underground: 1) + expect(@rules.may_terror_2_in?(a)).to be false + end + + it 'may_terro_2_in? is neutral' do + a = Sector.new(pop: 1, fln_underground: 1, neutral: true) + expect(@rules.may_terror_2_in?(a)).to be false + end + + it 'may_terro_2_in? gov base' do + a = Sector.new(pop: 1, fln_underground: 1, gov_bases: 1) + expect(@rules.may_terror_2_in?(a)).to be false + end + + it 'may_terro_2_in? neutral and gov base but terror' do + a = Sector.new(pop: 1, fln_underground: 1, neutral: true, gov_bases: 1, terror: 1) + expect(@rules.may_terror_2_in?(a)).to be false + end + + it '_pacifiable no gov base' do + a = Sector.new + expect(@rules._pacifiable(a, false)).to be false + end + + it '_pacifiable not country' do + a = Sector.new(name: 'country', gov_bases: 1) + expect(@rules._pacifiable(a, false)).to be false + end + + it '_pacifiable not country and gov base' do + a = Sector.new(gov_bases: 1) + expect(@rules._pacifiable(a, false)).to be true + end + + it '_pacifiable de Gaule country' do + a = Sector.new(name: 'country', troops: 1, police: 1) + expect(@rules._pacifiable(a, true)).to be false + end + + it '_pacifiable de Gaule sector and troops and police and gov control' do + a = Sector.new(troops: 1, french_police: 1) + expect(@rules._pacifiable(a, true)).to be true + end + + it '_pacifiable de Gaule no troops' do + a = Sector.new(french_police: 1) + expect(@rules._pacifiable(a, true)).to be false + end + + it '_pacifiable de Gaule no police' do + a = Sector.new(troops: 1) + expect(@rules._pacifiable(a, true)).to be false + end + + it '_pacifiable de Gaule no control' do + a = Sector.new(troops: 1, french_police: 1, fln_underground: 2) + expect(@rules._pacifiable(a, true)).to be false + end + end + describe '8.1.2 Procedure Guidelines' do + it 'placeable_guerrillas?' do + expect(@rules.placeable_guerrillas?).to be false + end + + it 'placeable_guerrillas? available' do + @board.available_fln_underground = 1 + expect(@rules.placeable_guerrillas?).to be true + end + + it 'placeable_guerrillas? active on map' do + @board.spaces << Sector.new(name: 'a', fln_active: 1) + expect(@rules.placeable_guerrillas?).to be true + end + + it 'placeable_guerrillas' do + expect(@rules.placeable_guerrillas).to eq 0 + end + + it 'placeable_guerrillas available' do + @board.available_fln_underground = 1 + expect(@rules.placeable_guerrillas).to eq 1 + end + + it 'placeable_guerrillas active on map' do + @board.spaces << Sector.new(name: 'a', fln_active: 1) + expect(@rules.placeable_guerrillas).to eq 1 + end + it 'available_fln_bases?' do @board.available_fln_bases = 0 expect(@rules.available_fln_bases?).to be false |