-
-
Save rab/4122427 to your computer and use it in GitHub Desktop.
BaselineBot
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
require 'rrobots' | |
class RobGreg | |
include Robot | |
attr_reader :events | |
def near_a_wall? | |
x <= size || y <= size || x >= battlefield_width - size || y >= battlefield_height - size | |
end | |
def toward_center | |
delta_x = battlefield_width.to_f/2 - x | |
delta_y = battlefield_height.to_f/2 - y | |
desired_heading = delta_x.zero? ? (delta_y > 0 ? 90 : 270) : Math.atan(delta_y / delta_x) * 180.0 / Math::PI | |
delta_h = desired_heading - heading | |
delta_h = 360 - delta_h if delta_h > 180 | |
delta_h | |
end | |
def evade | |
accelerate(1) | |
if near_a_wall? | |
turn toward_center | |
else | |
turn rand(21)-10 | |
end | |
end | |
def tick(new_events) | |
@events = new_events | |
if time == 0 | |
@turn = 30 | |
@last_scanned = 0 | |
@enemy_heading_bounds = nil | |
end | |
gh = gun_heat | |
say "H=%.3f"%gh | |
puts events.inspect unless events.empty? | |
@last_hit = time unless events['got_hit'].empty? | |
evade | |
if events['robot_scanned'].empty? | |
if (time - @last_scanned) > 5 | |
@turn = 30 | |
@enemy_heading_bounds = nil | |
elsif @enemy_heading_bounds | |
@enemy_heading_bounds = [ radar_heading, radar_heading + @turn ] | |
end | |
turn_gun @turn | |
else | |
bullet = case events['robot_scanned'][0][0] | |
when 0...300 | |
3 | |
when 300...400 | |
2 | |
when 400...500 | |
1 | |
when 500...750 | |
0.5 | |
else | |
0.4 | |
end | |
fire bullet if gh.zero? && (@last_scanned - time) < 2 | |
@last_scanned = time | |
@enemy_heading_bounds = [ radar_heading - @turn, radar_heading ] | |
@turn = (- @turn / 2).to_i | |
@turn *= 3 if @turn <= 1 | |
end | |
end | |
end |
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
require 'rrobots' | |
class Robot3 | |
include Robot | |
def tick events | |
@rapid_fire = 0 if @rapid_fire.nil? | |
@last_seen = 0 if @last_seen.nil? | |
@turn_speed = 3 if @turn_speed.nil? | |
if time - @last_seen > 200 | |
@turn_speed *= -1 | |
@last_seen = time | |
end | |
turn @turn_speed | |
if( @rapid_fire > 0 ) | |
fire 0.84 | |
turn_gun -(@turn_speed / @turn_speed) *2 | |
@rapid_fire = @rapid_fire - 1 | |
else | |
turn_gun @turn_speed * 1.25 | |
end | |
if( !events['robot_scanned'].empty? ) | |
@turn_speed *= -1 | |
@last_seen = time | |
@rapid_fire = 20 | |
end | |
@last_hit = time unless events['got_hit'].empty? | |
if @last_hit && time - @last_hit < 20 | |
accelerate(-1) | |
else | |
accelerate 1 | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment