Skip to content

Instantly share code, notes, and snippets.

@paulsturgess
Created September 3, 2013 19:31
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 paulsturgess/6428480 to your computer and use it in GitHub Desktop.
Save paulsturgess/6428480 to your computer and use it in GitHub Desktop.
class PaulAndRobin < RTanque::Bot::Brain
NAME = 'paul_and_robin'
include RTanque::Bot::BrainHelper
def tick!
command.speed = 1.5
new_heading = if sensors.position.on_wall?
sensors.heading + RTanque::Heading::HALF_ANGLE
else
RTanque::Heading.rand
end
command.heading = new_heading
if bots_in_vision.any?
command.turret_heading = nearest_bot.heading
command.fire(1)
else
seek_heading = sensors.turret_heading + RTanque::Heading.new_from_degrees(10)
command.turret_heading = seek_heading
command.radar_heading = seek_heading
end
end
def nearest_bot
bots_in_vision.first
end
def bots_in_vision
sensors.radar.sort_by(&:distance)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment