Created
July 9, 2014 02:03
-
-
Save PatrickKing/fbaed82d7e548f1aeb57 to your computer and use it in GitHub Desktop.
Dance the Tankgo (RTanque Tank)
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
class GameOver < RTanque::Bot::Brain | |
NAME = 'DanceTheTankgo' | |
include RTanque::Bot::BrainHelper | |
require 'pry' | |
def tick! | |
## main logic goes here | |
# use self.sensors to detect things | |
# See http://rubydoc.info/github/awilliams/RTanque/master/RTanque/Bot/Sensors | |
# use self.command to control tank | |
# See http://rubydoc.info/github/awilliams/RTanque/master/RTanque/Bot/Command | |
# self.arena contains the dimensions of the arena | |
# See http://rubydoc.info/github/awilliams/RTanque/master/frames/RTanque/Arena | |
# degree ||= 0 | |
# # command.radar_heading = RTanque::Heading.new(degree) | |
# command.radar_heading = RTanque::Heading.new(degree / 360 * (2 * Math::PI)) | |
# puts " Radar Heading: #{sensors.radar_heading.inspect} #{ degree}" | |
# degree += 1 | |
# degree = 0 if degree >= 360 | |
@once ||= false; | |
unless @once | |
@once = true | |
@spinning = true | |
@nw_point = RTanque::Point.new 10, arena.height - 10 | |
@ne_point = RTanque::Point.new arena.width - 10, arena.height - 10 | |
@se_point = RTanque::Point.new arena.width - 10, 10 | |
@sw_point = RTanque::Point.new 10, 10 | |
@destination = @nw_point | |
end | |
if @spinning | |
command.radar_heading = sensors.radar_heading + RTanque::Heading::ONE_DEGREE * 5 | |
# command.radar_heading = sensors.turret_heading + RTanque::Heading::ONE_DEGREE * 5 | |
# command.turret_heading = sensors.turret_heading + RTanque::Heading::ONE_DEGREE * 5 | |
# puts 'am I @spinning?', @spinning | |
end | |
if sensors.radar.any? | |
@spinning = false | |
if (sensors.turret_heading.to_degrees - sensors.radar.first.heading.to_degrees).abs < 4 | |
command.fire 1 | |
end | |
command.turret_heading = sensors.radar.first.heading | |
end | |
# sensors.radar.each do |reflection| | |
# # puts " #{reflection.name} #{reflection.heading.inspect} #{reflection.distance}" | |
# # binding.pry | |
# end | |
if sensors.radar.count == 0 | |
@spinning = true | |
end | |
command.heading = RTanque::Heading.new_between_points( | |
sensors.position, | |
@destination | |
) | |
command.speed = MAX_BOT_SPEED | |
case @destination | |
when @nw_point | |
@destination = @ne_point if @nw_point == sensors.position | |
when @ne_point | |
@destination = @se_point if @ne_point == sensors.position | |
when @se_point | |
@destination = @sw_point if @se_point == sensors.position | |
when @sw_point | |
@destination = @nw_point if @sw_point == sensors.position | |
end | |
at_tick_interval(10) do | |
# puts "Tick ##{sensors.ticks}!" | |
# puts " Gun Energy: #{sensors.gun_energy}" | |
# puts " Health: #{sensors.health}" | |
# puts " Position: (#{sensors.position.x}, #{sensors.position.y})" | |
# puts sensors.position.on_wall? ? " On Wall" : " Not on wall" | |
# puts " Speed: #{sensors.speed}" | |
# puts " Heading: #{sensors.heading.inspect}" | |
# puts " Turret Heading: #{sensors.turret_heading.inspect}" | |
# puts " Radar Heading: #{sensors.radar_heading.inspect}" | |
# puts " Radar Reflections (#{sensors.radar.count}):" | |
end | |
# # head right | |
# command.heading = RTanque::Heading.new(RTanque::Heading::EAST) | |
# # full speed ahead | |
# command.speed = MAX_BOT_SPEED | |
# # while looking behind us | |
# command.radar_heading = RTanque::Heading.new(RTanque::Heading::WEST) | |
# # and aiming down | |
# command.turret_heading = RTanque::Heading.new(RTanque::Heading::SOUTH) | |
# # and firing some slow & rapid shells | |
# command.fire(MIN_FIRE_POWER) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment