a ruby programming game
module ScorpionKing class Bulldog < Tournament::Agent attr_accessor :enemies, :prey def after_start @enemies = [] @enemy_size = 2.0/3.0 end def think been_attacked? @view = look_around move_to hunted_prey || found_enemy || best_resource end # goes the the biggest free resource def best_resource @view.select{|f| f.has_no_population? or myfield?(f) }.max_by{|f| f.resource} end def found_enemy if found_on_field = @view.select do |f| f.has_population? && @enemies.include?(f.agent) && size * @enemy_size > f.population end.min_by do |f| f.population end @prey = found_on_field.agent info "found enemy #{@prey}, hunt begins" found_on_field end end def hunted_prey if @prey if hunted_prey = @view.find do|f| f.has_population? && f.agent == @prey && size * @enemy_size > f.population end info "hunting down #{hunted_prey.agent}" hunted_prey else info "prey #{prey} lost" nil end end end def been_attacked? each_event do |event| if event.instance_of? AttackedEvent unless @enemies.include? event.attacker @enemies << event.attacker info "keep in mind enemy #{event.attacker}" end end end end def myfield? field field.x == 0 && field.y == 0 end end end