Last active
December 20, 2015 08:59
-
-
Save quimcalpe/6104637 to your computer and use it in GitHub Desktop.
RubyWarrior beginner epic mode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## | |
# No custom level tricks | |
# | |
# Total Score: 544 + 107 = 651 | |
# Your average grade for this tower is: S | |
# | |
# Level 1: S | |
# Level 2: S | |
# Level 3: S | |
# Level 4: S | |
# Level 5: S | |
# Level 6: S | |
# Level 7: S | |
# Level 8: S | |
# Level 9: S | |
class Player | |
def rescue_captives(warrior) | |
[:forward, :backward].each do |dir| | |
if warrior.feel(dir).captive? | |
warrior.rescue!(dir) | |
return true | |
end | |
end | |
return false | |
end | |
def under_ranged_attack(warrior) | |
if warrior.look(:backward)[1..2].to_s.match(/Archer|Wizard/) | |
warrior.walk! | |
return true | |
end | |
return false | |
end | |
def attack(warrior) | |
if warrior.feel.enemy? | |
warrior.attack! | |
return true | |
elsif warrior.feel(:backward).enemy? | |
warrior.pivot! | |
return true | |
end | |
[:forward, :backward].each do |dir| | |
warrior.look(dir).each do |cell| | |
return false if cell.captive? | |
if cell.enemy? | |
if dir == :backward | |
warrior.pivot! | |
elsif cell.to_s == "Sludge" && cell.unit.health<10 | |
return false | |
elsif cell.to_s == "Thick Sludge" && cell.unit.health<16 | |
return false | |
else | |
warrior.shoot!(dir) | |
end | |
return true | |
end | |
end | |
end | |
return false | |
end | |
def rest(warrior) | |
if warrior.health < 8 && warrior.look.to_s.match(/Archer|Wizard|Sludge/) | |
warrior.rest! | |
return true | |
end | |
return false | |
end | |
def walk(warrior) | |
[:forward, :backward].each do |dir| | |
if warrior.look(dir).to_s.match(/Captive/) | |
warrior.walk!(dir) | |
return true | |
end | |
end | |
if warrior.look.to_s.match(/wall/) && !warrior.feel.stairs? && !warrior.look[1].stairs? | |
warrior.pivot! | |
return true | |
elsif warrior.feel.empty? | |
warrior.walk! | |
return true | |
elsif warrior.feel.stairs? | |
warrior.walk! | |
return true | |
end | |
end | |
def play_turn(warrior) | |
if rescue_captives(warrior) | |
elsif under_ranged_attack(warrior) | |
elsif attack(warrior) | |
elsif rest(warrior) | |
else | |
walk(warrior) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment