def chooseStrategy():
enemies = self.findEnemies()
enemy = self.findNearest(enemies)
if self.gold >= self.costOf("griffin-rider"):
return "griffin-rider"
# If you can summon a griffin-rider, return "griffin-rider"
elif enemy:
if enemy.type == "fangrider" and self.distanceTo(enemy) < 30:
return "fight-back"
# If there is a fangrider on your side of the mines, return "fight-back"
else:
return "collect-coins"
def commandAttack():
# Command your griffin riders to attack ogres.
for griffin in self.findByType("griffin-rider"):
if griffin:
enemy = griffin.findNearest(griffin.findEnemies)
if enemy:
self.command(griffin, "attack", enemy)
def pickUpCoin():
# Collect coins
coin = self.findNearest(self.findItems())
if coin:
self.move(coin.pos)
def heroAttack():
# Your hero should attack fang riders that cross the minefield.
enemy = self.findNearest(self.findEnemies())
if enemy and self.distanceTo(enemy) < 30:
if self.canCast("fear", enemy):
self.cast("fear", enemy)
if self.canCast("invisibility", self):
self.cast("invisibility", self)
elif self.canCast("drain-life", enemy):
self.cast("drain-life", enemy)
if self.canCast("invisibility", self):
self.cast("invisibility", self)
elif self.canCast("invisibility", self):
self.cast("invisibility", self)
loop:
commandAttack()
strategy = chooseStrategy()
# Call a function, depending on what the current strategy is.
if strategy == "griffin-rider":
self.summon("griffin-rider")
if strategy == "fight-back":
heroAttack()
if strategy == "collect-coins":
pickUpCoin()
When I run this code it works fine until enemies appear, then my hero freezes and my griffins do nothing. What is wrong? Any help is greatly appreciated (even if it doesn’t work ).
Thank you so much. Can’t believe I didn’t see that. That solved the griffin problem but my hero still freezes when the enemy shows up. Any suggestions?
and then all the other stuff in the function, because i’ve already tried that too and it doesnt work. I’m so confused. Thanks for you’re help though.
elif enemy:
if enemy.type == "fangrider" and self.distanceTo(enemy) < 30:
return "fight-back"
If there is an enemy but it’s not a fangrider closer than 30m from you, then you will return None from this method and take no action. Try something like:
elif enemy and enemy.type == 'fangrider' and self.distanceTo(enemy) < 30:
return "fight-back"
Hi i’m totally stuck on this level I tried beating it, but I just can’t. Here is my code:
The goal is to survive for 30 seconds, and keep the mines intact for at least 30 seconds.
def chooseStrategy():
enemies = self.findEnemies()
enemy = self.findNearest(enemies)
# If you can summon a griffin-rider, return "griffin-rider"
if self.gold >= self.costOf(“griffin-rider”):
self.summon(“griffin-rider”)
# If there is a fangrider on your side of the mines, return "fight-back"
if enemy and self.distanceTo(enemy) < 6:
self.attack(enemy)
# Otherwise, return "collect-coins"
else:
coin = self.findNearest(self.findItems())
if coin:
self.move(coin.pos)
def commandAttack():
friends = self.findFriends()
friend = self.findNearest(friends)
defencePoint = {“x”: 56, “y”: 43}
if friend:
enemies = friend.findEnemies()
enemy = friend.findNearest(enemies)
if enemy and enemy.type is not “fang-rider”:
self.command(friend, “attack”, enemy)
else:
self.command(friend, “move”, defencePoint)
def pickUpCoin():
coin = self.findNearest(self.findItems())
if coin:
self.move(coin.pos)
def heroAttack():
enemies = self.findEnemies()
enemy = self.findNearest(enemies)
if enemy:
if enemy.type is “fang-rider”:
if self.distanceTo(enemy) > 6:
self.attack(enemy)
else:
pickUpCoin()
loop:
commandAttack()
strategy = chooseStrategy()
# Call a function, depending on what the current strategy is.
heroAttack()
pickUpCoin()
i dont known whats wrong with my code it doesnt say anything is wrong my hero doesnt move to collect gold and he summons one griffin and the griffin doesnt attack any enemies here is my code
def chooseStrategy():
enemies = self.findEnemies()
enemy = self.findNearest(enemies)
if self.gold >= self.costOf("griffin-rider"):
return "griffin-rider"
# If you can summon a griffin-rider, return "griffin-rider"
elif enemy and enemy.type == 'fangrider' and self.distanceTo(enemy) < 30:
return "fight-back"
# If there is a fangrider on your side of the mines, return "fight-back"
else:
return "collect-coins"
def commandAttack():
# Command your griffin riders to attack ogres.
for griffin in self.findByType("griffin-rider"):
if griffin:
enemy = griffin.findNearest(griffin.findEnemies)
if enemy:
self.command(griffin, "attack", enemy)
def pickUpCoin():
# Collect coins
coin = self.findNearest(self.findItems())
if coin:
self.move(coin.pos)
loop:
commandAttack()
strategy = chooseStrategy()
# Call a function, depending on what the current strategy is.
if strategy == "griffin-rider":
self.summon("griffin-rider")
if strategy == "collect-coins":
pickUpCoin()
nvm my code is fine now but the enemies get the mines in under 30 seconds
def chooseStrategy():
enemies = self.findEnemies()
enemy = self.findNearest(enemies)
if self.gold > self.costOf("griffin-rider"):
return "griffin-rider"
# If you can summon a griffin-rider, return "griffin-rider"
elif enemy:
if enemy.type is "fangrider" and self.distanceTo(enemy) < 30:
return "fight-back"
# If there is a fangrider on your side of the mines, return "fight-back"
else:
return "collect-coins"
# Otherwise, return "collect-coins"
def commandAttack():
# Command your griffin riders to attack ogres.
for griffin in self.findByType("griffin-rider"):
if griffin:
enemy = griffin.findNearestEnemy()
if enemy:
self.command(griffin, "attack", enemy)
def pickUpCoin():
# Collect coins
coin = self.findNearest(self.findItems())
if coin:
self.move(coin.pos)
def heroAttack():
# Your hero should attack fang riders that cross the minefield.
enemy = self.findNearest(self.findEnemies())
if enemy and self.distanceTo(enemy) < 30:
self.attack(enemy)
loop:
commandAttack()
strategy = chooseStrategy()
# Call a function, depending on what the current strategy is.
if strategy == "griffin-rider":
self.summon("griffin-rider")
if strategy == "fight-back":
heroAttack()
if strategy == "collect-coins":
pickUpCoin()
def chooseStrategy():
enemies = self.findEnemies()
enemy = self.findNearest(enemies)
if self.gold > self.costOf("griffin-rider"):
return "griffin-rider"
# If you can summon a griffin-rider, return "griffin-rider"
elif enemy and enemy.type == 'fangrider' and self.distanceTo(enemy) < 30:
return "fight-back"
# If there is a fangrider on your side of the mines, return "fight-back"
else:
return "collect-coins"
# Otherwise, return "collect-coins"
def commandAttack():
# Command your griffin riders to attack ogres.
for griffin in self.findByType("griffin-rider"):
if griffin:
enemy = griffin.findNearestEnemy()
if enemy:
self.command(griffin, "attack", enemy)
def pickUpCoin():
# Collect coins
coin = self.findNearest(self.findItems())
if coin:
self.move(coin.pos)
def heroAttack():
# Your hero should attack fang riders that cross the minefield.
enemy = self.findNearest(self.findEnemies())
if enemy and self.distanceTo(enemy) < 30:
self.attack(enemy)
loop:
commandAttack()
strategy = chooseStrategy()
# Call a function, depending on what the current strategy is.
if strategy == "griffin-rider":
self.summon("griffin-rider")
if strategy == "fight-back":
heroAttack()
if strategy == "collect-coins":
pickUpCoin()