Skip to content

Commit

Permalink
Added: Player module named BioCreature. BioCreature is an Endurance c…
Browse files Browse the repository at this point in the history
…haracter.
  • Loading branch information
NathanLapp committed Feb 8, 2014
1 parent b6804ff commit 35c5b33
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 15 deletions.
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2.1.0
29 changes: 14 additions & 15 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,21 @@ GEM
remote: http://rubygems.org/
specs:
columnize (0.3.6)
debugger (1.1.1)
debugger (1.6.5)
columnize (>= 0.3.1)
debugger-linecache (~> 1.1)
debugger-ruby_core_source (~> 1.1)
debugger-linecache (1.1.1)
debugger-ruby_core_source (>= 1.1.1)
debugger-ruby_core_source (1.1.1)
diff-lcs (1.1.3)
rspec (2.9.0)
rspec-core (~> 2.9.0)
rspec-expectations (~> 2.9.0)
rspec-mocks (~> 2.9.0)
rspec-core (2.9.0)
rspec-expectations (2.9.1)
diff-lcs (~> 1.1.3)
rspec-mocks (2.9.0)
debugger-linecache (~> 1.2.0)
debugger-ruby_core_source (~> 1.3.1)
debugger-linecache (1.2.0)
debugger-ruby_core_source (1.3.1)
diff-lcs (1.2.5)
rspec (2.14.1)
rspec-core (~> 2.14.0)
rspec-expectations (~> 2.14.0)
rspec-mocks (~> 2.14.0)
rspec-core (2.14.7)
rspec-expectations (2.14.5)
diff-lcs (>= 1.1.3, < 2.0)
rspec-mocks (2.14.5)

PLATFORMS
ruby
Expand Down
126 changes: 126 additions & 0 deletions players/biocreature.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
module BioCreature

def to_s
"BioCreature"
end

def self.extended(base)
base.instance_variable_set :@round, 0
end

def move
@round += 1

if should_fight?
fight
else
recover
end

end

private

def kill
if @round > 80
leader
else
easy_players = opponents.select{|p| p!=self}.select{|p| easyKill? p}
medium_players = opponents.select{|p| p!=self}.select{|p| killable? p}

if easy_players.count > 0
return easy_players[rand(easy_players.count - 1)]
elsif medium_players.count > 0
return medium_players[rand(medium_players.count - 1)]
end
end

end

# player: the player that you want to know if is killable
def killable? player
opponentDamage = calcDamage(fromPlayer: player, toPlayer: self)
selfDamage = calcDamage(fromPlayer: self, toPlayer: player)

# if the TTK for myself is equal to my opponent then return true
timeToKill(player: self, damage: opponentDamage) == timeToKill(player: player, damage: selfDamage)
# note: if you are wondering why only equals, then look at easyKill
end

# player: the player that you want to know if is an easy kill
def easyKill? player
opponentDamage = calcDamage(fromPlayer: player, toPlayer: self)
selfDamage = calcDamage(fromPlayer: self, toPlayer: player)

# if the TTK for myself is longer than my opponent (not equal) then return true
timeToKill(player: self, damage: opponentDamage) > timeToKill(player: player, damage: selfDamage)
end

# fromPlayer: the player that you want to know the damage for
# toPlayer: the player that you want to possibly attack
def calcDamage (fromPlayer: self, toPlayer: self)
# Damage = Strength - Defense/2
if self == fromPlayer
self.stats[:strength] - toPlayer.stats[:defense]/2
else
fromPlayer.stats[:strength] - self.stats[:defense]/2
end
end

# player: the player that you want to know the TTK for
# damage: the damage of the player other than the :player
def timeToKill (player: self, damage: 10)
# Time-To-Kill = Health / Damage
if player != self
player.stats[:health]/damage
else
self.stats[:health]/damage
end
end

def opponents
Game.world[:players].select{|p| p!=self}
end

def recover
[:rest]
end

def leader
opponents.max_by { |p| xp(p) }
end

def middle_of_pack
opponents.sort_by! { |p| xp(p) }
opponents[opponents.count/2]
end

def should_fight?
if health >= 100 && @round < 10
true
elsif @round >= 80
true
elsif xp > xp(middle_of_pack)
false
else
true
end
end

def xp(p = self)
p.stats[:experience]
end

def level(p = self)
p.stats[:level]
end

def health(p = self)
p.stats[:health]
end

def fight
[:attack, kill] unless kill.nil?
end

end

0 comments on commit 35c5b33

Please sign in to comment.