From 3f8fa1c7d6a2bde1e1aa9e1507ffb346c2790d28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Wed, 11 Mar 2026 09:49:23 +0100 Subject: move @control from Forces to Sector --- lib/colonial_twilight/board/forces.rb | 28 ++++++---------------------- lib/colonial_twilight/board/spaces.rb | 28 ++++++++++++++++++++++------ spec/forces_spec.rb | 16 ++++------------ 3 files changed, 32 insertions(+), 40 deletions(-) diff --git a/lib/colonial_twilight/board/forces.rb b/lib/colonial_twilight/board/forces.rb index ecf27df..b9bd94e 100644 --- a/lib/colonial_twilight/board/forces.rb +++ b/lib/colonial_twilight/board/forces.rb @@ -10,7 +10,7 @@ module ColonialTwilight attr_reader :french_troops, :french_police attr_reader :fln_underground, :fln_active attr_reader :fln_bases, :gov_bases - attr_reader :max_bases, :control + attr_reader :max_bases def initialize(sym) @name = sym @@ -18,7 +18,6 @@ module ColonialTwilight @french_troops, @french_police, @gov_bases = 0, 0, 0 @fln_underground, @fln_active, @fln_bases = 0, 0, 0 @max_bases = nil - @control = :uncontrolled @max_bases = 2 if %i[Country Sector].include?(sym) _variables_to_remove(sym)&.each do |s| instance_variable_set(s, nil) @@ -33,10 +32,10 @@ module ColonialTwilight def _variables_to_remove(sym) case sym - when :available then %i[@control @fln_active] - when :casualties then %i[@control @fln_active @fln_bases] - when :out_of_play then %i[@control @algerian_troops @algerian_police @fln_active @fln_bases] - when :Country then %i[@control @algerian_troops @algerian_police @french_troops @french_police] + when :available then %i[@fln_active] + when :casualties then %i[@fln_active @fln_bases] + when :out_of_play then %i[@algerian_troops @algerian_police @fln_active @fln_bases] + when :Country then %i[@algerian_troops @algerian_police @french_troops @french_police] when :City then nil when :Sector then nil end @@ -59,7 +58,7 @@ module ColonialTwilight def data h = {} %i[algerian_troops algerian_police french_troops french_police gov_bases - fln_underground fln_active fln_bases control].each do |sym| + fln_underground fln_active fln_bases].each do |sym| h[sym] = send(sym) unless send(sym).nil? end h @@ -115,7 +114,6 @@ module ColonialTwilight else raise "unknown force type : #{type}" end - update_control end def activate(num) @@ -135,19 +133,5 @@ module ColonialTwilight @gov_bases += num if type == :gov_bases @fln_bases += num if type == :fln_bases end - - def update_control - return nil if @control.nil? - - ctr = @control - @control = ( - case gov <=> fln - when 0 then :uncontrolled - when 1 then :GOV - when -1 then :FLN - end - ) - @control != ctr - end end end diff --git a/lib/colonial_twilight/board/spaces.rb b/lib/colonial_twilight/board/spaces.rb index fad3170..183a6a2 100644 --- a/lib/colonial_twilight/board/spaces.rb +++ b/lib/colonial_twilight/board/spaces.rb @@ -36,7 +36,7 @@ module ColonialTwilight BORDER = 4 attr_reader :wilaya, :sector, :name, :resettled - attr_accessor :pop, :terror, :adjacents, :alignment + attr_accessor :pop, :terror, :adjacents, :alignment, :control def initialize(name, wilaya, sector, pop, attrs = 0) @name = name @@ -45,6 +45,7 @@ module ColonialTwilight @pop = pop @attrs = attrs @alignment = :neutral + @control = :uncontrolled @resettled = false @terror = 0 @forces = Forces.new self.class.name.split('::')[-1].to_sym @@ -64,6 +65,18 @@ module ColonialTwilight @descr = "(#{@wilaya}-#{@sector})" end + def update_control + ctr = @control + @control = ( + case @forces.gov <=> @forces.fln + when 0 then :uncontrolled + when 1 then :GOV + when -1 then :FLN + end + ) + @control != ctr + end + public def to_s @@ -73,7 +86,7 @@ module ColonialTwilight def inspect "\n#{@descr} : #{@terrain} population : #{@pop}#{@resettled ? ' resettled' : ''} - control : #{control} + control : #{@control} alignment : #{@alignment} terror : #{@terror} #{@forces} @@ -86,7 +99,7 @@ module ColonialTwilight %i[gov gov_bases gov_cubes french_cubes algerian_cubes troops police french_troops french_police algerian_troops algerian_police - fln fln_bases guerrillas fln_underground fln_active max_bases control].each do |sym| + fln fln_bases guerrillas fln_underground fln_active max_bases].each do |sym| define_method(sym) { @forces.send(sym) } end @@ -131,19 +144,20 @@ module ColonialTwilight end def uncontrolled? - control == :uncontrolled + @control == :uncontrolled end def fln_control? - control == :FLN + @control == :FLN end def gov_control? - control == :GOV + @control == :GOV end def add(type, num = 1) @forces.add(type, num) + update_control end def shift_terror(num = 1) @@ -208,6 +222,8 @@ module ColonialTwilight @descr += ' : French' end + def update_control; end + def sector? false end diff --git a/spec/forces_spec.rb b/spec/forces_spec.rb index 79e4e2b..09bb6b1 100644 --- a/spec/forces_spec.rb +++ b/spec/forces_spec.rb @@ -9,7 +9,7 @@ describe ColonialTwilight::Forces do end it 'nil' do - %i[control fln_active].each do |sym| + %i[fln_active].each do |sym| expect(@f.send(sym)).to be nil end end @@ -26,7 +26,7 @@ describe ColonialTwilight::Forces do end it 'nil' do - %i[control fln_active fln_bases].each do |sym| + %i[fln_active fln_bases].each do |sym| expect(@f.send(sym)).to be nil end end @@ -44,7 +44,7 @@ describe ColonialTwilight::Forces do end it 'nil' do - %i[control algerian_troops algerian_police fln_active fln_bases].each do |sym| + %i[algerian_troops algerian_police fln_active fln_bases].each do |sym| expect(@f.send(sym)).to be nil end end @@ -62,7 +62,7 @@ describe ColonialTwilight::Forces do end it 'nil' do - %i[control algerian_troops algerian_police french_troops french_police].each do |sym| + %i[algerian_troops algerian_police french_troops french_police].each do |sym| expect(@f.send(sym)).to be nil end end @@ -112,14 +112,6 @@ describe ColonialTwilight::Forces do expect(@f.police).to be 8 end - it 'switch control' do - expect(@f.control).to be :GOV - @f.add :fln_active, 2 - expect(@f.control).to be :uncontrolled - @f.add :fln_active, 1 - expect(@f.control).to be :FLN - end - it 'inspect' do expect(@f.inspect.instance_of?(String)).to be true end -- cgit v1.1-2-g2b99