Skip to content

Commit

Permalink
Merge pull request reedlaw#26 from davidk01/master
Browse files Browse the repository at this point in the history
I added a variation of eric.rb
  • Loading branch information
Reed G. Law committed Apr 12, 2012
2 parents cb468b0 + c78481b commit ba47259
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions players/davidk.rb
@@ -0,0 +1,34 @@
module DavidK
def to_s
"david karapetyan"
end

def move
opponent = killable_opponent
if stats[:health] >= 50 && !opponent.nil?
[:attack, opponent]
else
[:rest]
end
end

private

def killable_opponent
all_opponents = Game.world[:players].select{|p| p != self}
n = 1
possible_opponents = all_opponents.select {|o| can_kill_in_n_hits?(o, n)}.sort {|a,b| b.stats[:health] <=> a.stats[:health]}
#while possible_opponents.empty?
# n += 2
# possible_opponents = all_opponents.select {|o| can_kill_in_n_hits?(o, n)}.sort {|a,b| b.stats[:health] <=> a.stats[:health]}
#end
possible_opponents.first
end

def can_kill_in_n_hits?(player, n)
enemy_stats = player.stats
points = stats[:strength] - (enemy_stats[:defense] / 2)
enemy_stats[:health] <= n * points
end

end

0 comments on commit ba47259

Please sign in to comment.