-
Notifications
You must be signed in to change notification settings - Fork 0
/
level7.rb
42 lines (37 loc) · 915 Bytes
/
level7.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
class Player
def initialize()
@health = 0
@direction = :forward
end
def play_turn(warrior)
if warrior.feel.wall?
warrior.pivot!
elsif (warrior.feel(@direction).empty?)
if (should_rest? warrior)
warrior.rest!
elsif (should_flee? warrior)
warrior.walk!(:backward)
else
warrior.walk!(@direction)
end
else
warrior.attack!(@direction)
end
@health = warrior.health
end
def should_flee?(warrior)
flee_health = 7
poor_health = warrior.health < flee_health
under_attack = under_attack? warrior
return under_attack && poor_health
end
def should_rest?(warrior)
min_health = 10
good_health = warrior.health > min_health
under_attack = under_attack? warrior
return !(good_health || under_attack)
end
def under_attack?(warrior)
return warrior.health < @health
end
end