Skip to content

Instantly share code, notes, and snippets.

@rlhh
Created December 3, 2013 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rlhh/7769492 to your computer and use it in GitHub Desktop.
Save rlhh/7769492 to your computer and use it in GitHub Desktop.
# Seek&Destroy: Sample Bot
#
# Enjoys following and target and firing many shots
class SomeBot < RTanque::Bot::Brain
NAME = 'I_KILL_YOU'
include RTanque::Bot::BrainHelper
CORNERS = [:NW, :NE, :SE, :SW]
TURRET_FIRE_RANGE = RTanque::Heading::ONE_DEGREE * 5.0
def tick!
@desired_heading ||= nil
if (lock = self.get_radar_lock)
self.destroy_lock(lock)
@desired_heading = nil
else
self.seek_lock
end
self.command.fire(0.25)
end
def destroy_lock(reflection)
if sensors.position.on_top_wall?
command.heading = self.sensors.position.heading(RTanque::Point.new(self.arena.height/2, 0, self.arena))
elsif sensors.position.on_bottom_wall?
command.heading = self.sensors.position.heading(RTanque::Point.new(self.arena.height/2, 0, self.arena))
elsif sensors.position.on_left_wall?
command.heading = self.sensors.position.heading(RTanque::Point.new(0, self.arena.width/2, self.arena))
elsif sensors.position.on_right_wall?
command.heading = self.sensors.position.heading(RTanque::Point.new(0, self.arena.width/2, self.arena))
end
command.radar_heading = reflection.heading + 0.02
command.turret_heading = reflection.heading
command.speed = reflection.distance > 200 ? MAX_BOT_SPEED : MAX_BOT_SPEED / 2.0
if (reflection.heading.delta(sensors.turret_heading)).abs < TURRET_FIRE_RANGE
command.fire(reflection.distance > 200 ? MAX_FIRE_POWER : MIN_FIRE_POWER)
end
end
def seek_lock
if sensors.position.on_top_wall?
command.heading = self.sensors.position.heading(RTanque::Point.new(self.arena.height/2, 0, self.arena))
elsif sensors.position.on_bottom_wall?
command.heading = self.sensors.position.heading(RTanque::Point.new(self.arena.height/2, 0, self.arena))
elsif sensors.position.on_left_wall?
command.heading = self.sensors.position.heading(RTanque::Point.new(0, self.arena.width/2, self.arena))
elsif sensors.position.on_right_wall?
command.heading = self.sensors.position.heading(RTanque::Point.new(0, self.arena.width/2, self.arena))
end
command.radar_heading = sensors.radar_heading + MAX_RADAR_ROTATION
command.speed = MAX_BOT_SPEED
if @desired_heading
command.heading = -@desired_heading
command.turret_heading = @desired_heading
end
end
def make_circles
command.speed = MAX_BOT_SPEED # takes a value between -5 to 5
command.heading = sensors.heading + 0.01
end
def get_radar_lock
@locked_on ||= nil
lock = if @locked_on
sensors.radar.find { |reflection| reflection.name == @locked_on } || sensors.radar.first
else
sensors.radar.first
end
@locked_on = lock.name if lock
lock
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment