summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/colonial_twilight/fln_rules.rb73
-rw-r--r--spec/fln_rules_spec.rb99
2 files changed, 172 insertions, 0 deletions
diff --git a/lib/colonial_twilight/fln_rules.rb b/lib/colonial_twilight/fln_rules.rb
new file mode 100644
index 0000000..fa07805
--- /dev/null
+++ b/lib/colonial_twilight/fln_rules.rb
@@ -0,0 +1,73 @@
+#! /usr/bin/env ruby
+# frozen_string_literal: true
+
+module ColonialTwilight
+ # general rules governing operations and activities
+ module FLNRules
+ # Rally 3.3.1
+ def may_rally_in?(space)
+ (space.sector? || (space.city? && !space.support?) || (space.country? && space.independent?))
+ end
+
+ def rally_spaces(board)
+ board.search { |s| may_rally_in? s }
+ end
+
+ # March 3.3.2
+
+ # Attack 3.3.3
+ def may_attack_in?(space)
+ (space.fln_cubes.positive? && space.gov.positive?)
+ end
+
+ def attack_spaces(board)
+ board.search { |s| may_attack_in? s }
+ end
+
+ # Terror 3.3.4
+ def may_terror_in?(space)
+ (!space.country? && !space.pop.zero? && space.fln_underground.positive?)
+ end
+
+ def terror_spaces(board)
+ board.search { |s| may_terror_in? s }
+ end
+
+ # Extort 4.3.1
+ def may_extort_in?(space)
+ (!space.pop.zero? && space.fln_underground.positive? && space.fln_control? &&
+ (space.country? ? space.independent? : true))
+ end
+
+ def extort_spaces(board)
+ board.search { |s| may_extort_in? s }
+ end
+
+ # Subvert 4.3.2
+ def may_subvert_in?(space)
+ (space.fln_underground.positive? && space.algerian_cubes.positive?)
+ end
+
+ def subvert_spaces(board)
+ board.search { |s| may_subvert_in? s }
+ end
+
+ # Ambush 4.3.3
+ def may_ambush_in?(space)
+ may_attack_in?(space)
+ end
+
+ def ambush_spaces(board)
+ board.search { |s| may_ambush_in? s }
+ end
+
+ # OAS 5.3.1
+ def may_oas_in?(space)
+ (!space.country? && !space.pop.zero? && !space.terror.positive?)
+ end
+
+ def oas_spaces(board)
+ board.search { |s| may_oas_in? s }
+ end
+ end
+end
diff --git a/spec/fln_rules_spec.rb b/spec/fln_rules_spec.rb
new file mode 100644
index 0000000..8c3ec04
--- /dev/null
+++ b/spec/fln_rules_spec.rb
@@ -0,0 +1,99 @@
+# frozen_string_literal: true
+
+require './lib/colonial_twilight/fln_rules'
+require './lib/colonial_twilight/board'
+
+class FLNRulesImpl
+ include ColonialTwilight::FLNRules
+end
+
+describe ColonialTwilight::FLNRules do
+ rules = FLNRulesImpl.new
+ describe 'Rally' do
+ board = ColonialTwilight::Board.new
+ # 25 sectors + 3 cities
+ it 'collects spaces where operation can be conducted' do expect(rules.rally_spaces(board).size).to eq(28) end
+ end
+
+ describe 'Rally' do
+ board = ColonialTwilight::Board.new
+ board.load :short
+ # 25 sectors + 2 countries
+ it 'collects spaces where operation can be conducted' do expect(rules.rally_spaces(board).size).to eq(27) end
+ end
+
+ describe 'Attack' do
+ board = ColonialTwilight::Board.new
+ # 25 sectors + 3 cities
+ it 'collects spaces where operation can be conducted' do expect(rules.attack_spaces(board).size).to eq(0) end
+ end
+
+ describe 'Attack' do
+ board = ColonialTwilight::Board.new
+ board.load :short
+ # 25 sectors + 2 countries
+ it 'collects spaces where operation can be conducted' do expect(rules.attack_spaces(board).size).to eq(7) end
+ end
+
+ describe 'Terror' do
+ board = ColonialTwilight::Board.new
+ it 'collects spaces where operation can be conducted' do expect(rules.terror_spaces(board).size).to eq(0) end
+ end
+
+ describe 'Terror' do
+ board = ColonialTwilight::Board.new
+ board.load :short
+ # 6 sectors
+ it 'collects spaces where operation can be conducted' do expect(rules.terror_spaces(board).size).to eq(6) end
+ end
+
+ describe 'Extort' do
+ board = ColonialTwilight::Board.new
+ it 'collects spaces where operation can be conducted' do expect(rules.extort_spaces(board).size).to eq(0) end
+ end
+
+ describe 'Extort' do
+ board = ColonialTwilight::Board.new
+ board.load :short
+ # 2 sectors
+ it 'collects spaces where operation can be conducted' do expect(rules.extort_spaces(board).size).to eq(2) end
+ end
+
+ describe 'Subvert' do
+ board = ColonialTwilight::Board.new
+ it 'collects spaces where operation can be conducted' do expect(rules.subvert_spaces(board).size).to eq(0) end
+ end
+
+ describe 'Subvert' do
+ board = ColonialTwilight::Board.new
+ board.load :short
+ # 4 sectors
+ it 'collects spaces where operation can be conducted' do expect(rules.subvert_spaces(board).size).to eq(4) end
+ end
+
+ describe 'Ambush' do
+ board = ColonialTwilight::Board.new
+ # 25 sectors + 3 cities
+ it 'collects spaces where operation can be conducted' do expect(rules.ambush_spaces(board).size).to eq(0) end
+ end
+
+ describe 'Ambush' do
+ board = ColonialTwilight::Board.new
+ board.load :short
+ # 25 sectors + 2 countries
+ it 'collects spaces where operation can be conducted' do expect(rules.ambush_spaces(board).size).to eq(7) end
+ end
+
+ describe 'OAS' do
+ board = ColonialTwilight::Board.new
+ # 14 sectors + 3 cities
+ it 'collects spaces where operation can be conducted' do expect(rules.oas_spaces(board).size).to eq(17) end
+ end
+
+ describe 'OAS' do
+ board = ColonialTwilight::Board.new
+ board.load :short
+ # 11 sectors + 3 countries
+ it 'collects spaces where operation can be conducted' do expect(rules.oas_spaces(board).size).to eq(14) end
+ end
+end