diff options
Diffstat (limited to 'lib/colonial_twilight/board.rb')
| -rw-r--r-- | lib/colonial_twilight/board.rb | 162 |
1 files changed, 14 insertions, 148 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 |
