summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2023-10-06 16:45:18 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2023-10-06 16:45:18 +0200
commit853ab7db1c4bcb1a8f95b400435c24a5e8bcf6c7 (patch)
tree9a5038a6ee69829a09f9e5ce896f3f5f497cd0d0
parentdcc1cc51c4ac9eb80431999fef79f0d46728073b (diff)
downloadcolonial-twilight-853ab7db1c4bcb1a8f95b400435c24a5e8bcf6c7.zip
colonial-twilight-853ab7db1c4bcb1a8f95b400435c24a5e8bcf6c7.tar.gz
FLNRulse : clean, add #max_fln_to_place_in
-rw-r--r--lib/colonial_twilight/fln_rules.rb24
-rw-r--r--spec/fln_rules_spec.rb16
2 files changed, 27 insertions, 13 deletions
diff --git a/lib/colonial_twilight/fln_rules.rb b/lib/colonial_twilight/fln_rules.rb
index 3df2c32..481a6ee 100644
--- a/lib/colonial_twilight/fln_rules.rb
+++ b/lib/colonial_twilight/fln_rules.rb
@@ -1,8 +1,6 @@
#! /usr/bin/env ruby
# frozen_string_literal: true
-# rubocop:disable Style/Documentation
-#
module ColonialTwilight
module FLNRules
# Rally 3.3.1 + France Track
@@ -11,15 +9,19 @@ module ColonialTwilight
end
def rally_spaces(board)
- board.search { |s| may_rally_in? s }
+ board.search(&method(:may_rally_in?))
end
def may_agitate_in?(space)
!space.country? && (space.fln_control? || space.fln_bases.positive?)
end
- def agitate_spaces(spaces)
- spaces.select { |s| may_agitate_in? s }
+ def agitate_spaces(board)
+ board.search(&method(:may_agitate_in?))
+ end
+
+ def max_fln_to_place_in(space)
+ space.fln_bases.positive? ? space.pop + 1 - space.fln_cubes : 1
end
# March 3.3.2
@@ -30,7 +32,7 @@ module ColonialTwilight
end
def attack_spaces(board)
- board.search { |s| may_attack_in? s }
+ board.search(&method(:may_attack_in?))
end
# Terror 3.3.4
@@ -39,7 +41,7 @@ module ColonialTwilight
end
def terror_spaces(board)
- board.search { |s| may_terror_in? s }
+ board.search(&method(:may_terror_in?))
end
# Extort 4.3.1
@@ -49,7 +51,7 @@ module ColonialTwilight
end
def extort_spaces(board)
- board.search { |s| may_extort_in? s }
+ board.search(&method(:may_extort_in?))
end
# Subvert 4.3.2
@@ -58,7 +60,7 @@ module ColonialTwilight
end
def subvert_spaces(board)
- board.search { |s| may_subvert_in? s }
+ board.search(&method(:may_subvert_in?))
end
# Ambush 4.3.3
@@ -67,7 +69,7 @@ module ColonialTwilight
end
def ambush_spaces(board)
- board.search { |s| may_ambush_in? s }
+ board.search(&method(:may_ambush_in?))
end
# OAS 5.3.1
@@ -76,7 +78,7 @@ module ColonialTwilight
end
def oas_spaces(board)
- board.search { |s| may_oas_in? s }
+ board.search(&method(:may_oas_in?))
end
end
end
diff --git a/spec/fln_rules_spec.rb b/spec/fln_rules_spec.rb
index a373082..d266cb4 100644
--- a/spec/fln_rules_spec.rb
+++ b/spec/fln_rules_spec.rb
@@ -24,17 +24,29 @@ describe ColonialTwilight::FLNRules do
# 25 sectors + 2 countries
expect(rules.rally_spaces(@board).size).to eq(27)
end
+
+ it 'may place 1 FLN cube' do
+ @board.load :short
+ space = @board.by_name('Mostaganem')
+ expect(rules.max_fln_to_place_in(space)).to eq(1)
+ end
+
+ it 'may place 2 FLN cube' do
+ @board.load :short
+ space = @board.by_name('Orleansville')
+ expect(rules.max_fln_to_place_in(space)).to eq(2)
+ end
end
describe 'Agitate' do
it 'collects spaces where operation can be conducted' do
- expect(rules.agitate_spaces(@board.spaces).size).to eq(0)
+ expect(rules.agitate_spaces(@board).size).to eq(0)
end
it 'collects spaces where operation can be conducted' do
@board.load :short
# 6 with bases + 1 in fln control
- expect(rules.agitate_spaces(@board.spaces).size).to eq(5)
+ expect(rules.agitate_spaces(@board).size).to eq(5)
end
end