forked from reedlaw/ruby-mmo
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
david karapetyan
committed
Apr 12, 2012
1 parent
b8a0e44
commit f38b527
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
module DavidK | ||
def to_s | ||
"david karapetyan" | ||
end | ||
|
||
def move | ||
if stats[:health] >= 90 | ||
[:attack, killable_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) } | ||
while possible_opponents.empty? | ||
n += 2 | ||
possible_opponents = all_opponents.select {|o| can_kill_in_n_hits?(o, n) } | ||
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 |