def summonTroops():
if hero.gold > hero.costOf("soldier"):
hero.summon("soldier")
if hero.gold > hero.costOf("archer"):
hero.summon("archer")
if hero.gold > hero.costOf("griffin-rider"):
hero.summon("griffin-rider")
def commandSoldier():
soldiers = hero.findByType("soldier")
for soldier in soldiers:
Senemies = soldier.findEnemies()
for Senemy in Senemies:
if Senemy and soldier:
hero.command(soldier, "attack", Senemy)
def commandArcher():
archers = hero.findByType("archer")
for archer in archers:
Aenemies = archer.findEnemies()
for Aenemy in Aenemies:
if Aenemy and archer:
hero.command(archer, "attack", Aenemy)
def commandPaladin():
paladins = hero.findByType("paladin")
for paladin in paladins:
Penemies = paladin.findEnemies()
Pfriend = paladin.findNearest(hero.findFriends())
for Penemy in Penemies:
if Penemy and paladin:
hero.command(paladin, "attack", Penemy)
if paladin.canCast("heal, Pfriend"):
hero.command(paladin, "cast, heal", Pfriend)
def heroAttack():
enemies = hero.findEnemies()
for enemy in enemies:
if enemy:
hero.attack(enemy)
if hero.isReady("chain-lightning"):
hero.cast("chain-lightning", enemy)
def pickUpFlags():
flag = hero.findFlag()
if flag:
hero.pickUpFlag(flag)
while True:
summonTroops()
commandSoldier()
commandArcher()
commandPaladin()
heroAttack()
pickUpFlags()
My inventory(hero is Usara Master Wizard):
Please help me to optimize the code for her and make it work
For her means using RaiseDead, summonUndead, summonBurl, summonYeti, and, maybe summonRobobomb
First mistake I found, you do not have the emperor’s gloves, so you cannot do chain-lightning. Your soldiers probably are not attacking anyone because you are trying to cast chain-lightning when you do not have the spell, causing an error. Second mistake lies in summonTroops function. Your hero will only summon the soldier and a few archer and griffin riders due to the default 60 gold and the gems in the warlock area because the soldier is the cheapest. Your hero will spend gold on soldier before you are able to boot up for the rest. Unless this is what you meant, try to use an array like the one in Ace of Coders.
To optimize, you can add the summom burl, undead, yeti, and raise-dead to the heroAttack function. Also, you can make a function like commandUndeadAndYeti to command them to your will. Summon robobomb is not really useful unless you know this trick… Hint: Pair it with magnet field and your bear’s freezing spell( I am also a Usara user )
i you did, please don’t. codecombat isn’t a speedruning rpg game. its for learning. Whats the use if u dont understand the code, and copy from someone else to make you look smart?