My code is fine, it fineshes the level (as long as those death frisbee thingies don’t hit a peasant) but it glitches out and my hero does this wierd turning back and fourth thing, as if he stein one direction and then another.
c = 0
while True:
for friend in hero.findFriends():
if friend.type == "soldier":
enemy = friend.findNearestEnemy()
if enemy:
hero.command(friend, "attack", enemy)
else:
hero.command(friend, "move", {"x" : 80, "y" : 40})
item = hero.findNearestItem()
if item:
hero.move(item.pos)
# If you have enough gold, summon a soldier.
if hero.gold >= hero.costOf("soldier") and c < 5:
hero.summon("soldier")
c += 1
elif c > 4:
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)
else:
hero.move({"x" : 80, "y" : 40})
i tried putting “if item and c < 5” in the code but then the hero loses the level, even thought this should make him arrive to fight earlier. What is wrong here?
c = 0
while True:
array = hero.findFriends()
for friend in hero.findFriends():
if friend.type == "soldier":
enemy = friend.findNearestEnemy()
if enemy:
hero.command(friend, "attack", enemy)
else:
hero.command(friend, "move", {"x" : 80, "y" : 40})
item = hero.findNearestItem()
if item and len(array) < 16:
hero.move(item.pos)
# If you have enough gold, summon a soldier.
if hero.gold >= hero.costOf("soldier") and c < 5:
hero.summon("soldier")
c += 1
elif c > 4:
enemy = hero.findNearestEnemy()
if enemy:
hero.attack(enemy)
else:
hero.move({"x" : 80, "y" : 40})
fixed the code but id still like to make it make more sense, what i did here is count the peasants (11) and make 5 soldiers (total 16, which is why array has to be less than 16) which i shouldn’t have to do because the variable c should work the same yet it doesnt.
The second to last code you posted pretty much solves the level, you just need to keep the hero on the left side of the map. If you move the hero to the right then headhunters and a shaman appear, whereas if you just stay on the left collecting gold, only scouts turn up, and one by one over the level so that the soldiers can easily kill them.
Danny
also,
the last peice of code I posted now works for some reason. I solved it days ago but that was just replaying the same code over and over again. It now works without pressing the ‘submit’ button.