From 964cba1f5640113b55a386239b9b8c698c9fafdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Thu, 9 Nov 2023 15:34:43 +0100 Subject: FLNBotRules : add #pick_guerrillas_from --- lib/colonial_twilight/fln_bot_rules.rb | 6 ++++++ spec/fln_bot_rules_spec.rb | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/lib/colonial_twilight/fln_bot_rules.rb b/lib/colonial_twilight/fln_bot_rules.rb index f82cb39..4294136 100644 --- a/lib/colonial_twilight/fln_bot_rules.rb +++ b/lib/colonial_twilight/fln_bot_rules.rb @@ -234,6 +234,12 @@ module ColonialTwilight h.reject { |_k, v| v.zero? } # FIXME in empty? maybe hide active guerrillas ? end + def pick_guerrillas_from(board = @board) + return :available if board.available_fln_underground.positive? + + _remove_guerrillas_priority(board.spaces).sample + end + # 1) place: outofplay -> available | bases -> guerrillas if choice # 2) place: underground first unless from map then place active first flipped as underground # 3) march: underground -> active, unless march would activate then move active first diff --git a/spec/fln_bot_rules_spec.rb b/spec/fln_bot_rules_spec.rb index 328b316..2abe2b8 100644 --- a/spec/fln_bot_rules_spec.rb +++ b/spec/fln_bot_rules_spec.rb @@ -651,6 +651,13 @@ describe ColonialTwilight::FLNBotRules do expect(@rules._remove_guerrillas_priority([a, b, c, d], { d => true })[0]).to be b end + it 'pick guerrillas from most guerrillas' do + @rules.board.spaces << Sector.new(fln_active: 2, fln_underground: 1) + @rules.board.spaces << (b = Sector.new(fln_active: 2, fln_underground: 2)) + @rules.board.spaces << Sector.new(fln_active: 1, fln_underground: 2) + expect(@rules.pick_guerrillas_from(@rules.board)).to be b + end + it 'remove_from all' do a = Sector.new(fln_active: 2, fln_underground: 1, fln_bases: 1) h = @rules.remove_from(a, 6) -- cgit v1.1-2-g2b99