Skip to content

Commit

Permalink
Merge pull request reedlaw#24 from crnixon/master
Browse files Browse the repository at this point in the history
Count Manchego enters the ring
  • Loading branch information
Reed G. Law committed Apr 12, 2012
2 parents e0800b9 + 5494c47 commit f68cc36
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions players/manchego.rb
@@ -0,0 +1,51 @@
module Manchego
def to_s
"Count Manchego"
end

# I AM A VAMPIRE
def alive
false
end

def move
action = if killable_enemies.size > 0
[:attack, killable_enemies.first]
elsif stats[:health] < 90
[:rest]
elsif self == apex_predator
[:attack, weakest_prey]
else
[:attack, apex_predator]
end
return action
end

def players
Game.world[:players]
end

def enemies
players.select { |p| p != self }
end

def apex_predator
players.sort_by { |e| -e.stats[:experience] }.first
end

def weakest_prey
enemies.sort_by { |e| e.stats[:health] }.first
end

def killable_enemies
enemies.select { |enemy| killable?(enemy) }.sort_by { |e| -e.stats[:experience] }
end

def killable?(player)
damage_vs(player) >= player.stats[:health]
end

def damage_vs(player)
stats[:strength] - (player.stats[:defense] / 2)
end
end

0 comments on commit f68cc36

Please sign in to comment.