Skip to content

Instantly share code, notes, and snippets.

@acrookston
Created July 30, 2013 19:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acrookston/6115938 to your computer and use it in GitHub Desktop.
Save acrookston/6115938 to your computer and use it in GitHub Desktop.
class Player
def od(dir)
return dir == :backward ? :forward : :backward
end
def play_turn(warrior)
w = warrior
@direction = :forward if @direction == nil
@back = 0 if @back == nil
@rest = false if @rest == nil
if w.feel(@direction).wall?
@direction = od(@direction)
end
# raise [w.feel(:backward).wall?, @direction].inspect
if w.health < 9 || @rest
@rest = true
if w.feel(od(@direction)).empty? && @back < 3
@back += 1
w.walk! od(@direction)
else
w.rest!
if w.health >= 18
@back = 0
@rest = false
end
end
elsif shoot? w, od(@direction)
w.shoot! od(@direction)
elsif shoot? w, @direction
w.shoot! @direction
elsif w.feel(@direction).empty?
w.walk!(@direction)
elsif w.feel(@direction).captive?
w.rescue!(@direction)
elsif w.feel(@direction).enemy?
w.attack!(@direction)
@rest = true
end
end
def shoot?(w, dir)
w.look(dir).each do |s|
if s.captive?
return false
elsif s.enemy?
return true
end
end
return false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment