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 heroAttack():
# Your hero should attack fang riders that cross the minefield.
enemy = self.findNearest(self.findEnemies())
elif enemy and enemy.type == ‘fangrider’ and self.distanceTo(enemy) < 30:
return "fight-back"
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()
why doesn’t it work?
help would be greatly appreciated
Hello, Trevor. Please format your code according to the FAQ.
Here’s what I can see off the top of my head:
In commandAttack(): griffin.findEnemies should have a pair of parentheses, as it is a method.
In heroAttack():
-You have an elif block that looks to be copied from chooseStrategy. Remove it. It has no place here.
-You check if you can cast invisibility multiple times. You only need to do so once.
-You never really attack the enemy you find.
It would also help to have a description of your error. Correct these things, then come back to us.
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”):
return “griffin-rider”
# If there is a fangrider on your side of the mines, return "fight-back"
elif enemy:
self.findByType(“fangrider”)
if enemy.type is “fangrider” and self.distanceTo(enemy)<30:
return “fight-back”
# Otherwise, return "collect-coins"
else:
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 heroAttack():
# Your hero should attack fang riders that cross the minefield.
enemy = self.findNearest(self.findEnemies())
if enemy and self.distanceTo(“fangrider”) < 30:
self.attack(“fangrider”)
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()
whats wrong . my charecter freezes when enemies appear
any help would be appreciated!!
Even though your code is not properly formatted, the issue is in the heroAttack() function:
def heroAttack():
enemy = self.findNearest(self.findEnemies())
if enemy and self.distanceTo("fangrider") < 30:
self.attack("fangrider")
The are no enemies called “fangrider” – that’s rather the enemy.type. So you need something like this:
if enemy and enemy.type == "fangrider" and self.distanceTo(enemy) < 30:
self.attack(enemy)
Although the self.distanceTo(enemy) < 30 part can get you into trouble (you will walk into the minefield) so try to improve that. (hint: check the x-coordinate of the enemy…)
My code which also cleared the bonus.
condition : you need 1000+ HP and about 200 DP
The tactics is to stop the breach to the mineyard with the griffon and kill the fang rider which breached the mineyard with your hero quickly. Don’t attack the fang rider which breached the mineyard with your griffon. Other enemy will breach your mineyard.