Skip to content

Instantly share code, notes, and snippets.

@dhoelzgen
Created May 11, 2011 07:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhoelzgen/966044 to your computer and use it in GitHub Desktop.
Save dhoelzgen/966044 to your computer and use it in GitHub Desktop.
SaboteurAgent in experimental DSL
require 'simple_agent'
class SaboteurAgent < SimpleAgent
on_percept :visibleEntity do |name, position, team, status|
next if team == @team
broadcast
if enemy = @enemies[name]
enemy.position = position
enemy.status = status
else
@enemies[name] = Enemy.new( name, position, team, status )
end
end
motivate :attack do
next -1 if bb.disabled
next -1 unless bb.position
candidates = @enemies.values.find_all { |enemy| enemy.position == bb.position && enemy.enabled }
target = candidates.sort.last
if bb.transient[:attack_target] = target
80
else
-1
end
end
on_goal :attack do
say "Attacking #{bb.transient[:attack_target].name}"
next skip! unless has_energy 2
attack! bb.transient[:attack_target]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment