Hello, I have been working on this level for a while now but can’t seem to keep all of the soldiers alive, the same one always dies, does anyone have any suggestions?
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)
self.command(soldier, "defend", defendPos);
pass
def findStrongestTarget():
mostHealth = 0
enemies = self.findEnemies()
enemyIndex = 0
while len(enemies) > enemyIndex:
enemy = enemies[enemyIndex]
if enemy:
enemyIndex += 1
if enemy.health > mostHealth:
mostHealth = enemy.health
bestTarget = enemy
if bestTarget and bestTarget.health > 15:
return bestTarget
else:
return None
pass
def commandArcher(archer):
nearest = archer.findNearestEnemy()
if archerTarget:
self.command(archer, "attack", archerTarget)
elif nearest:
self.command(archer, "attack", nearest)
archerTarget = None
while True:
if self.gold > self.costOf("soldier"):
self.summon("soldier")
if not archerTarget or archerTarget.health <= 0:
archerTarget = findStrongestTarget()
friends = self.findFriends()
soldiers = self.findByType("soldier")
archers = self.findByType("archers")
for i, soldier in enumerate(soldiers):
commandSoldier(soldier, i, len(soldiers));
for i in range(len(archers)):
archer = archers[i]
commandArcher(archer)
Please do not revive dead topics unless you have a similar issue. @CranKeD_Wired hasn’t been on the forum for almost a year, so there is a pretty good chance that he will not even see your question.
@AnSeDra is currently suspended so, he/she will not see your message. AnSeDra puts Andrei at the end of his sentence because (I’m assuming) that is his/her name.
Lydia