Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: c833b2742d
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 161 lines (133 sloc) 4.187 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
(0..2).each do |n|
  eval %(
module Dank#{n}
BOSS_DANGER_ZONE = 90
MINION_DANGER_ZONE = 80
ATTACKER_POOL = 5
CAUTIOUS_ROUNDS = 20
RISKY_ROUNDS = 50
def self.extended(base)
base.instance_variable_set :@round_count, 0
end
def to_s
minion? ? "Minion" : "Dan Knox"
end
def move
@round_count += 1
prepare_friendlies if game_is_beginning?
promote_minion if boss_lacks_experience? || boss_dead?
minion? ? rest_or_attack : command_and_control
end
def trade(command,target=nil)
case command
when :begin_game
@minion = true
@game_underway = true
when :set_target
@target = target
when :set_boss
@minion = false
when :set_super_secret_code
@super_secret_code = target
end
end
protected
def rest_or_attack
@target = available_monsters.sample if @target.nil?
if @round_count < CAUTIOUS_ROUNDS
@target = available_monsters.sample if available_monsters.any?
return [:rest] unless (@round_count % 2 == 0)
end
dangerous_health? ? [:rest] : [:attack,@target]
end

def command_and_control
ensure_only_one_boss
@target = @next_target
set_attack_targets
rest_or_attack
end

def set_attack_targets
@current_friends = friends
attackers = ATTACKER_POOL
(friends).each_with_index do |friend,index|
if @round_count > RISKY_ROUNDS && secure_bots.any?
new_target = secure_bots.first
else
new_target = index <= attackers ? strongest_enemies[0] : strongest_enemies[1]
end
if friend.respond_to?(:iff)
friend.set_target( @super_secret_code, 0, new_target )
else
friend.trade( :set_target, new_target )
end
end
@next_target = strongest_enemies[0] || friends.first # Everyone else is dead... start giving more experience to the boss
end

def aggregrate_strength
@current_friends.inject(0) { |sum,friend| sum + friend.stats[:strength] }
end

def dangerous_health?
boss? ?
(stats[:health] <= BOSS_DANGER_ZONE) :
(stats[:health] <= MINION_DANGER_ZONE)
end

def target_set?
@target
end

def promote_minion
if most_experienced_minion.nil?
@minion = false
else
@minion = true
most_experienced_minion.trade(:set_boss)
end
end

def boss_lacks_experience?
potential_boss = most_experienced_minion || (return false)
return false unless potential_boss.respond_to?(:stats)
stats[:experience] < potential_boss.stats[:experience]
end

def prepare_friendlies
@game_underway = true
@minion = false
friends.each do |friend|
friend.trade :begin_game
end
end
def friends
Game.world[:players].select { |p| p.to_s =~ /(Minion|Dan Knox)/ && p != self }
end
def secure_bots
Game.world[:players].select { |p| p.respond_to?(:iff) && p.alive }
end
def enemies
Game.world[:players].select { |p| p.alive }.reject { |p| friends.include?(p) or p == self }
end

def strongest_enemies
enemies.sort { |a,b| b.stats[:experience] <=> a.stats[:experience] }
end

def most_experienced_minion
friends.sort_by { |m| m.stats[:experience] }.last
end

def available_monsters
Game.world[:players].select { |player| monsters.include?(player.to_s) && player.alive }
end
def boss_dead?
boss = Game.world[:players].select { |p| p.to_s =~ /Dan Knox/ && p.alive }.first
boss.nil?
end
def monsters
["rat"]
end

def minion?
@minion
end

def boss?
!@minion
end

def game_is_beginning?
!@game_underway
end
end
)
end
Something went wrong with that request. Please try again.