This repository has been archived by the owner on Jul 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:bathruby/battlebots
- Loading branch information
Showing
2 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
class Chaos2 < RTanque::Bot::Brain | ||
NAME = "Chaos 2" | ||
include RTanque::Bot::BrainHelper | ||
|
||
TURRET_FIRE_RANGE = RTanque::Heading::ONE_DEGREE * 5.0 | ||
|
||
def tick! | ||
p | ||
command.fire_power = 3 | ||
command.speed = 10 | ||
command.heading = sensors.heading - (RTanque::Heading::ONE_DEGREE * (rand*40-10)) | ||
command.turret_heading = sensors.turret_heading - (RTanque::Heading::ONE_DEGREE * (rand*40-10)) | ||
|
||
# turn turrent to face other bot | ||
|
||
@desired_heading ||= nil | ||
|
||
if (lock = self.get_radar_lock) | ||
self.destroy_lock(lock) | ||
@desired_heading = nil | ||
else | ||
Chaos2::NAME.replace "#{NAME.gsub(/\(.+?\)/, '')}" | ||
seek_lock | ||
end | ||
end | ||
|
||
def destroy_lock(reflection) | ||
# head and shoot towards the target | ||
command.heading = reflection.heading | ||
command.radar_heading = reflection.heading | ||
command.turret_heading = reflection.heading | ||
|
||
# change speed based on how close to the target | ||
command.speed = if reflection.distance > 100 | ||
MAX_BOT_SPEED | ||
elsif reflection.distance < 50 | ||
-MAX_BOT_SPEED | ||
else | ||
MAX_BOT_SPEED.to_f/reflection.distance | ||
end | ||
|
||
if (reflection.heading.delta(sensors.turret_heading)).abs < TURRET_FIRE_RANGE | ||
command.fire(2) | ||
end | ||
end | ||
|
||
def seek_lock | ||
if sensors.position.on_wall? | ||
@desired_heading = sensors.heading + RTanque::Heading::HALF_ANGLE | ||
command.speed = -MAX_BOT_SPEED | ||
else | ||
command.speed = MAX_BOT_SPEED | ||
end | ||
command.radar_heading = sensors.radar_heading + MAX_RADAR_ROTATION | ||
|
||
if @desired_heading | ||
command.heading = @desired_heading | ||
command.turret_heading = @desired_heading | ||
else | ||
command.heading = sensors.heading - (RTanque::Heading::ONE_DEGREE * (rand*40-10)) | ||
command.turret_heading = sensors.turret_heading - (RTanque::Heading::ONE_DEGREE * (rand*40-10)) | ||
end | ||
end | ||
|
||
def get_radar_lock | ||
@locked_on ||= nil | ||
lock = if @locked_on | ||
Chaos2::NAME.replace "#{NAME.gsub(/\(.+?\)/, '')}(#{@locked_on.gsub(/\(.+?\)/, '')})" | ||
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
class TankSpanker < RTanque::Bot::Brain | ||
NAME = 'TankSpanker' | ||
include RTanque::Bot::BrainHelper | ||
|
||
TURRET_FIRE_RANGE = RTanque::Heading::ONE_DEGREE * 1.5 | ||
|
||
def tick! | ||
self.evade | ||
# make_circles | ||
|
||
if(self.nearest_target) | ||
target = nearest_target | ||
kill(target) | ||
else | ||
scan | ||
make_circles | ||
end | ||
|
||
at_tick_interval(100) do | ||
puts sensors.inspect | ||
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}):" | ||
sensors.radar.each do |reflection| | ||
puts " #{reflection.name} #{reflection.heading.inspect} #{reflection.distance}" | ||
end | ||
end | ||
end | ||
|
||
def evade | ||
command.speed = MAX_BOT_SPEED | ||
command.heading = sensors.heading + 0.02 | ||
end | ||
|
||
def kill(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(MAX_FIRE_POWER) | ||
end | ||
end | ||
|
||
def nearest_target | ||
self.sensors.radar.min { |a,b| a.distance <=> b.distance } | ||
end | ||
|
||
def scan | ||
self.command.radar_heading = self.sensors.radar_heading + MAX_RADAR_ROTATION | ||
end | ||
## main logic goes here | ||
# use self.sensors to detect things | ||
# use self.command to control tank | ||
# self.arena contains the dimensions of the arena | ||
# self.command.radar_heading = self.sensors.radar_heading + MAX_RADAR_ROTATION | ||
# make_circles | ||
# self.command.radar_heading = self.sensors.radar_heading + MAX_RADAR_ROTATION | ||
# command.fire(0.25) | ||
|
||
# if sensors.position.on_wall? | ||
# command.heading = RTanque::Heading.new(RTanque::Heading::WEST) | ||
# end | ||
|
||
|
||
def make_circles | ||
command.speed = -2 # takes a value between -5 to 5 | ||
command.heading = sensors.heading + 0.01 | ||
end | ||
end |