Class: XenosEnigma::Xenos::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/xenos_enigma/xenos/base.rb

Overview

Base class holds all the logic for correctly detecting xenos ships

Direct Known Subclasses

Aeldari, Tau

Constant Summary collapse

SHIP_DETECTION =
{ tolerance: 2, compound_tolerance: 1.6, min_segments: 3 }.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBase

Returns a new instance of Base.



9
10
11
12
13
14
15
# File 'lib/xenos_enigma/xenos/base.rb', line 9

def initialize
  raise 'This is an abstract class' if instance_of?(XenosEnigma::Xenos::Base)

  @xeno_signature = self.class::SIGNATURE.split(/\n/)
  @ship_width  = @xeno_signature.first.size
  @ship_height = @xeno_signature.size
end

Instance Attribute Details

#ship_heightObject (readonly)

Returns the value of attribute ship_height.



5
6
7
# File 'lib/xenos_enigma/xenos/base.rb', line 5

def ship_height
  @ship_height
end

#ship_widthObject (readonly)

Returns the value of attribute ship_width.



5
6
7
# File 'lib/xenos_enigma/xenos/base.rb', line 5

def ship_width
  @ship_width
end

#xeno_signatureObject (readonly)

Returns the value of attribute xeno_signature.



5
6
7
# File 'lib/xenos_enigma/xenos/base.rb', line 5

def xeno_signature
  @xeno_signature
end

Instance Method Details

#analyze?(radar_partial, look_ahead_radar_data) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/xenos_enigma/xenos/base.rb', line 17

def analyze?(radar_partial, look_ahead_radar_data)
  return if radar_partial.size < ship_width

  hit = nil

  @xeno_signature.each_with_index do |xeno_row, xeno_y_position|
    if possible_match?(xeno_row, radar_partial)
      hit = full_scan(xeno_y_position, look_ahead_radar_data)
      break if hit
    end
  end

  hit
end