Class: XenosEnigma::Xenos::Base
- Inherits:
-
Object
- Object
- XenosEnigma::Xenos::Base
- Defined in:
- lib/xenos_enigma/xenos/base.rb
Overview
Base class holds all the logic for correctly detecting xenos ships
Constant Summary collapse
- SHIP_DETECTION =
{ tolerance: 2, compound_tolerance: 1.6, min_segments: 3 }.freeze
Instance Attribute Summary collapse
-
#ship_height ⇒ Object
readonly
Returns the value of attribute ship_height.
-
#ship_width ⇒ Object
readonly
Returns the value of attribute ship_width.
-
#xeno_signature ⇒ Object
readonly
Returns the value of attribute xeno_signature.
Instance Method Summary collapse
- #analyze?(radar_partial, look_ahead_radar_data) ⇒ Boolean
-
#initialize ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize ⇒ Base
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_height ⇒ Object (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_width ⇒ Object (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_signature ⇒ Object (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
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 |