summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2023-10-24 09:32:52 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2023-10-24 09:32:52 +0200
commit4a3f2e4adce52e7a3495f0a825fe2f502e052006 (patch)
tree466b94034eb6d84dd76c7eaea2178570ebf746fd
parentab2b97fc77b8b52c8b9a402b59dbf4454516b64f (diff)
downloadcolonial-twilight-4a3f2e4adce52e7a3495f0a825fe2f502e052006.zip
colonial-twilight-4a3f2e4adce52e7a3495f0a825fe2f502e052006.tar.gz
FLNBotRules : add #available_fln_bases, comment, fix Mock#terror
-rw-r--r--lib/colonial_twilight/fln_bot_rules.rb34
-rw-r--r--spec/fln_bot_rules_spec.rb10
-rw-r--r--spec/mock_board.rb4
3 files changed, 30 insertions, 18 deletions
diff --git a/lib/colonial_twilight/fln_bot_rules.rb b/lib/colonial_twilight/fln_bot_rules.rb
index cbe2145..1049b82 100644
--- a/lib/colonial_twilight/fln_bot_rules.rb
+++ b/lib/colonial_twilight/fln_bot_rules.rb
@@ -158,27 +158,30 @@ module ColonialTwilight
spaces.select { |s| s.send(sym) == v }
end
+ def available_fln_bases?(board = @board)
+ board.available_fln_bases.positive?
+ end
+
def may_add_base_in?(space)
space.guerrillas > 2 && (space.fln_bases < (space.country? ? space.max_bases : 1))
end
def max_placable_guerrillas_in?(space)
- n = max_placable_guerrillas(space)
- n = n.clamp(0, space.pop + 1 - space.guerrillas) if space.fln_bases.positive?
- n
+ max_placable_guerrillas(space).clamp(0, space.fln_bases.positive? ? (space.pop + 1 - space.guerrillas) : 666)
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
+ # 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
+ # applied as last filter in FLNBot#_place_fln
def place_guerrillas(spaces)
# 4) support -> with friendly pieces -> random
- l0 = (l0 = spaces.select(&:support?)).empty? ? spaces : l0
- l1 = (l1 = l0.select { |s| s.guerrillas.positive? }).empty? ? l0 : l1
- l1.shuffle
+ f = _filter(spaces, &:support?)
+ _filter(f) { |s| s.guerrillas.positive? }.shuffle
end
+ # FLNBot#_place_fln_in
def removable_guerrillas(space)
# 5) active only, leave 2 guerrillas at base or support
a = (a = space.fln_underground) > 2 ? 2 : a
@@ -190,6 +193,7 @@ module ColonialTwilight
spaces.reject { |s| steps.key?(s) }
end
+ # FLNBot#_place_fln_in
def remove_guerrillas_priority(spaces, steps)
# 5) #removable_guerrillas then most guerrillas first
return [] if (l = not_selected(spaces, steps).select { |s| removable_guerrillas(s).positive? }).empty?
@@ -197,6 +201,7 @@ module ColonialTwilight
_max(l, :guerrillas).shuffle
end
+ # not used yet
def remove_from(space, num = 1)
# 6) remove active -> underground -> base
h = {}
@@ -206,12 +211,9 @@ module ColonialTwilight
h
end
- def remove_gov(num = 1)
- # 7) map -> availabe (base -> french -> algerian; troops -> police)
- end
-
- # 8) reduce : commitment -> support -> france track -> gov resource
- # 9) shift : support -> oppose | best combined; remove terror only if also shift
- # 10) random
+ # 7) remove gov : map -> availabe (base -> french -> algerian; troops -> police)
+ # 8) reduce : commitment -> support -> france track -> gov resource
+ # 9) shift : support -> oppose | best combined; remove terror only if also shift
+ # 10) random
end
end
diff --git a/spec/fln_bot_rules_spec.rb b/spec/fln_bot_rules_spec.rb
index 547e2ea..a841b67 100644
--- a/spec/fln_bot_rules_spec.rb
+++ b/spec/fln_bot_rules_spec.rb
@@ -367,6 +367,16 @@ describe ColonialTwilight::FLNBotRules do
end
describe '8.1.2 Procedure Guidelines' do
+ it 'available_fln_bases?' do
+ @board.available_fln_bases = 0
+ expect(@rules.available_fln_bases?).to be false
+ end
+
+ it 'available_fln_bases?' do
+ @board.available_fln_bases = 1
+ expect(@rules.available_fln_bases?).to be true
+ end
+
it 'may_add_base_in?' do
a = Sector.new({ fln_active: 3 })
expect(@rules.may_add_base_in?(a)).to be true
diff --git a/spec/mock_board.rb b/spec/mock_board.rb
index 18dad5b..e75ba73 100644
--- a/spec/mock_board.rb
+++ b/spec/mock_board.rb
@@ -4,7 +4,7 @@ class Sector
attr_reader :name
attr_writer :data
- def initialize(data = { name: 'sector', pop: 0, fln_bases: 0, fln_active: 0, fln_underground: 0, gov_cubes: 0, independent: true, support: false, terror: false })
+ def initialize(data = { name: 'sector', pop: 0, fln_bases: 0, fln_active: 0, fln_underground: 0, gov_cubes: 0, independent: true, support: false, terror: 0 })
@name = data[:name] || 'sector'
@data = data
end
@@ -33,7 +33,7 @@ class Sector
@data[:support]
end
- def terror?
+ def terror
@data[:terror]
end