hi. i’m not too sure about what to change on this level. here’s my code:
`def chooseStrategy():
enemies = hero.findEnemies()
if hero.costOf("griffin-rider"):
return "griffin-rider"
enemies = hero.findEnemies()
for enemy in enemies:
if enemy.type == "fangrider":
if enemy.pos.x < 34:
return "fight-back"
for enemy in enemies:
if enemy.pos.x > 34 and hero.gold < hero.costOf("griffin-rider"):
return "collect-coins"
def commandAttack():
friends = hero.findFriends()
giffinRider = None
for friend in friends:
if friend.type == "griffin-rider":
boi = griffinRider
if boi:
hero.command(boi, "attack", target)
pass
def pickUpCoin():
# Collect coins
coin = hero.findNearestItem()
if coin:
hero.move(coin.pos)
pass
def heroAttack():
enemies = hero.findEnemies()
for enemy in enemies:
if enemy.type == "fangrider" and enemy.pos.x < 34:
hero.attack(enemy)
pass
while True:
commandAttack()
strategy = chooseStrategy()
if "griffin-rider":
commandAttack()
if "fight-back":
heroAttack()
elif "collect-coins":
pickUpCoin()`
Here put
strategy = chooseStrategy()
if strategy=="griffin-rider":
#here summon a griffin-rider
elif strategy=="fight-back":
heroAttack()
elif strategy=="collect-coins":
pickUpCoin()`
2 Likes
Instead of that put this:
for friend in friends:
if friend.type == "griffin-rider":
enemy = friend.findNearestEnemy()
if enemy:
hero.command(friend, "attack", enemy)
2 Likes
Instead of that put this:
enemy = hero.findNearestEnemy()
if enemy.health > 0:
hero.attack(enemy)
Instead of that, put something like this:
if hero.gold >= hero.costOf("griffin-rider"):
Does it work now?
2 Likes
here’s the new code:
def chooseStrategy():
enemies = hero.findEnemies()
if hero.costOf("griffin-rider"):
return "griffin-rider"
enemies = hero.findEnemies()
for enemy in enemies:
if enemy.type == "fangrider":
if enemy.pos.x < 34:
return "fight-back"
for enemy in enemies:
if enemy.pos.x > 34 and hero.gold < hero.costOf("griffin-rider"):
return "collect-coins"
def commandAttack():
friends = hero.findFriends()
giffinRider = None
for friend in friends:
if friend.type == "griffin-rider":
enemy = friend.findNearestEnemy()
if enemy:
hero.command(friend, "attack", enemy)
pass
def pickUpCoin():
# Collect coins
coin = hero.findNearestItem()
if coin:
hero.move(coin.pos)
pass
def heroAttack():
enemy = hero.findNearestEnemy()
if enemy.health > 0:
hero.attack(enemy)
pass
while True:
commandAttack()
strategy = chooseStrategy()
if "griffin-rider":
commandAttack()
elif "fight-back":
heroAttack()
elif "collect-coins":
pickUpCoin()
I edited the last one. Does it work with that change?
2 Likes
And you forgot to correct this:
Instead of that put this:
for friend in friends:
if friend.type == "griffin-rider":
enemy = friend.findNearestEnemy()
if enemy:
hero.command(friend, "attack", enemy)
Does it work now?
2 Likes
i’ll be back soon, i have a video conference. bye
Delete all of this and put
return "collect-coins"
2 Likes
Have you completed the level?
2 Likes
no i haven’t. here’s the new code:
def chooseStrategy():
enemies = hero.findEnemies()
if hero.costOf("griffin-rider"):
return "griffin-rider"
enemies = hero.findEnemies()
for enemy in enemies:
if enemy.type == "fangrider":
if enemy.pos.x < 34:
return "fight-back"
return "collect-coins"
def commandAttack():
friends = hero.findFriends()
for friend in friends:
if friend.type == "griffin-rider":
enemy = friend.findNearestEnemy()
if enemy:
hero.command(friend, "attack", enemy)
pass
def pickUpCoin():
# Collect coins
coin = hero.findNearestItem()
if coin:
hero.move(coin.pos)
pass
def heroAttack():
enemy = hero.findNearestEnemy()
if enemy.health > 0:
hero.attack(enemy)
pass
while True:
commandAttack()
strategy = chooseStrategy()
if "griffin-rider":
commandAttack()
elif "fight-back":
heroAttack()
elif "collect-coins":
pickUpCoin()
You have not corrected this!!
Instead of that put this:
for friend in friends:
if friend.type == "griffin-rider":
enemy = friend.findNearestEnemy()
if enemy:
hero.command(friend, "attack", enemy)
2 Likes
which line, because i think i did
Try to change the lines I showed you with this.
2 Likes
which line number? (20 chars)
like this?:
while True:
commandAttack()
strategy = chooseStrategy()
for friend in friends:
if friend.type == "griffin-rider":
enemy = friend.findNearestEnemy()
if enemy:
hero.command(friend, "attack", enemy)