5
5
# - do evasive action when get hit (health changes between turns)
6
6
class NickDuck
7
7
include Robot
8
- def detectEnemy
8
+ def initialize
9
+ # TODO: add all variables here
10
+ end
11
+ def detectEnemy
9
12
unless events [ 'robot_scanned' ] . empty?
10
13
@seen_enemy_recently = true
11
14
@last_time_enemy_seen = time
@@ -25,20 +28,19 @@ def turn_clockwise
25
28
end
26
29
def setRobotTurnDirection ( min , max )
27
30
@midpoint = min +90
31
+ @local_heading = @heading
28
32
if ( min == 270 ) && ( max == 90 ) && ( @heading >= 270 || @heading <= 90 )
29
- if @local_heading <= 90
33
+ if @heading <= 90
30
34
@local_heading = @heading +360
31
35
end
32
36
max = max +360
33
37
@midpoint = 360
34
38
else
35
- @local_heading = @heading
39
+ #%361 to help with the edge case of escaping y max turning counter
36
40
@midpoint = ( @midpoint ) %361
37
41
end
38
- say min . to_s . concat ( ' ' ) . concat ( @local_heading . to_s ) . concat ( ' ' ) . concat ( max . to_s )
39
42
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
42
44
if @local_heading >= @midpoint
43
45
turn_counter
44
46
else
@@ -47,23 +49,28 @@ def setRobotTurnDirection(min, max)
47
49
end
48
50
end
49
51
def setRobotTurn
50
- #say @x.to_s.concat(' ').concat(@y.to_s)
51
- #say @size
52
+ @edge_detection_activated = false
52
53
@edge_detection_constant = 70
53
54
if ( @x -@size -@edge_detection_constant ) <= 0
54
55
setRobotTurnDirection ( 90 , 270 )
55
- elsif ( @x +@size +@edge_detection_constant ) >= @battlefield_width
56
+ end
57
+ if ( @x +@size +@edge_detection_constant ) >= @battlefield_width
56
58
setRobotTurnDirection ( 270 , 90 )
57
- elsif ( @y -@size -@edge_detection_constant ) <= 0
59
+ end
60
+ if ( @y -@size -@edge_detection_constant ) <= 0
58
61
setRobotTurnDirection ( 0 , 180 )
59
- elsif ( @y +@size +@edge_detection_constant ) >= @battlefield_height
62
+ end
63
+ if ( @y +@size +@edge_detection_constant ) >= @battlefield_height
60
64
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
67
74
end
68
75
end
69
76
end
0 commit comments