-
Notifications
You must be signed in to change notification settings - Fork 0
/
RubyWarrior_8.rb
93 lines (73 loc) · 1.46 KB
/
RubyWarrior_8.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
class Player
def canFight(warrior)
if warrior.health < 15
return false
end
return true
end
def danger(warrior)
if warrior.health < 12
return true
end
return false
end
def checkCondition(warrior)
if warrior.feel.wall?
return "pivot"
end
if (warrior.feel:backward).captive?
return "rescueBack"
end
if warrior.feel.captive?
return "rescue"
end
if warrior.feel.enemy?
return "attack"
end
warrior.look.each do |space|
if space.captive?
return "walk"
end
if space.enemy?
return "shoot"
end
end
if isRangeAttack(warrior)
if canFight(warrior)
return "walk"
end
return "escape"
end
if warrior.health < 20
return "rest"
end
return "walk"
end
def isRangeAttack(warrior)
if @health != nil && @health > warrior.health
return true
end
return false
end
def play_turn(warrior)
state = checkCondition(warrior)
case state
when "shoot"
warrior.shoot!
when "rescue"
warrior.rescue!
when "pivot"
warrior.pivot!
when "rest"
warrior.rest!
when "escape"
warrior.walk!:backward
when "attack"
warrior.attack!
when "walk"
warrior.walk!
end
@health = warrior.health
# cool code goes here
end
end