Skip to content

Commit ca4464b

Browse files
Nick BreenNick Breen
authored andcommitted
Updated problems with NickDuck edge turning. Also updated tournment.rb to work on ubuntu and fixed printout bug on rrobots.rb
1 parent 555034a commit ca4464b

File tree

3 files changed

+78
-71
lines changed

3 files changed

+78
-71
lines changed

NickDuck.rb

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
# - do evasive action when get hit (health changes between turns)
66
class NickDuck
77
include Robot
8-
def detectEnemy
8+
def initialize
9+
# TODO: add all variables here
10+
end
11+
def detectEnemy
912
unless events['robot_scanned'].empty?
1013
@seen_enemy_recently = true
1114
@last_time_enemy_seen = time
@@ -25,20 +28,19 @@ def turn_clockwise
2528
end
2629
def setRobotTurnDirection(min, max)
2730
@midpoint = min+90
31+
@local_heading = @heading
2832
if (min == 270) && (max == 90) && (@heading >= 270 || @heading <= 90)
29-
if @local_heading <= 90
33+
if @heading <= 90
3034
@local_heading = @heading+360
3135
end
3236
max = max+360
3337
@midpoint = 360
3438
else
35-
@local_heading = @heading
39+
#%361 to help with the edge case of escaping y max turning counter
3640
@midpoint = (@midpoint)%361
3741
end
38-
say min.to_s.concat(' ').concat(@local_heading.to_s).concat(' ').concat(max.to_s)
3942
if (min <= @local_heading) && (@local_heading <= max)
40-
say (@local_heading.to_s).concat(' ').concat(((min+90)%360).to_s)
41-
#%361 to help with the edge case of escaping y max turning counter
43+
@edge_detection_activated = true
4244
if @local_heading >= @midpoint
4345
turn_counter
4446
else
@@ -47,23 +49,28 @@ def setRobotTurnDirection(min, max)
4749
end
4850
end
4951
def setRobotTurn
50-
#say @x.to_s.concat(' ').concat(@y.to_s)
51-
#say @size
52+
@edge_detection_activated = false
5253
@edge_detection_constant = 70
5354
if (@x-@size-@edge_detection_constant) <= 0
5455
setRobotTurnDirection(90, 270)
55-
elsif (@x+@size+@edge_detection_constant) >= @battlefield_width
56+
end
57+
if (@x+@size+@edge_detection_constant) >= @battlefield_width
5658
setRobotTurnDirection(270, 90)
57-
elsif (@y-@size-@edge_detection_constant) <= 0
59+
end
60+
if (@y-@size-@edge_detection_constant) <= 0
5861
setRobotTurnDirection(0, 180)
59-
elsif (@y+@size+@edge_detection_constant) >= @battlefield_height
62+
end
63+
if (@y+@size+@edge_detection_constant) >= @battlefield_height
6064
setRobotTurnDirection(180, 360)
61-
elsif !@seen_enemy_recently
62-
@turn_variable = rand(0..5)
63-
if @turn_variable == 0
64-
turn 5
65-
#elsif @turn_variable > 1
66-
turn 30
65+
end
66+
if !@edge_detection_activated
67+
if !@seen_enemy_recently
68+
@turn_variable = rand(0..8)
69+
if @turn_variable == 0
70+
turn 1
71+
elsif @turn_variable > 1
72+
# turn -10
73+
end
6774
end
6875
end
6976
end

rrobots.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def print_outcome(battlefield)
219219
puts " #{robot.name}:"
220220
puts " shots_fired: #{'%.1f' % robot.shots_fired}"
221221
puts " shots_hit: #{'%.1f' % robot.shots_hit}"
222-
puts " accuracy: #{'%.1f' % (100*robot.shots_hit/robot.shots_fired)} %"
222+
puts " accuracy: #{'%.1f' % (100*robot.shots_hit/[robot.shots_fired,1].max)} %"
223223
puts " damage_given: #{'%.1f' % robot.damage_given}"
224224
puts " damage_taken: #{'%.1f' % (100 - robot.energy)}"
225225
puts " kills: #{robot.kills}"

0 commit comments

Comments
 (0)