-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrubywarrior.rb
122 lines (121 loc) · 3.25 KB
/
rubywarrior.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
class Player
def play_turn(warrior)
# cool code goes here
@minimumHealth = 10
if @warriorNeedsRest != nil and @warriorNeedsRest == true then
if warrior.health < @previousHealth then
if @walkingForward == nil then
warrior.walk!
else
warrior.walk!(:backward)
end
elsif warrior.health >= 20 then
@warriorNeedsRest = false
if @walkingForward == nil then
warrior.walk!
else
warrior.walk!(:backward)
end
else
warrior.rest!
end
elsif @walkingForward == nil or @walkingForward == false then
@enemiesBehind = false;
warrior.look(:backward).each { |spot|
if spot.captive? then
#do nothing
break
elsif spot.enemy? then
@enemiesBehind = true
break
end
}
if @enemiesAhead == true then
warrior.shoot!(:backward)
elsif warrior.feel(:backward).captive? then
warrior.rescue!(:backward)
elsif warrior.feel(:backward).enemy? then
if warrior.health > 5 then
warrior.attack!(:backward)
else
warrior.walk!
@warriorNeedsRest = true
end
elsif warrior.feel(:backward).empty? then
#are we taking damage?
if @previousHealth == nil then
warrior.walk!(:backward)
elsif warrior.health < @previousHealth then
#do we have enough hp?
if warrior.health < @minimumHealth then
#go back
warrior.walk!
@warriorNeedsRest = true
else
#charge!!!
warrior.walk!(:backward)
end
else
if warrior.health < @minimumHealth then
#go back
warrior.walk!
@warriorNeedsRest = true
else
warrior.walk!(:backward)
end
end
elsif warrior.feel(:backward).wall? then
warrior.walk!
@walkingForward = 'yes'
end
else
@enemiesAhead = false
warrior.look.each do |spot|
if spot.captive? then
#do nothing
break
elsif spot.enemy? then
@enemiesAhead = true
break
end
end
if @enemiesAhead == true then
warrior.shoot!
elsif warrior.feel.captive? then
warrior.rescue!
elsif warrior.feel.enemy? then
if warrior.health > 3 then
warrior.attack!
else
warrior.walk!(:backward)
@warriorNeedsRest = true
end
elsif warrior.feel.empty? then
#are we taking damage?
if warrior.health < @previousHealth then
#do we have enough hp?
if warrior.health < @minimumHealth then
#go back
warrior.walk!(:backward)
@warriorNeedsRest = true
else
#charge!!!
warrior.walk!
end
else
if warrior.health < @minimumHealth then
#go back
warrior.walk!(:backward)
@warriorNeedsRest = true
else
warrior.walk!
end
end
end
end
if warrior.health < 5 then
@warriorNeedsRest = true
end
@previousHealth = warrior.health
end
end