Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge remote-tracking branch 'upstream/master'

  • Loading branch information...
commit 66e2eda3ae7441091af5af496e8e95ad86e19b2f 2 parents 3842bad + b779631
david karapetyan authored
Showing with 64 additions and 12 deletions.
  1. +1 −0  engine/player.rb
  2. +1 −1  engine/player_proxy.rb
  3. +62 −11 players/dank.rb
View
1  engine/player.rb
@@ -1,6 +1,7 @@
class Player
attr_accessor :proxy
attr_reader :max_health, :health, :level, :strength, :defense, :alive
+ alias :alive? :alive
LEVEL_THRESHOLDS = [50,100,200,500,1000,1500,2500,4000]
HEALTH_INDEX = [100,110,125,145,170,195,225,260]
View
2  engine/player_proxy.rb
@@ -4,7 +4,7 @@ def initialize(player)
end
def method_missing(method, *args, &block)
- if [:alive, :move, :fight, :to_s, :trade, :rest, :inspect, :stats].include? method
+ if [:alive, :alive?, :move, :fight, :to_s, :trade, :rest, :inspect, :stats].include? method
@player.send(method, *args, &block)
end
end
View
73 players/dank.rb
@@ -2,16 +2,23 @@
eval %(
module Dank#{n}
BOSS_DANGER_ZONE = 90
- MINION_DANGER_ZONE = 20
+ 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?
+ promote_minion if boss_lacks_experience? || boss_dead?
minion? ? rest_or_attack : command_and_control
end
@@ -24,6 +31,8 @@ def trade(command,target=nil)
@target = target
when :set_boss
@minion = false
+ when :set_super_secret_code
+ @super_secret_code = target
end
end
@@ -31,6 +40,10 @@ def trade(command,target=nil)
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
@@ -45,9 +58,17 @@ def set_attack_targets
@current_friends = friends
attackers = ATTACKER_POOL
- friends.each_with_index do |friend,index|
- new_target = index <= attackers ? strongest_enemies[0] : strongest_enemies[1]
- friend.trade( :set_target, new_target )
+ (friends + secure_bots).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
@@ -68,8 +89,12 @@ def target_set?
end
def promote_minion
- @minion = true
- most_experienced_minion.trade(:set_boss)
+ if most_experienced_minion.nil?
+ @minion = false
+ else
+ @minion = true
+ most_experienced_minion.trade(:set_boss)
+ end
end
def boss_lacks_experience?
@@ -79,16 +104,37 @@ def boss_lacks_experience?
end
def prepare_friendlies
+ @game_underway = true
@minion = false
+ @super_secret_code = discover_secure_bot_secret_code
friends.each do |friend|
- friend.trade(:begin_game)
+ friend.trade :set_super_secret_code, @super_secret_code
+ friend.trade :begin_game
end
end
-
+
+ def discover_secure_bot_secret_code
+ discovery_bot = secure_bots.first
+ initial_target = enemies.first
+ secret_code = nil
+ (0..1_000_000).map do |possible_key|
+ success = discovery_bot.set_target( possible_key, 0, initial_target )
+ if success
+ secret_code = possible_key
+ break
+ end
+ end
+ secret_code
+ 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
@@ -104,7 +150,12 @@ def most_experienced_minion
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
Please sign in to comment.
Something went wrong with that request. Please try again.