Created
April 9, 2013 02:59
-
-
Save parasquid/5342583 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# Seek&Destroy: Sample Bot | |
# | |
# Enjoys following and target and firing many shots | |
class SeekAndDestroy < RTanque::Bot::Brain | |
NAME = 'Jimmy' | |
include RTanque::Bot::BrainHelper | |
TURRET_FIRE_RANGE = RTanque::Heading::ONE_DEGREE * 5.0 | |
def tick! | |
if (lock = self.get_radar_lock) | |
self.destroy_lock(lock) | |
@desired_heading = nil | |
else | |
self.seek_lock | |
end | |
end | |
def destroy_lock(reflection) | |
command.heading = reflection.heading | |
command.radar_heading = reflection.heading | |
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_wall? | |
@desired_heading = sensors.heading + RTanque::Heading::HALF_ANGLE | |
end | |
command.radar_heading = sensors.radar_heading + MAX_RADAR_ROTATION | |
command.speed = 1 | |
if @desired_heading | |
command.heading = @desired_heading | |
command.turret_heading = @desired_heading | |
end | |
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 |
This file contains hidden or 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
# Seek&Destroy: Sample Bot | |
# | |
# Enjoys following and target and firing many shots | |
class SeekAndDestroy < RTanque::Bot::Brain | |
NAME = 'Patrick' | |
include RTanque::Bot::BrainHelper | |
TURRET_FIRE_RANGE = RTanque::Heading::ONE_DEGREE * 5.0 | |
def tick! | |
if (lock = self.get_radar_lock) | |
self.destroy_lock(lock) | |
@desired_heading = nil | |
else | |
self.seek_lock | |
end | |
end | |
def destroy_lock(reflection) | |
command.heading = reflection.heading | |
command.radar_heading = reflection.heading | |
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_wall? | |
@desired_heading = sensors.heading + RTanque::Heading::HALF_ANGLE | |
end | |
command.radar_heading = sensors.radar_heading + MAX_RADAR_ROTATION | |
command.speed = 1 | |
if @desired_heading | |
command.heading = @desired_heading | |
command.turret_heading = @desired_heading | |
end | |
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 |
This file contains hidden or 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
# Seek&Destroy: Sample Bot | |
# | |
# Enjoys following and target and firing many shots | |
class SeekAndDestroy < RTanque::Bot::Brain | |
NAME = 'Tristan' | |
include RTanque::Bot::BrainHelper | |
TURRET_FIRE_RANGE = RTanque::Heading::ONE_DEGREE * 5.0 | |
def tick! | |
if (lock = self.get_radar_lock) | |
self.destroy_lock(lock) | |
@desired_heading = nil | |
else | |
self.seek_lock | |
end | |
end | |
def destroy_lock(reflection) | |
command.heading = reflection.heading | |
command.radar_heading = reflection.heading | |
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_wall? | |
@desired_heading = sensors.heading + RTanque::Heading::HALF_ANGLE | |
end | |
command.radar_heading = sensors.radar_heading + MAX_RADAR_ROTATION | |
command.speed = 1 | |
if @desired_heading | |
command.heading = @desired_heading | |
command.turret_heading = @desired_heading | |
end | |
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