summaryrefslogtreecommitdiffstats
path: root/lib/colonial_twilight/fln_bot/fln_terror.rb
blob: a9fd9e2935eb43393f802a018ba9bb41701b4473 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# frozen_string_literal: true

module ColonialTwilight
  module FLNBotTerror
    def terror
      # return false if !available_resources.positive? && !extort
      return false if event_playable? && event_more_effective_than_terror?

      until (space = terror_1_priority(@board.search { |s| may_terror_1_in?(s) }).sample).nil?
        exc = space.fln_underground == 1 ? space : nil
        break if !available_resources.positive? && !extort(except: exc)

        apply_action @turn.operation_in(:terror, space, 1).terror
      end

      if last_campaign?
        until (space = @board.search { |s| may_terror_2_in?(s) }.sample).nil?
          exc = space.fln_underground == 1 ? space : nil
          break if !available_resources.positive? && !extort(except: exc)

          apply_action @turn.operation_in(:terror, space, 1).terror
        end
      end

      @turn.operation_done?
    end
  end
end