summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2026-03-11 09:39:14 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2026-03-11 09:39:14 +0100
commitb7ef8c8ed365703571befe7396c2627a8c943e8d (patch)
tree15dac0d4bbc7b6aafa854c9da2f68d4a133f33bd
parent1b8d0c020ed45e5969e7f836e6c100bae4552c75 (diff)
downloadcolonial-twilight-b7ef8c8ed365703571befe7396c2627a8c943e8d.zip
colonial-twilight-b7ef8c8ed365703571befe7396c2627a8c943e8d.tar.gz
move force,spaces,scenario,setup into subdir board
-rw-r--r--lib/colonial_twilight/board.rb162
-rw-r--r--lib/colonial_twilight/board/forces.rb (renamed from lib/colonial_twilight/forces.rb)5
-rw-r--r--lib/colonial_twilight/board/scenario.rb67
-rw-r--r--lib/colonial_twilight/board/setup.rb87
-rw-r--r--lib/colonial_twilight/board/spaces.rb (renamed from lib/colonial_twilight/spaces.rb)11
-rw-r--r--spec/forces_spec.rb2
-rw-r--r--spec/spaces_spec.rb2
7 files changed, 177 insertions, 159 deletions
diff --git a/lib/colonial_twilight/board.rb b/lib/colonial_twilight/board.rb
index c999c87..213fa9c 100644
--- a/lib/colonial_twilight/board.rb
+++ b/lib/colonial_twilight/board.rb
@@ -1,7 +1,10 @@
#! /usr/bin/env ruby
# frozen_string_literal: true
-require 'colonial_twilight/spaces'
+require_relative 'board/forces'
+require_relative 'board/spaces'
+require_relative 'board/setup'
+require_relative 'board/scenario'
module ColonialTwilight
class Board
@@ -23,6 +26,9 @@ module ColonialTwilight
# define_method "out_of_play_#{sym}" do @out_of_play.send(sym) end
end
+ include Setup
+ include Scenario
+
def initialize
@spaces = []
@capabilities = []
@@ -36,8 +42,7 @@ module ColonialTwilight
@commitment = Track.new 50
@france_track = Track.new 5
@border_zone_track = Track.new 4
- set_spaces
- set_adjacents
+ setup
end
def inspect
@@ -46,9 +51,9 @@ module ColonialTwilight
def load(scenario)
case scenario
- when :short then short
- when :medium then medium
- when :full then full
+ when :short then short_scenario
+ when :medium then medium_scenario
+ when :full then full_scenario
else raise "unknown scenario : #{scenario}"
end
end
@@ -93,13 +98,13 @@ module ColonialTwilight
end
def shift(space, towards, num = 1)
- num.times { space.shift towards }
+ num.times { space.shift(towards) }
end
def shift_track(what, amount)
- raise "unknown track : #{what}" unless TRACKS.include? what
+ raise "unknown track : #{what}" unless TRACKS.include?(what)
- instance_variable_get("@#{what}").shift amount
+ instance_variable_get("@#{what}").shift(amount)
end
def apply(action)
@@ -150,144 +155,5 @@ module ColonialTwilight
raise "unknown Board variable named #{obj}"
end
end
-
- def add(kls, *args)
- @spaces << kls.new(*args)
- end
-
- def set_spaces
- mountain = Sector::MOUNTAIN
- border = Sector::BORDER
- coastal = Sector::COASTAL
- add Sector, 'Barika', 'I', 1, 1, mountain
- add Sector, 'Batna', 'I', 2, 0, mountain
- add Sector, 'Biskra', 'I', 3, 0, border
- add Sector, 'Oum El Bouaghi', 'I', 4, 0, mountain
- add Sector, 'Tebessa', 'I', 5, 1, mountain | border
- add Sector, 'Negrine', 'I', 6, 0, mountain | border
- add City, 'Constantine', 'II', 2
- add Sector, 'Setif', 'II', 1, 1, mountain | coastal
- add Sector, 'Philippeville', 'II', 2, 2, mountain | coastal
- add Sector, 'Souk Ahras', 'II', 3, 2, coastal | border
- add Sector, 'Tizi Ouzou', 'III', 1, 2, mountain | coastal
- add Sector, 'Bordj Bou Arreridj', 'III', 2, 1, mountain
- add Sector, 'Bougie', 'III', 3, 2, mountain | coastal
- add City, 'Algiers', 'IV', 3, coastal
- add Sector, 'Medea', 'IV', 1, 2, mountain | coastal
- add Sector, 'Orleansville', 'IV', 2, 2, mountain | coastal
- add City, 'Oran', 'V', 2, coastal
- add Sector, 'Mecheria', 'V', 1, 0, mountain | border
- add Sector, 'Tlemcen', 'V', 2, 1, border | coastal
- add Sector, 'Sidi Bel Abbes', 'V', 3, 1, coastal
- add Sector, 'Mostaganem', 'V', 4, 2, mountain | coastal
- add Sector, 'Saida', 'V', 5, 0, mountain
- add Sector, 'Mascara', 'V', 6, 0, mountain
- add Sector, 'Tiaret', 'V', 7, 0, mountain
- add Sector, 'Ain Sefra', 'V', 8, 0, border
- add Sector, 'Laghouat', 'V', 9, 0
- add Sector, 'Sidi Aissa', 'VI', 1, 0, mountain
- add Sector, 'Ain Oussera', 'VI', 2, 1, mountain
- add Country, 'Morocco'
- add Country, 'Tunisia'
- end
-
- def adjacents(name, *args)
- by_name(name).adjacents = args
- end
-
- def set_adjacents
- adjacents 'Barika', 1, 2, 3, 7, 8, 11, 26
- adjacents 'Batna', 0, 2, 3, 5
- adjacents 'Biskra', 0, 1, 5, 25, 26, 29
- adjacents 'Oum El Bouaghi', 0, 1, 4, 5, 8, 9
- adjacents 'Tebessa', 3, 5, 9, 29
- adjacents 'Negrine', 1, 2, 3, 4, 29
- adjacents 'Constantine', 7, 8
- adjacents 'Setif', 0, 6, 8, 11, 12
- adjacents 'Philippeville', 0, 3, 7, 6, 9
- adjacents 'Souk Ahras', 3, 4, 8, 29
- adjacents 'Tizi Ouzou', 11, 12, 14
- adjacents 'Bordj Bou Arreridj', 0, 7, 10, 12, 14, 26
- adjacents 'Bougie', 7, 10, 11
- adjacents 'Algiers', 14
- adjacents 'Medea', 10, 11, 13, 15, 26, 27
- adjacents 'Orleansville', 14, 20, 23, 27
- adjacents 'Oran', 19
- adjacents 'Mecheria', 18, 21, 24, 28
- adjacents 'Tlemcen', 17, 19, 21, 28
- adjacents 'Sidi Bel Abbes', 16, 18, 20, 21, 22
- adjacents 'Mostaganem', 15, 19, 22, 23
- adjacents 'Saida', 17, 18, 19, 22, 24
- adjacents 'Mascara', 19, 20, 21, 23, 24
- adjacents 'Tiaret', 15, 20, 22, 24, 27
- adjacents 'Ain Sefra', 17, 21, 22, 23, 25, 27, 28
- adjacents 'Laghouat', 2, 24, 26, 27
- adjacents 'Sidi Aissa', 0, 2, 11, 14, 25, 27
- adjacents 'Ain Oussera', 14, 15, 23, 24, 25, 26
- adjacents 'Morocco', 17, 18, 24
- adjacents 'Tunisia', 2, 4, 5, 9
- end
-
- def resettle(name)
- by_name(name).resettle!
- end
-
- def set_space(idx, opts, align = nil)
- s = @spaces[idx]
- s.alignment = align unless align.nil?
- %i[gov_bases fln_bases french_troops french_police algerian_troops algerian_police
- fln_underground].each { |sym| s.add(sym, opts[sym]) if opts.key? sym }
- end
-
- def short
- @opposition_bases.v = 19
- @support_commitment.v = 22
- @commitment.v = 15
- @fln_resources.v = 15
- @gov_resources.v = 20
- @france_track.v = 4
- @border_zone_track.v = 3
- @out_of_play.init({ fln_underground: 5 })
- @available.init({ gov_bases: 2, french_police: 4, fln_bases: 7, fln_underground: 8 })
- resettle 'Setif'
- resettle 'Tlemcen'
- resettle 'Bordj Bou Arreridj'
-
- set_space 0, { algerian_police: 1, fln_underground: 1 }, :oppose
- set_space 2, { french_police: 1 }
- set_space 4, { algerian_police: 1, fln_underground: 1 }, :oppose
- set_space 5, { french_police: 1 }
- set_space 6, { french_police: 1 }, :support
- set_space 7, { fln_underground: 1 }
- set_space 8, { french_troops: 4, algerian_police: 1, gov_bases: 1 }
- set_space 9, { french_troops: 1, algerian_police: 1, gov_bases: 1, fln_underground: 1, fln_bases: 1 }, :oppose
- set_space 10, { french_police: 1, fln_underground: 1, fln_bases: 1 }, :oppose
- set_space 11, { french_police: 1 }
- set_space 12, { french_police: 1, fln_underground: 1, fln_bases: 1 }, :oppose
- set_space 13, { french_troops: 4, algerian_troops: 1, french_police: 1 }, :support
- set_space 14, { algerian_troops: 1, gov_bases: 1 }
- set_space 15, { french_police: 1, algerian_police: 1, fln_underground: 1, fln_bases: 1 }, :oppose
- set_space 16, { algerian_troops: 1, french_police: 1, algerian_police: 1 }, :support
- set_space 17, { french_police: 1, algerian_police: 1 }
- set_space 18, { french_police: 2, fln_underground: 1 }
- set_space 19, { french_police: 1, gov_bases: 1 }
- set_space 20, { french_police: 1 }
- set_space 22, { french_police: 1 }
- set_space 23, { french_police: 1 }
- set_space 24, { french_police: 1 }
- set_space 27, {}, :oppose
- set_space 28, { fln_underground: 4, fln_bases: 2 }
- set_space 29, { fln_underground: 5, fln_bases: 2 }
- spaces[28].independent!
- spaces[29].independent!
- end
-
- def medium
- raise 'MEDIUM scenario net implemented yet'
- end
-
- def full
- raise 'FULL scenario net implemented yet'
- end
end
end
diff --git a/lib/colonial_twilight/forces.rb b/lib/colonial_twilight/board/forces.rb
index 6d26dea..ecf27df 100644
--- a/lib/colonial_twilight/forces.rb
+++ b/lib/colonial_twilight/board/forces.rb
@@ -1,4 +1,3 @@
-#! /usr/bin/env ruby
# frozen_string_literal: true
# rubocop:disable Style/AccessorGrouping
@@ -20,7 +19,7 @@ module ColonialTwilight
@fln_underground, @fln_active, @fln_bases = 0, 0, 0
@max_bases = nil
@control = :uncontrolled
- @max_bases = 2 if %i[Country Sector].include? sym
+ @max_bases = 2 if %i[Country Sector].include?(sym)
_variables_to_remove(sym)&.each do |s|
instance_variable_set(s, nil)
end
@@ -120,7 +119,7 @@ module ColonialTwilight
end
def activate(num)
- raise "can't activate #{num}" if @fln_underground < num
+ raise "cannot activate #{num}" if @fln_underground < num
@fln_underground -= num
@fln_active += num
diff --git a/lib/colonial_twilight/board/scenario.rb b/lib/colonial_twilight/board/scenario.rb
new file mode 100644
index 0000000..a0f5edf
--- /dev/null
+++ b/lib/colonial_twilight/board/scenario.rb
@@ -0,0 +1,67 @@
+# frozen_string_literal: true
+
+module ColonialTwilight
+ module Scenario
+ def resettle(name)
+ by_name(name).resettle!
+ end
+
+ def set_space(idx, opts, align = nil)
+ s = @spaces[idx]
+ s.alignment = align unless align.nil?
+ %i[gov_bases fln_bases french_troops french_police algerian_troops algerian_police
+ fln_underground].each { |sym| s.add(sym, opts[sym]) if opts.key?(sym) }
+ end
+
+ def short_scenario
+ @opposition_bases.v = 19
+ @support_commitment.v = 22
+ @commitment.v = 15
+ @fln_resources.v = 15
+ @gov_resources.v = 20
+ @france_track.v = 4
+ @border_zone_track.v = 3
+ @out_of_play.init(fln_underground: 5)
+ @available.init(gov_bases: 2, french_police: 4, fln_bases: 7, fln_underground: 8)
+ resettle 'Setif'
+ resettle 'Tlemcen'
+ resettle 'Bordj Bou Arreridj'
+
+ set_space 0, { algerian_police: 1, fln_underground: 1 }, :oppose
+ set_space 2, { french_police: 1 }
+ set_space 4, { algerian_police: 1, fln_underground: 1 }, :oppose
+ set_space 5, { french_police: 1 }
+ set_space 6, { french_police: 1 }, :support
+ set_space 7, { fln_underground: 1 }
+ set_space 8, { french_troops: 4, algerian_police: 1, gov_bases: 1 }
+ set_space 9, { french_troops: 1, algerian_police: 1, gov_bases: 1, fln_underground: 1, fln_bases: 1 }, :oppose
+ set_space 10, { french_police: 1, fln_underground: 1, fln_bases: 1 }, :oppose
+ set_space 11, { french_police: 1 }
+ set_space 12, { french_police: 1, fln_underground: 1, fln_bases: 1 }, :oppose
+ set_space 13, { french_troops: 4, algerian_troops: 1, french_police: 1 }, :support
+ set_space 14, { algerian_troops: 1, gov_bases: 1 }
+ set_space 15, { french_police: 1, algerian_police: 1, fln_underground: 1, fln_bases: 1 }, :oppose
+ set_space 16, { algerian_troops: 1, french_police: 1, algerian_police: 1 }, :support
+ set_space 17, { french_police: 1, algerian_police: 1 }
+ set_space 18, { french_police: 2, fln_underground: 1 }
+ set_space 19, { french_police: 1, gov_bases: 1 }
+ set_space 20, { french_police: 1 }
+ set_space 22, { french_police: 1 }
+ set_space 23, { french_police: 1 }
+ set_space 24, { french_police: 1 }
+ set_space 27, {}, :oppose
+ set_space 28, { fln_underground: 4, fln_bases: 2 }
+ set_space 29, { fln_underground: 5, fln_bases: 2 }
+ spaces[28].independent!
+ spaces[29].independent!
+ end
+
+ def medium_scenario
+ raise 'MEDIUM scenario net implemented yet'
+ end
+
+ def full_scenario
+ raise 'FULL scenario net implemented yet'
+ end
+ end
+end
diff --git a/lib/colonial_twilight/board/setup.rb b/lib/colonial_twilight/board/setup.rb
new file mode 100644
index 0000000..110a674
--- /dev/null
+++ b/lib/colonial_twilight/board/setup.rb
@@ -0,0 +1,87 @@
+# frozen_string_literal: true
+
+module ColonialTwilight
+ module Setup
+ def setup
+ set_spaces
+ set_adjacents
+ end
+
+ def add(kls, *args)
+ @spaces << kls.new(*args)
+ end
+
+ def set_spaces
+ mountain = Sector::MOUNTAIN
+ border = Sector::BORDER
+ coastal = Sector::COASTAL
+ add Sector, 'Barika', 'I', 1, 1, mountain
+ add Sector, 'Batna', 'I', 2, 0, mountain
+ add Sector, 'Biskra', 'I', 3, 0, border
+ add Sector, 'Oum El Bouaghi', 'I', 4, 0, mountain
+ add Sector, 'Tebessa', 'I', 5, 1, mountain | border
+ add Sector, 'Negrine', 'I', 6, 0, mountain | border
+ add City, 'Constantine', 'II', 2
+ add Sector, 'Setif', 'II', 1, 1, mountain | coastal
+ add Sector, 'Philippeville', 'II', 2, 2, mountain | coastal
+ add Sector, 'Souk Ahras', 'II', 3, 2, coastal | border
+ add Sector, 'Tizi Ouzou', 'III', 1, 2, mountain | coastal
+ add Sector, 'Bordj Bou Arreridj', 'III', 2, 1, mountain
+ add Sector, 'Bougie', 'III', 3, 2, mountain | coastal
+ add City, 'Algiers', 'IV', 3, coastal
+ add Sector, 'Medea', 'IV', 1, 2, mountain | coastal
+ add Sector, 'Orleansville', 'IV', 2, 2, mountain | coastal
+ add City, 'Oran', 'V', 2, coastal
+ add Sector, 'Mecheria', 'V', 1, 0, mountain | border
+ add Sector, 'Tlemcen', 'V', 2, 1, border | coastal
+ add Sector, 'Sidi Bel Abbes', 'V', 3, 1, coastal
+ add Sector, 'Mostaganem', 'V', 4, 2, mountain | coastal
+ add Sector, 'Saida', 'V', 5, 0, mountain
+ add Sector, 'Mascara', 'V', 6, 0, mountain
+ add Sector, 'Tiaret', 'V', 7, 0, mountain
+ add Sector, 'Ain Sefra', 'V', 8, 0, border
+ add Sector, 'Laghouat', 'V', 9, 0
+ add Sector, 'Sidi Aissa', 'VI', 1, 0, mountain
+ add Sector, 'Ain Oussera', 'VI', 2, 1, mountain
+ add Country, 'Morocco'
+ add Country, 'Tunisia'
+ end
+
+ def adjacents(name, *args)
+ by_name(name).adjacents = args
+ end
+
+ def set_adjacents
+ adjacents 'Barika', 1, 2, 3, 7, 8, 11, 26
+ adjacents 'Batna', 0, 2, 3, 5
+ adjacents 'Biskra', 0, 1, 5, 25, 26, 29
+ adjacents 'Oum El Bouaghi', 0, 1, 4, 5, 8, 9
+ adjacents 'Tebessa', 3, 5, 9, 29
+ adjacents 'Negrine', 1, 2, 3, 4, 29
+ adjacents 'Constantine', 7, 8
+ adjacents 'Setif', 0, 6, 8, 11, 12
+ adjacents 'Philippeville', 0, 3, 7, 6, 9
+ adjacents 'Souk Ahras', 3, 4, 8, 29
+ adjacents 'Tizi Ouzou', 11, 12, 14
+ adjacents 'Bordj Bou Arreridj', 0, 7, 10, 12, 14, 26
+ adjacents 'Bougie', 7, 10, 11
+ adjacents 'Algiers', 14
+ adjacents 'Medea', 10, 11, 13, 15, 26, 27
+ adjacents 'Orleansville', 14, 20, 23, 27
+ adjacents 'Oran', 19
+ adjacents 'Mecheria', 18, 21, 24, 28
+ adjacents 'Tlemcen', 17, 19, 21, 28
+ adjacents 'Sidi Bel Abbes', 16, 18, 20, 21, 22
+ adjacents 'Mostaganem', 15, 19, 22, 23
+ adjacents 'Saida', 17, 18, 19, 22, 24
+ adjacents 'Mascara', 19, 20, 21, 23, 24
+ adjacents 'Tiaret', 15, 20, 22, 24, 27
+ adjacents 'Ain Sefra', 17, 21, 22, 23, 25, 27, 28
+ adjacents 'Laghouat', 2, 24, 26, 27
+ adjacents 'Sidi Aissa', 0, 2, 11, 14, 25, 27
+ adjacents 'Ain Oussera', 14, 15, 23, 24, 25, 26
+ adjacents 'Morocco', 17, 18, 24
+ adjacents 'Tunisia', 2, 4, 5, 9
+ end
+ end
+end
diff --git a/lib/colonial_twilight/spaces.rb b/lib/colonial_twilight/board/spaces.rb
index 5c04250..fad3170 100644
--- a/lib/colonial_twilight/spaces.rb
+++ b/lib/colonial_twilight/board/spaces.rb
@@ -1,7 +1,6 @@
-#! /usr/bin/env ruby
# frozen_string_literal: true
-require 'colonial_twilight/forces'
+require_relative 'forces'
module ColonialTwilight
class Track
@@ -158,8 +157,8 @@ module ColonialTwilight
end
def resettle!
- raise "can't resettle a country " if country?
- raise "can't resettle a sector with a population =! 1" if @pop != 1
+ raise 'cannot resettle a country' if country?
+ raise 'cannot resettle a sector with a population =! 1' if @pop != 1
@pop = 0
@resettled = true
@@ -167,11 +166,11 @@ module ColonialTwilight
def shift(towards)
if towards == :oppose
- raise "can't shift towards oppose" if oppose?
+ raise 'cannot shift towards oppose' if oppose?
@alignment = (support? ? :neutral : :oppose)
elsif towards == :support
- raise "can't shift towards support" if support?
+ raise 'cannot shift towards support' if support?
@alignment = (oppose? ? :neutral : :support)
else
diff --git a/spec/forces_spec.rb b/spec/forces_spec.rb
index 110139e..79e4e2b 100644
--- a/spec/forces_spec.rb
+++ b/spec/forces_spec.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require './lib/colonial_twilight/forces'
+require './lib/colonial_twilight/board/forces'
describe ColonialTwilight::Forces do
describe 'Available' do
diff --git a/spec/spaces_spec.rb b/spec/spaces_spec.rb
index 0e05707..1f2726f 100644
--- a/spec/spaces_spec.rb
+++ b/spec/spaces_spec.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
-require './lib/colonial_twilight/spaces'
+require './lib/colonial_twilight/board/spaces'
# require './spec/mock_board'
describe ColonialTwilight::Track do