Skip to content

Instantly share code, notes, and snippets.

@tomjnixon
Created September 5, 2013 15:41
Show Gist options
  • Save tomjnixon/6451920 to your computer and use it in GitHub Desktop.
Save tomjnixon/6451920 to your computer and use it in GitHub Desktop.
crappy bot
class Tomninator < RTanque::Bot::Brain
NAME = 'tomninator'
include RTanque::Bot::BrainHelper
def initialize(*args)
super *args
@scan_state = "scan"
@direction = 0
end
def tick!
# command.speed = 3
# command.heading = 0
# command.radar_heading = Math::PI / 2
# command.turret_heading = Math::PI / 2
command.fire(5)
if @scan_state == "scan"
puts "scan"
# Check if a bot is visible
if sensors.radar.to_a.length > 0
@locked_bot_name = sensors.radar.to_a.first.name
@scan_state = "locked"
else
# spin round
puts "spinning"
command.radar_heading = sensors.radar_heading + Math::PI / 10
end
end
if @scan_state == "locked"
# Try to find the locked bot in the scan
found_bot = nil
sensors.radar.each do |scanned_bot|
if scanned_bot.name == @locked_bot_name
found_bot = scanned_bot
end
end
# if the locked bot is no longer visible, start scanning again.
if found_bot.nil?
@scan_state = "scan"
else
# update radar and turret to move towards locked bot.
@direction = found_bot.heading
command.radar_heading = found_bot.heading
end
end
command.turret_heading = @direction
# do a random walk
command.speed = 3
# range = Math::PI / 2
# command.heading = sensors.heading - range + Random.rand(range * 2)
command.heading = sensors.heading + 0.003 * Math::PI
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment