Last active
August 1, 2017 13:43
-
-
Save lirenyeo/4de93100b03706c4ade106abd0c8e43b to your computer and use it in GitHub Desktop.
my rtanque bot
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
class Liren < RTanque::Bot::Brain | |
NAME = 'Liren' | |
include RTanque::Bot::BrainHelper | |
def tick! | |
command.speed = RTanque::Bot::MAX_SPEED | |
command.heading = RTanque::Heading.new(RTanque::Heading::EAST) | |
command.radar_heading = RTanque::Heading::ONE_DEGREE * Random.rand(360) | |
command.turret_heading = RTanque::Heading::ONE_DEGREE * Random.rand(360) | |
command.fire(RTanque::Bot::MIN_FIRE_POWER) | |
if (!defined?(@direction)) | |
@direction = 0 | |
@previousTargetX = 0 | |
@previousTargetY = 0 | |
end | |
onWall = false | |
if (sensors.position.on_top_wall?) | |
command.heading = RTanque::Heading::SOUTH | |
command.turret_heading = RTanque::Heading::NORTH | |
onWall = true | |
elsif (sensors.position.on_bottom_wall?) | |
command.heading = RTanque::Heading::NORTH | |
command.turret_heading = RTanque::Heading::SOUTH | |
onWall = true | |
elsif (sensors.position.on_left_wall?) | |
command.heading = RTanque::Heading::EAST | |
command.turret_heading = RTanque::Heading::WEST | |
onWall = true | |
elsif (sensors.position.on_right_wall?) | |
command.heading = RTanque::Heading::WEST | |
command.turret_heading = RTanque::Heading::EAST | |
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 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment