Last active
August 29, 2015 14:01
-
-
Save atharrison/467d6ce6a681daf841a6 to your computer and use it in GitHub Desktop.
Revisions
-
atharrison revised this gist
May 6, 2014 . 1 changed file with 7 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -10,6 +10,10 @@ class AthBot1 < RTanque::Bot::Brain @rng ||= Random.new end @previous_speed = MAX_BOT_SPEED def tick! ## main logic goes here if (target = self.nearest_target) @@ -36,11 +40,12 @@ class AthBot1 < RTanque::Bot::Brain end def change_speed command.speed = [(@previous_speed || MAX_BOT_SPEED) + rng.rand(2) ? new_speed : -new_speed, MAX_BOT_SPEED / 0.6 ].max @previous_speed = command.speed end def new_speed rng.rand(30) end def move_randomly -
atharrison revised this gist
May 6, 2014 . 1 changed file with 23 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -4,6 +4,7 @@ class AthBot1 < RTanque::Bot::Brain TURRET_FIRE_RANGE = RTanque::Heading::ONE_DEGREE * 1.0 SWITCH_CORNER_TICK_RANGE = (600..1000) POWER_FACTOR = 1.0 def rng @rng ||= Random.new @@ -17,7 +18,9 @@ class AthBot1 < RTanque::Bot::Brain self.detect_targets end self.change_speed self.move # use self.sensors to detect things # See http://rubydoc.info/github/awilliams/RTanque/master/RTanque/Bot/Sensors @@ -32,18 +35,37 @@ class AthBot1 < RTanque::Bot::Brain move_randomly end def change_speed rng.rand(2) ? new_speed : -new_speed end def new_speed rng.rand(10) end def move_randomly command.heading = self.sensors.position.heading(RTanque::Point.new(random_width, random_height, self.arena)) command.speed = MAX_BOT_SPEED end def fire_randomly #self.command.turret_heading = random_heading self.command.fire(MAX_FIRE_POWER / POWER_FACTOR) end def random_width rng.rand(self.arena.width) end def random_height rng.rand(self.arena.height) end def random_heading rng.rand(Math::PI * 2 * 1000).to_f/1000 end def nearest_target self.sensors.radar.min { |a,b| a.distance <=> b.distance } end @@ -57,7 +79,7 @@ class AthBot1 < RTanque::Bot::Brain 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/POWER_FACTOR) end end -
atharrison created this gist
May 6, 2014 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,65 @@ class AthBot1 < RTanque::Bot::Brain NAME = 'Andrew' include RTanque::Bot::BrainHelper TURRET_FIRE_RANGE = RTanque::Heading::ONE_DEGREE * 1.0 SWITCH_CORNER_TICK_RANGE = (600..1000) def rng @rng ||= Random.new end def tick! ## main logic goes here if (target = self.nearest_target) self.fire_upon(target) else self.detect_targets end self.move # 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 end def move move_randomly end def move_randomly command.heading = self.sensors.position.heading(RTanque::Point.new(random_width, random_height, self.arena)) command.speed = MAX_BOT_SPEED end def random_width rng.rand(self.arena.width) end def random_height rng.rand(self.arena.height) end def nearest_target self.sensors.radar.min { |a,b| a.distance <=> b.distance } end def detect_targets self.command.radar_heading = self.sensors.radar_heading + MAX_RADAR_ROTATION self.command.turret_heading = self.sensors.heading + RTanque::Heading::HALF_ANGLE end def fire_upon(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 end