Skip to content
This repository has been archived by the owner on Jul 4, 2023. It is now read-only.

Commit

Permalink
Merge pull request #5 from sstarr/master
Browse files Browse the repository at this point in the history
Would anyone like any toast?
  • Loading branch information
andrew committed Jan 15, 2015
2 parents db888b7 + ead9502 commit 4839231
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions bots/talkie_toaster.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
class TalkieToaster < RTanque::Bot::Brain
NAME = 'Talkie Toaster'
include RTanque::Bot::BrainHelper

def tick!
if (!defined?(@direction))
@direction = 0
end

onWall = false
if (sensors.position.on_top_wall?)
command.heading = RTanque::Heading::SOUTH
onWall = true
elsif (sensors.position.on_bottom_wall?)
command.heading = RTanque::Heading::NORTH
onWall = true
elsif (sensors.position.on_left_wall?)
command.heading = RTanque::Heading::EAST
onWall = true
elsif (sensors.position.on_right_wall?)
command.heading = RTanque::Heading::WEST
onWall = true
end

if (onWall)
if (sensors.heading.delta(command.heading) > 0)
@direction = 1
else
@direction = -1
end
else
if (Random.rand(80) < 1)
@direction = 0 - @direction
end

command.heading = sensors.heading + @direction * RTanque::Heading::ONE_DEGREE * 5.0
end
command.speed = RTanque::Bot::MAX_SPEED

reflections = sensors.radar
reflections = reflections.reject { |r| r.name == NAME }
nearest = reflections.sort_by { |r| r.distance }.first

if nearest
command.radar_heading = nearest.heading
command.turret_heading = nearest.heading
command.fire(RTanque::Bot::MAX_FIRE_POWER)
end
end
end

0 comments on commit 4839231

Please sign in to comment.