Skip to content

Commit

Permalink
Merge pull request reedlaw#18 from jimworm/master
Browse files Browse the repository at this point in the history
Just for fun, not a job application
  • Loading branch information
Reed G. Law committed Apr 12, 2012
2 parents 085f657 + 578321d commit 0662e25
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions players/jimworm.rb
@@ -0,0 +1,36 @@
module Jimworm # who's just doing this for fun
def move
if win_assured? or at_risk?
[:rest]
elsif killable?(opponents.first)
[:attack, opponents.first]
else
[:attack, (rat || opponents.last)]
end
end

def to_s
"jimworm"
end

protected
def win_assured?
opponents.empty? or (opponents.count < 2 and stats[:experience] >= opponents.sort_by{|p|p.stats[:experience]}.last.stats[:experience])
end

def at_risk?
stats[:health] == 100 ? false : stats[:health] <= opponents.last.stats[:health]
end

def opponents
Game.world[:players].select{|p| p.to_s != 'rat' and p != self}.sort_by{|p|p.stats[:health]}
end

def killable?(player)
stats[:strength] >= player.stats[:health] + (player.stats[:defense] / 2)
end

def rat
Game.world[:players].select{|p| p.to_s == 'rat'}.first
end
end

0 comments on commit 0662e25

Please sign in to comment.