Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

valentin's player #11

Merged
merged 1 commit into from

2 participants

@valentinzberea

No description provided.

@reedlaw reedlaw merged commit 5405962 into reedlaw:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 11, 2012
  1. @valentinzberea

    valentin player

    valentinzberea authored
This page is out of date. Refresh to see the latest.
Showing with 24 additions and 0 deletions.
  1. +24 −0 players/valentin.rb
View
24 players/valentin.rb
@@ -0,0 +1,24 @@
+module Valentin
+ def to_s
+ "Valentin"
+ end
+ def move
+ max_health = 100
+ points = self.stats[:strength] - self.stats[:defense]/2
+
+ kill = Game.world[:players].select{|p| p!=self && p.stats[:health] <= points && p.alive}.first
+ return [:attack, kill] unless kill.nil?
+
+ opponents = Game.world[:players].select{|p| p!=self && p.alive && p.to_s != 'rat'}
+
+ best_opponent = opponents.max { |a, b| a.stats[:experience] <=> b.stats[:experience] }
+ in_advantage = self.stats[:experience] > best_opponent.stats[:experience]
+
+ if self.stats[:health] <= opponents.count * points && in_advantage
+ return [:rest]
+ end
+
+ weakest_opponent = opponents.min { |a, b| a.stats[:health] <=> b.stats[:health] }
+ return [:attack, weakest_opponent] unless weakest_opponent.nil?
+ end
+end
Something went wrong with that request. Please try again.