diff options
| -rw-r--r-- | lib/colonial_twilight/fln_bot/fln_rules.rb | 95 | ||||
| -rw-r--r-- | spec/fln_rules_spec.rb | 199 |
2 files changed, 0 insertions, 294 deletions
diff --git a/lib/colonial_twilight/fln_bot/fln_rules.rb b/lib/colonial_twilight/fln_bot/fln_rules.rb deleted file mode 100644 index 2f57403..0000000 --- a/lib/colonial_twilight/fln_bot/fln_rules.rb +++ /dev/null @@ -1,95 +0,0 @@ -# frozen_string_literal: true - -module ColonialTwilight - module FLNRules - # Rally 3.3.1 + France Track - def may_rally_in?(space) - space.sector? || (space.city? && !space.support?) || (space.country? && space.independent?) - end - - def rally_spaces(board) - board.search(&method(:may_rally_in?)) - end - - def may_agitate_in?(space) - !space.country? && (space.fln_control? || space.fln_bases.positive?) && (space.terror.positive? || !space.oppose?) - end - - def agitate_spaces(board) - board.search(&method(:may_agitate_in?)) - end - - def max_placable_guerrillas(space) - space.fln_bases.positive? ? space.fln_bases + space.pop : 1 - end - - def max_agitate_cost(space) - space.terror + (space.oppose? ? 0 : 1) - end - - # March 3.3.2 - def must_stop?(space_from, space_to) - space_from.wilaya != space_to.wilaya || space_from.country? || space_to.country? - end - - def must_activate?(board, space_from, space_to, num = 1) - international = space_from.country? || space_to.country? - (international || space_to.support?) && - (num + space_to.gov_cubes + (international ? board.border_zone_track : 0)) > 3 - end - - # Attack 3.3.3 - def may_attack_in?(space) - space.guerrillas.positive? && space.gov.positive? - end - - def attack_spaces(board) - board.search(&method(:may_attack_in?)) - end - - # Terror 3.3.4 - def may_terror_in?(space) - !space.country? && space.pop.positive? && space.fln_underground.positive? - end - - def terror_spaces(board) - board.search(&method(:may_terror_in?)) - end - - # Extort 4.3.1 - def may_extort_in?(space) - space.fln_underground.positive? && (space.country? ? space.independent? : space.pop.positive? && space.fln_control?) - end - - def extort_spaces(board) - board.search(&method(:may_extort_in?)) - 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(&method(:may_subvert_in?)) - end - - # Ambush 4.3.3 - def may_ambush_in?(space) - may_attack_in?(space) && space.fln_underground.positive? - end - - def ambush_spaces(board) - board.search(&method(:may_ambush_in?)) - end - - # OAS 5.3.1 - def may_oas_in?(space) - !space.country? && space.pop.positive? && space.terror.zero? - end - - def oas_spaces(board) - board.search(&method(:may_oas_in?)) - end - end -end diff --git a/spec/fln_rules_spec.rb b/spec/fln_rules_spec.rb deleted file mode 100644 index dc19be1..0000000 --- a/spec/fln_rules_spec.rb +++ /dev/null @@ -1,199 +0,0 @@ -# frozen_string_literal: true - -require './lib/colonial_twilight/fln_bot/fln_rules' -require './lib/colonial_twilight/board' -require './spec/mock_board' - -class FLNRulesImpl - include ColonialTwilight::FLNRules -end - -describe ColonialTwilight::FLNRules do - rules = FLNRulesImpl.new - - before do - @board = ColonialTwilight::Board.new - end - - describe 'Rally' do - it 'collects spaces where operation can be conducted' do - expect(rules.rally_spaces(@board).size).to eq(28) - end - - it 'collects spaces where operation can be conducted' do - @board.load :short - # 25 sectors + 2 countries - expect(rules.rally_spaces(@board).size).to eq(27) - end - - it 'may_rally_in? sector' do - a = Sector.new - expect(rules.may_rally_in?(a)).to be true - end - - it 'may_rally_in? in city not at support' do - a = Sector.new({ name: 'city', support: false }) - expect(rules.may_rally_in?(a)).to be true - end - - it 'may_rally_in? not in city at support' do - a = Sector.new({ name: 'city', support: true }) - expect(rules.may_rally_in?(a)).to be false - end - - it 'may_rally_in? in independent country' do - a = Sector.new({ name: 'country', independent: true }) - expect(rules.may_rally_in?(a)).to be true - end - - it 'may_rally_in? not in not independent country' do - a = Sector.new({ name: 'country', independent: false }) - expect(rules.may_rally_in?(a)).to be false - end - - it 'may place 1 guerrillas' do - a = Sector.new({ pop: 3 }) - expect(rules.max_placable_guerrillas(a)).to eq(1) - end - - it 'may place pop + base guerrillas' do - a = Sector.new({ pop: 3, fln_bases: 2 }) - expect(rules.max_placable_guerrillas(a)).to eq(5) - end - end - - describe 'Agitate' do - it 'collects spaces where operation can be conducted' do - expect(rules.agitate_spaces(@board).size).to eq(0) - end - - it 'collects spaces where operation can be conducted' do - @board.load :short - # 4 with bases + 1 in fln control : but only 1 without fln control - expect(rules.agitate_spaces(@board).size).to eq(1) - end - - it 'compute agitate cost terror and shift' do - a = Sector.new(terror: 2) - expect(rules.max_agitate_cost(a)).to eq(3) - end - - it 'compute agitate terror' do - a = Sector.new(terror: 1, oppose: true) - expect(rules.max_agitate_cost(a)).to eq(1) - end - end - - describe 'Attack' do - it 'collects spaces where operation can be conducted' do - # 25 sectors + 3 cities - expect(rules.attack_spaces(@board).size).to eq(0) - end - - it 'collects spaces where operation can be conducted' do - @board.load :short - # 25 sectors + 2 countries - expect(rules.attack_spaces(@board).size).to eq(7) - end - end - - describe 'Terror' do - it 'collects spaces where operation can be conducted' do - expect(rules.terror_spaces(@board).size).to eq(0) - end - - it 'collects spaces where operation can be conducted' do - # 6 sectors - @board.load :short - expect(rules.terror_spaces(@board).size).to eq(6) - end - end - - describe 'Extort' do - it 'collects spaces where operation can be conducted' do - expect(rules.extort_spaces(@board).size).to eq(0) - end - - it 'collects spaces where operation can be conducted' do - @board.load :short - # 2 sectors + 2 countries - expect(rules.extort_spaces(@board).size).to eq(4) - end - end - - describe 'Subvert' do - it 'collects spaces where operation can be conducted' do - expect(rules.subvert_spaces(@board).size).to eq(0) - end - - it 'collects spaces where operation can be conducted' do - @board.load :short - # 4 sectors - expect(rules.subvert_spaces(@board).size).to eq(4) - end - end - - describe 'Ambush' do - it 'collects spaces where operation can be conducted' do - # 25 sectors + 3 cities - expect(rules.ambush_spaces(@board).size).to eq(0) - end - - it 'collects spaces where operation can be conducted' do - @board.load :short - # 25 sectors + 2 countries - expect(rules.ambush_spaces(@board).size).to eq(7) - end - end - - describe 'OAS' do - it 'collects spaces where operation can be conducted' do - # 14 sectors + 3 cities - expect(rules.oas_spaces(@board).size).to eq(17) - end - - it 'collects spaces where operation can be conducted' do - @board.load :short - # 11 sectors + 3 countries - expect(rules.oas_spaces(@board).size).to eq(14) - end - end - - describe 'March' do - it 'may keep on' do - expect(rules.must_stop?(@board.by_name('Saida'), @board.by_name('Mecheria'))).to be false - end - - it 'must stop when crossing international borders' do - expect(rules.must_stop?(@board.by_name('Morocco'), @board.by_name('Mecheria'))).to be true - end - - it 'must stop when crossing international borders' do - expect(rules.must_stop?(@board.by_name('Tebessa'), @board.by_name('Tunisia'))).to be true - end - - it 'must stop when crossing a wilaya border' do - expect(rules.must_stop?(@board.by_name('Setif'), @board.by_name('Barika'))).to be true - end - - it 'must not activate' do - expect(rules.must_activate?(@board, @board.by_name('Setif'), @board.by_name('Barika'))).to be false - end - - it 'might activate when support' do - c = @board.by_name('Constantine') - c.alignment = :support - c.add :french_troops, 1 - expect(rules.must_activate?(@board, @board.by_name('Setif'), c, 2)).to be false - expect(rules.must_activate?(@board, @board.by_name('Setif'), c, 3)).to be true - end - - it 'might activate when crossing border' do - c = @board.by_name('Mecheria') - c.add :french_troops, 1 - expect(rules.must_activate?(@board, @board.by_name('Morocco'), c, 2)).to be false - expect(rules.must_activate?(@board, @board.by_name('Morocco'), c, 3)).to be true - end - - end -end |
