Created
August 2, 2013 20:19
-
-
Save tarolandia/6143117 to your computer and use it in GitHub Desktop.
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 | |
@health = 20 | |
@bottom = false | |
@pivot = false | |
@last_mode = nil | |
@last_move = nil | |
@mode = :walk | |
@move = :backward | |
@fullrecover = false | |
def play_turn(warrior) | |
if !@bottom | |
@bottom = @last_move == :backward && warrior.feel(:backward).wall? | |
end | |
@fullrecover = false if warrior.health == 20 | |
@mode, @move = decide(warrior) | |
case @mode | |
when :rescue | |
warrior.rescue!(@move) | |
when :attack | |
warrior.attack!(@move) | |
when :heal | |
warrior.rest! | |
when :pivot | |
warrior.pivot! | |
else | |
warrior.walk!(@move) | |
end | |
check_situation(warrior) | |
end | |
private | |
def check_situation(warrior) | |
@last_move = @move | |
@last_mode = @mode | |
@health = warrior.health | |
end | |
def under_attack?(warrior) | |
@health > warrior.health | |
end | |
def can_fight?(warrior) | |
warrior.health > 10 | |
end | |
def decide(warrior) | |
safe_move = false | |
if !@bottom | |
@move = :backward | |
else | |
if under_attack?(warrior) && !can_fight?(warrior) | |
@move = :backward | |
safe_move = true | |
else | |
@move = :forward | |
end | |
end | |
if safe_move | |
@mode = :walk | |
@fullrecover = true | |
else | |
@mode = :attack if warrior.feel(@move).enemy? | |
@mode = :rescue if warrior.feel(@move).captive? | |
@mode = :walk if warrior.feel(@move).empty? | |
@mode = :pivot if !@bottom | |
@mode = :heal if @fullrecover | |
end | |
return @mode, @move | |
end | |
end |
Author
tarolandia
commented
Aug 3, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment