class Rubots::Samples::TargetFinder

Homes into the center of the map, then stays there, points up, and aims down.

Constants

ANGLE_DOWN
ANGLE_LEFT
ANGLE_RIGHT
ANGLE_UP

Public Class Methods

new(map, me, targets) click to toggle source
# File lib/rubots/samples/target_finder.rb, line 10
def initialize(map, me, targets)
  @finding = :x
  @map = map
  @find_x = map.width / 2
  @find_y = map.height / 2
end

Public Instance Methods

command(me, targets) click to toggle source
# File lib/rubots/samples/target_finder.rb, line 17
def command(me, targets)
  if @finding == :x
    find_x(me)
  elsif @finding == :y
    find_y(me)
  elsif me.angle != 0
    rotate_to 0
  else
    rotate_gun_to 180
  end
end
find_x(me) click to toggle source
# File lib/rubots/samples/target_finder.rb, line 33
def find_x(me)
  if me.x > @find_x && me.angle != ANGLE_LEFT
    rotate_to ANGLE_LEFT
  elsif me.x < @find_x && me.angle != ANGLE_RIGHT
    rotate_to ANGLE_RIGHT
  elsif me.x != @find_x
    if (@find_x - me.x).abs > 50
      throttle 4
    else
      throttle 1
    end
  else # At pos x
    @finding = :y
    throttle 0
  end
end
find_y(me) click to toggle source
# File lib/rubots/samples/target_finder.rb, line 50
def find_y(me)
  if me.y > @find_y && me.angle != ANGLE_UP
    rotate_to ANGLE_UP
  elsif me.y < @find_y && me.angle != ANGLE_DOWN
    rotate_to ANGLE_DOWN
  elsif me.y != @find_y
    if (@find_y - me.y).abs > 50
      throttle 5
    else
      throttle 1
    end
  else # At pos y
    @finding = :none
    throttle 0
  end
end
name() click to toggle source
# File lib/rubots/samples/target_finder.rb, line 29
def name
  "GoToCenter"
end