can someone help please
Can I see your code?
def commandSoldier(soldier, soldierIndex, numSoldiers):
angle = Math.PI * 2 * soldierIndex / numSoldiers
defendPos = {"x": 41, "y": 40}
defendPos.x += 10 * Math.cos(angle)
defendPos.y += 10 * Math.sin(angle)
hero.command(soldier, "defend", defendPos);
# Find the strongest target (most health)
# This function returns something! When you call the function, you will get some value back.
def findStrongestTarget():
mostHealth = 0
bestTarget = None
enemies = hero.findEnemies()
# Figure out which enemy has the most health, and set bestTarget to be that enemy.
# Only focus archers' fire if there is a big ogre.
if bestTarget and bestTarget.health > 15:
return bestTarget
else:
return None
# If the strongestTarget has more than 15 health, attack that target. Otherwise, attack the nearest target.
def commandArcher(archer):
nearest = archer.findNearestEnemy()
if archerTarget:
hero.command(archer, "attack", archerTarget)
elif nearest:
hero.command(archer, "attack", nearest)
archerTarget = None
while True:
# If archerTarget is defeated or doesn't exist, find a new one.
if not archerTarget or archerTarget.health <= 0:
# Set archerTarget to be the target that is returned by findStrongestTarget()
archerTarget = findStrongestTarget()
friends = hero.findFriends()
soldiers = hero.findByType("soldier")
# Create a variable containing your archers.
for i in range(len(soldiers)):
soldier = soldiers[i]
commandSoldier(soldier, i, len(soldiers));
# use commandArcher() to command your archers
hello you there I put my code
You did not write anything in it! Try to solve the level first and then send us your code and only then we will try to help you.
I restarted by accident
def commandSoldier(soldier, soldierIndex, numSoldiers):
angle = Math.PI * 2 * soldierIndex / numSoldiers
defendPos = {"x": 41, "y": 40}
defendPos.x += 10 * Math.cos(angle)
defendPos.y += 10 * Math.sin(angle)
hero.command(soldier, "defend", defendPos);
# Find the strongest target (most health)
# This function returns something! When you call the function, you will get some value back.
def findStrongestTarget():
mostHealth = 0
bestTarget = None
enemies = hero.findEnemies()
# Figure out which enemy has the most health, and set bestTarget to be that enemy.
# Only focus archers' fire if there is a big ogre.
if bestTarget and bestTarget.health > 15:
return bestTarget
else:
return None
# If the strongestTarget has more than 15 health, attack that target. Otherwise, attack the nearest target.
def commandArcher(archer):
nearest = archer.findNearestEnemy()
if archerTarget:
hero.command(archer, "attack", archerTarget)
elif nearest:
hero.command(archer, "attack", nearest)
archerTarget = None
while True:
# If archerTarget is defeated or doesn't exist, find a new one.
if not archerTarget or archerTarget.health <= 0:
# Set archerTarget to be the target that is returned by
findStrongestTarget()
archerTarget = findStrongestTarget()
friends = hero.findFriends()
soldiers = hero.findByType("soldier")
# Create a variable containing your archers.
archers = hero.findByType("archer")
for i, soldier in enumerate(soldiers):
commandSoldier(soldier, i, len(soldiers));
summonSoldier()
for i in range(len(soldiers)):
soldier = soldiers[i]
commandSoldier(soldier, i, len(soldiers));
# use commandArcher() to command your archers
commandArcher(archer);
I added some back on
You just put this. Try more because if I solve the level for you, you will not learn anything.
# Figure out which enemy has the most health, and set bestTarget to be that enemy.
# Only focus archers' fire if there is a big ogre.
wat do I put in-between here
I’m cant learn I have memory lose
Inbetween those lines you need to put q while loop which loops through the enemies comparing each of their healths’ to mostHealth and finding the strongest one. Like you did in the Sarven desert with coins.
Danny
1 Like