Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #91 from limekin/master

Added player limekin.rb.
  • Loading branch information...
commit e1fa8be59bf42427ac864141b7da1a7c02e3f9dc 2 parents 3753187 + 5bdcc81
@reedlaw authored
Showing with 73 additions and 0 deletions.
  1. +73 −0 players/limekin.rb
View
73 players/limekin.rb
@@ -0,0 +1,73 @@
+module OwningTimeLOL
+
+ def to_s
+ "limekin"
+ end
+
+ def move
+
+ @players = sort_by_health( get_alive_players )
+ @monsters = sort_by_health( get_alive_monsters )
+
+ if self_last_hit?
+ return [:rest]
+ else
+ opponent = second_killable_player || second_killable_monster || strongest_player || strongest_monster
+ [:attack, opponent]
+ end
+ end
+
+
+ def get_alive_players
+ (Game.world[:players] || []).select do |player|
+ player.alive? and player != self
+ end
+ end
+
+ def get_alive_monsters
+ (Game.world[:monsters] || []).select do |monster|
+ monster.alive?
+ end
+ end
+
+ def sort_by_health(opponents)
+ opponents.sort_by do |opponent|
+ fs( opponent, :max_health )
+ end
+ end
+
+ def self_last_hit?
+ (@players + @monsters).any? do |opponent|
+ fs(opponent, :strength) - fs(self,:defense)/2 == @health
+ end
+ end
+
+ def second_killable_player
+ killable_players = @players.select do |player|
+ fs(player, :health) == fs(self,:strength) - fs(player, :defense)/2
+ end || []
+ killable_players[1]
+ end
+
+ def second_killable_monster
+ killable_monster = @monsters.select do |monster|
+ fs(monster, :health) == fs(self, :strength) - fs(monster, :defense)/2
+ end || []
+ killable_monster[1]
+
+ end
+
+ def strongest_player
+ @players[0]
+ end
+
+ def strongest_monster
+ @monsters[0]
+ end
+
+ def fs(opponent, attr)
+ opponent.stats[attr]
+ end
+
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.