OK, you’re far enough through CoCo now that to some extent you’re going to have to solve the problems by yourself - you’ll learn by trying things to see if they work, even if it’s frustrating. Each time you change the code, run it to see what happens and whether that was what you wanted. It’s a skill you’ll keep needing as you get better at coding!
One thing from your code - you still have the hero command move statements in pairs, so they won’t work as you want them to - you’ll have to separate them and write code to say which one happens when.
# Вы можете находить друзей сквозь стены. Но не врагов.
# Берегитесь гладких, скользких ледяных участков!
def lowestHealthFriend():
lowestHealth = 99999
lowestFriend = None
friends = hero.findFriends()
friends.append(hero.findByType('paladin')[0])
for friend in friends:
if friend.health < lowestHealth and friend.health < friend.maxHealth:
lowestHealth = friend.health
lowestFriend = friend
return lowestFriend
while True:
flag = hero.findFlag("green")
enemy = hero.findNearestEnemy()
if flag:
if hero.isReady("blink"):
hero.blink(flag.pos)
hero.pickUpFlag(flag)
else:
hero.pickUpFlag(flag)
else:
if enemy:
if hero.isReady("throw") and hero.distanceTo(enemy.pos) < hero.throwRange:
hero.throw(enemy)
elif hero.isReady("shadow-vortex"):
hero.shadowVortex(hero.pos, {"x": 74, "y": 15})
elif hero.isReady("wall-of-darkness"):
hero.wallOfDarkness([{"x": 22, "y": 24}, {"x": 22, "y": 5}]);
elif hero.canCast("chain-lightning", enemy) and enemy.type == 'witch':
hero.cast("chain-lightning", enemy)
else:
hero.attack(enemy)
friends = hero.findFriends()
for friend in friends:
enemy = friend.findNearestEnemy()
if friend.type == 'archer':
if enemy.type == 'witch':
hero.command(friend, "attack", enemy)
else:
if friend.pos != {'x': 31, 'y': 58}:
hero.command(friend, "move", {'x': 31, 'y': 58})
else:
hero.command(friend, "move", {'x': 49, 'y': 58})
elif friend.type == 'paladin':
lowestFriend = lowestHealthFriend()
if lowestFriend and hero.findByType("paladin")[0].canCast('heal'):
friend.cast('heal')
if enemy.type == 'witch':
hero.command(friend, "attack", enemy)
else:
if friend.pos != {'x': 31, 'y': 58}:
hero.command(friend, "move", {'x': 31, 'y': 58})
else:
hero.command(friend, "move", {'x': 49, 'y': 58})
elif friend.type == 'soldier':
if enemy.type == 'witch':
hero.command(friend, "attack", enemy)
else:
if friend.pos != {'x': 31, 'y': 58}:
hero.command(friend, "move", {'x': 31, 'y': 58})
else:
hero.command(friend, "move", {'x': 49, 'y': 58})
I don’t actually know, why my friends keep dying.The witch kills them. @jka2706, I come to this forum when I can’t find any ideas.I passed many levels by myself.But some levels are too difficult.That’s why I can’t solve them myself.
Sometimes it’s good idea to start from the blank page.
I complete this level with strategy based on time-depending functions to command allies and hero. Not the perfect variant I think. But I would maybe suggest you to use the same tactics.
And xython is right, searching the forum for this level related topics may help also.