So I’m not really sure what’s happening on this level. here’s the link and my code.
~Andrew
# The goal is to survive for 30 seconds, and keep the mines intact for at least 30 seconds.
def chooseStrategy():
enemies = hero.findEnemies()
# If you can summon a griffin-rider, return "griffin-rider"
if hero.gold > hero.costOf("griffin-rider"):
return "griffin-rider"
# If there is a fangrider on your side of the mines, return "fight-back"
elif enemy.type == "fangrider":
return "fight-back"
# Otherwise, return "collect-coins"
else:
return "collect-coins"
def commandAttack():
# Command your griffin riders to attack ogres.
enemy = hero.findNearestEnemy()
friends = hero.findFriends()
for friend in friends:
hero.command(friend, "attack", enemy)
pass
def pickUpCoin():
# Collect coins
item = hero.findNearestItem()
hero.moveXY(item.pos.x,item.pos.y)
pass
def heroAttack():
# Your hero should attack fang riders that cross the minefield.
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)
pass
while True:
pickUpCoin()
commandAttack()
strategy = chooseStrategy()
# Call a function, depending on what the current strategy is.
hero.strategy
heroAttack
So, @CocoCharlie there are a couple issues with your code and strategy. First one that I see is this:
It actually says in the comment right beneath to check if the fangrider is on your side of the mines
Next issue is this:
It also says in a comment, (this time right above it) to only attack fangriders that cross the minefield.
Last issue that I see is this one:
What you should do here should look a little more like this:
if strategy == "griffin-rider":
(Summon your griffin rider)
if strategy == "fight-back":
(Call your attack function)
if strategy == "collect-coins":
(Call your coin collection function)
Here’s my now code. I have to get offline now though.
# The goal is to survive for 30 seconds, and keep the mines intact for at least 30 seconds.
def chooseStrategy():
enemies = hero.findEnemies()
enemy = hero.findNearestEnemy()
fangrider = enemy.type == "fangrider"
# If you can summon a griffin-rider, return "griffin-rider"
if hero.gold > hero.costOf("griffin-rider"):
return "griffin-rider"
# If there is a fangrider on your side of the mines, return "fight-back"
elif fangrider.pos.x < 35:
return "fight-back"
# Otherwise, return "collect-coins"
else:
return "collect-coins"
def commandAttack():
# Command your griffin riders to attack ogres.
enemy = hero.findNearestEnemy()
friends = hero.findFriends()
for friend in friends:
hero.command(friend, "attack", enemy)
pass
def pickUpCoin():
# Collect coins
item = hero.findNearestItem()
hero.moveXY(item.pos.x,item.pos.y)
pass
def heroAttack():
# Your hero should attack fang riders that cross the minefield.
fangrider = enemy.type == "fangrider"
fangrider2 = fangrider.pos.x < 35
if fangrider2:
hero.attack(fangrider2)
pass
while True:
strategy = chooseStrategy()
# Call a function, depending on what the current strategy is.
if strategy == "griffin-rider":
hero.summon("griffin-rider")
if strategy == "fight-back":
heroAttack()
if strategy == "collect-coins":
pickUpCoin()
if enemy.type is "fangrider" and enemy.pos.x < 38:
(Combine the 2 lines into 1)
Also, you might need to change this part:
Try changing the enemy = hero.findNearestEnemy() to enemy = friend.findNearestEnemy() and put it inside the loop where you iterate through your friends so each friend finds an enemy.
Another thing you need to change is this part:
What I would suggest doing is checking to see the fangrider’s x position and to see if it exists in 1 line so it is simplified which will make it easier to find mistakes. It would look something like this:
enemy = hero.findNearest(hero.findEnemies())
if enemy and enemy.pos.x < 38:
hero.attack(enemy)
The last issue I see is this part:
What worked for me was adding a pickUpCoin() and a commandAttack() before you choose your strategy because if you don’t (at least for me) my hero actually kept stopping which kept him from gathering enough gold, so I failed. Sorry for writing so much, but I hope it all helps!
-Grzmot
Ok, this aint working. It’s working a little better though. Thanks for that long and tedious explanation btw @Grzmot
# The goal is to survive for 30 seconds, and keep the mines intact for at least 30 seconds.
def chooseStrategy():
# If you can summon a griffin-rider, return "griffin-rider"
if hero.gold > hero.costOf("griffin-rider"):
return "griffin-rider"
# If there is a fangrider on your side of the mines, return "fight-back"
friends = hero.findFriends()
for friend in friends:
enemy = friend.findNearestEnemy()
if enemy:
if enemy.type is "fangrider" and enemy.pos.x < 38:
return "fight-back"
# Otherwise, return "collect-coins"
else:
return "collect-coins"
def commandAttack():
# Command your griffin riders to attack ogres.
enemy = hero.findNearestEnemy()
friends = hero.findFriends()
for friend in friends:
hero.command(friend, "attack", enemy)
pass
def pickUpCoin():
# Collect coins
item = hero.findNearestItem()
hero.moveXY(item.pos.x,item.pos.y)
pass
def heroAttack():
# Your hero should attack fang riders that cross the minefield.
enemy = hero.findNearest(hero.findEnemies())
if enemy and enemy.pos.x < 38:
hero.attack(enemy)
pass
while True:
pickUpCoin()
commandAttack()
strategy = chooseStrategy()
# Call a function, depending on what the current strategy is.
if strategy == "griffin-rider":
hero.summon("griffin-rider")
if strategy == "fight-back":
heroAttack()
if strategy == "collect-coins":
pickUpCoin()
# The goal is to survive for 30 seconds, and keep the mines intact for at least 30 seconds.
def chooseStrategy():
# If you can summon a griffin-rider, return "griffin-rider"
if hero.gold > hero.costOf("griffin-rider"):
return "griffin-rider"
# If there is a fangrider on your side of the mines, return "fight-back"
friends = hero.findFriends()
for friend in friends:
enemy = friend.findNearestEnemy()
if enemy:
if enemy.type is "fangrider" and enemy.pos.x < 36:
return "fight-back"
# Otherwise, return "collect-coins"
else:
return "collect-coins"
def commandAttack():
# Command your griffin riders to attack ogres.
enemy = hero.findNearestEnemy()
friends = hero.findFriends()
for friend in friends:
hero.command(friend, "attack", enemy)
pass
def pickUpCoin():
# Collect coins
item = hero.findNearestItem()
if item:
hero.moveXY(item.pos.x,item.pos.y)
pass
def heroAttack():
# Your hero should attack fang riders that cross the minefield.
enemy = hero.findNearest(hero.findEnemies())
distance = hero.distanceTo(enemy)
if enemy and enemy.pos.x < 38 and distance < 30:
hero.attack(enemy)
pass
while True:
commandAttack()
strategy = chooseStrategy()
# Call a function, depending on what the current strategy is.
if strategy == "griffin-rider":
hero.summon("griffin-rider")
if strategy == "fight-back":
heroAttack()
if strategy == "collect-coins":
pickUpCoin()
This should be just defining the fangrider as fangrider = hero.findNearest(hero.findByType("fangrider")
And then checking if there is a fangrider and if the fangrider’s pos.x is less than 36
If so, return “fight-back”
Change this to hero.move(item.pos) so you can command your friends too
Lydia
Ok, now it’s finding a colon that it says shouldn’t be there. In the if statement of the fangrider type.
# The goal is to survive for 30 seconds, and keep the mines intact for at least 30 seconds.
def chooseStrategy():
# If you can summon a griffin-rider, return "griffin-rider"
if hero.gold > hero.costOf("griffin-rider"):
return "griffin-rider"
# If there is a fangrider on your side of the mines, return "fight-back"
friends = hero.findFriends()
for friend in friends:
enemy = friend.findNearestEnemy()
if enemy:
fangrider = hero.findNearest(hero.findByType("fangrider")
if fangrider and fangrider.pos.x < 36:
return "fight-back"
# Otherwise, return "collect-coins"
else:
return "collect-coins"
def commandAttack():
# Command your griffin riders to attack ogres.
enemy = hero.findNearestEnemy()
friends = hero.findFriends()
for friend in friends:
hero.command(friend, "attack", enemy)
pass
def pickUpCoin():
# Collect coins
item = hero.findNearestItem()
if item:
hero.move(item.pos)
pass
def heroAttack():
# Your hero should attack fang riders that cross the minefield.
enemy = hero.findNearest(hero.findEnemies())
distance = hero.distanceTo(enemy)
if enemy and enemy.pos.x < 38 and distance < 30:
hero.attack(enemy)
pass
while True:
commandAttack()
strategy = chooseStrategy()
# Call a function, depending on what the current strategy is.
if strategy == "griffin-rider":
hero.summon("griffin-rider")
if strategy == "fight-back":
heroAttack()
if strategy == "collect-coins":
pickUpCoin()
# The goal is to survive for 30 seconds, and keep the mines intact for at least 30 seconds.
def chooseStrategy():
# If you can summon a griffin-rider, return "griffin-rider"
if hero.gold > hero.costOf("griffin-rider"):
return "griffin-rider"
# If there is a fangrider on your side of the mines, return "fight-back"
enemy = friend.findNearestEnemy()
if enemy:
fangrider = hero.findNearest(hero.findByType("fangrider")
if fangrider and fangrider.pos.x < 36:
return "fight-back"
# Otherwise, return "collect-coins"
else:
return "collect-coins"
def commandAttack():
# Command your griffin riders to attack ogres.
enemy = hero.findNearestEnemy()
friends = hero.findFriends()
for friend in friends:
hero.command(friend, "attack", enemy)
pass
def pickUpCoin():
# Collect coins
item = hero.findNearestItem()
if item:
hero.move(item.pos)
pass
def heroAttack():
# Your hero should attack fang riders that cross the minefield.
enemy = hero.findNearest(hero.findEnemies())
distance = hero.distanceTo(enemy)
if enemy and enemy.pos.x < 38 and distance < 30:
hero.attack(enemy)
pass