Skip to content

Commit

Permalink
Added flipback player
Browse files Browse the repository at this point in the history
  • Loading branch information
atimin committed Apr 15, 2012
1 parent 6bd7b44 commit 0efeaf1
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions players/flipback.rb
@@ -0,0 +1,38 @@
module Flipback
FATE = 0.7

def to_s
"flipback"
end

def move
return [ :rest ] if stats[:health] < 60

target = dying_player
if target
[:attack, target]
elsif other_players.count == 1 || rand > FATE || stats[:health] >= 100
[:attack, best_player]
else
[ :rest ]
end
end

private
def other_players
Game.world[:players].select{ |p| p != self }
end

def best_player
other_players.sort{ |i,j| i.stats[:experience] <=> j.stats[:experience] }.last
end

def dying_player
other_players.select{ |p| can_kill?(p) }.first
end

def can_kill?(player)
points = stats[:strength] - (player.stats[:defense] / 2)
player.stats[:health] <= points
end
end

0 comments on commit 0efeaf1

Please sign in to comment.