Skip to content
This repository
Browse code

Added flipback player

  • Loading branch information...
commit 0efeaf151849454f9fbfe06972c2c84335478e9b 1 parent 6bd7b44
Aleksey Timin flipback authored

Showing 1 changed file with 38 additions and 0 deletions. Show diff stats Hide diff stats

  1. +38 0 players/flipback.rb
38 players/flipback.rb
... ... @@ -0,0 +1,38 @@
  1 +module Flipback
  2 + FATE = 0.7
  3 +
  4 + def to_s
  5 + "flipback"
  6 + end
  7 +
  8 + def move
  9 + return [ :rest ] if stats[:health] < 60
  10 +
  11 + target = dying_player
  12 + if target
  13 + [:attack, target]
  14 + elsif other_players.count == 1 || rand > FATE || stats[:health] >= 100
  15 + [:attack, best_player]
  16 + else
  17 + [ :rest ]
  18 + end
  19 + end
  20 +
  21 + private
  22 + def other_players
  23 + Game.world[:players].select{ |p| p != self }
  24 + end
  25 +
  26 + def best_player
  27 + other_players.sort{ |i,j| i.stats[:experience] <=> j.stats[:experience] }.last
  28 + end
  29 +
  30 + def dying_player
  31 + other_players.select{ |p| can_kill?(p) }.first
  32 + end
  33 +
  34 + def can_kill?(player)
  35 + points = stats[:strength] - (player.stats[:defense] / 2)
  36 + player.stats[:health] <= points
  37 + end
  38 +end

0 comments on commit 0efeaf1

Please sign in to comment.
Something went wrong with that request. Please try again.