Created
September 5, 2013 15:31
-
-
Save chrislo/6451782 to your computer and use it in GitHub Desktop.
RTanque bot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class LibbyBot < RTanque::Bot::Brain | |
NAME = 'libby_bot' | |
include RTanque::Bot::BrainHelper | |
TURRET_FIRE_RANGE = RTanque::Heading::ONE_DEGREE * 1.0 | |
def tick! | |
self.move_randomly | |
if (target = self.nearest_target) | |
self.fire_upon(target) | |
else | |
self.detect_targets | |
end | |
end | |
def fire_upon(target) | |
self.command.radar_heading = target.heading | |
self.command.turret_heading = target.heading | |
if self.sensors.turret_heading.delta(target.heading).abs < TURRET_FIRE_RANGE | |
self.command.fire(3) | |
end | |
end | |
def nearest_target | |
self.sensors.radar.min { |a,b| a.distance <=> b.distance } | |
end | |
def detect_targets | |
self.command.radar_heading = self.sensors.radar_heading + MAX_RADAR_ROTATION | |
self.command.turret_heading = self.sensors.heading + RTanque::Heading::HALF_ANGLE | |
end | |
def move_randomly | |
self.at_tick_interval(2) { | |
command.heading = sensors.heading + RTanque::Heading.new_from_degrees(rand(5)) | |
command.speed = MAX_BOT_SPEED | |
} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment