Created
May 6, 2014 23:44
-
-
Save kevinnio/be4e2b2ec6d1f8a9968b to your computer and use it in GitHub Desktop.
Código del nivel 9, modo Intermediate
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
class Player | |
def play_turn(warrior) | |
@units = warrior.listen | |
@enemies = @units.select { |unit| unit.enemy? } | |
@captives = @units.select { |unit| unit.captive? } | |
@hurry_captives = @captives.select { |captive| captive.ticking? } | |
[@hurry_captives, @enemies, @captives].each do |units| | |
if not units.empty? | |
act warrior, warrior.direction_of(units.first) | |
break | |
end | |
end | |
act warrior, warrior.direction_of_stairs if @units.empty? | |
end | |
def enemies_around(warrior, direction) | |
er = [] | |
[:backward, :left, :right, :forward] .each do |d| | |
space = warrior.feel(d) | |
er.push space if space.enemy? and d != direction | |
end | |
return er | |
end | |
def act(w, d) | |
er = enemies_around(w, d) | |
if not er.empty? | |
er.each do |e| | |
if w.direction_of(e) != d | |
w.bind! w.direction_of(e) | |
break | |
end | |
end | |
elsif w.feel(d).empty? | |
if er.empty? and (w.health < 10 or | |
(w.health < 20 and @hurry_captives.empty? and not @units.empty?)) | |
w.rest! | |
else | |
w.walk! d | |
end | |
elsif w.feel(d).enemy? | |
look = w.look.select { |s| s.enemy?} | |
captive_ahead = w.look.select {|s| s.captive?} | |
if look.size >= 2 and captive_ahead.empty? | |
w.detonate! d | |
else | |
w.attack! d | |
end | |
elsif w.feel(d).captive? | |
w.rescue! d | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment