Class: RTanque::Bot::Radar

Inherits:
Object
  • Object
show all
Extended by:
NormalizedAttr
Includes:
Enumerable, Movable
Defined in:
lib/rtanque/bot/radar.rb

Defined Under Namespace

Classes: Reflection

Constant Summary

VISION_RANGE =
Configuration.radar.vision

Constants included from NormalizedAttr

NormalizedAttr::MAX_DELTA

Instance Method Summary collapse

Methods included from NormalizedAttr

attr_normalized, normalized_attrs

Methods included from Movable

#arena, #arena=, #bound_to_arena, #dead?, #heading, #heading=, #position=, #speed, #speed=, #tick, #update_position

Constructor Details

#initialize(bot, heading) ⇒ Radar

Returns a new instance of Radar



21
22
23
24
25
# File 'lib/rtanque/bot/radar.rb', line 21

def initialize(bot, heading)
  @bot = bot
  @heading = heading
  @reflections = []
end

Instance Method Details

#can_detect?(other_bot) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/rtanque/bot/radar.rb', line 49

def can_detect?(other_bot)
  VISION_RANGE.include?(Heading.delta_between_points(self.position, self.heading, other_bot.position))
end

#each(&block) ⇒ Object



31
32
33
# File 'lib/rtanque/bot/radar.rb', line 31

def each(&block)
  @reflections.each(&block)
end

#empty?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/rtanque/bot/radar.rb', line 35

def empty?
  self.count == 0
end

#positionObject



27
28
29
# File 'lib/rtanque/bot/radar.rb', line 27

def position
  @bot.position
end

#scan(bots) ⇒ Object



39
40
41
42
43
44
45
46
47
# File 'lib/rtanque/bot/radar.rb', line 39

def scan(bots)
  @reflections.clear
  bots.each do |other_bot|
    if self.can_detect?(other_bot)
      @reflections << Reflection.new_from_points(self.position, other_bot.position) { |reflection| reflection.name = other_bot.name }
    end
  end
  self
end