Cavern Survival Code


(Working code / solution removed)

Above is my code for Cavern Survival. I cant find a way to make it better. Also, may someone please help me on the code needed to command soldiers? Thanks, TheDemonPrince


My name in CodeCombat is TheSavageCoder


Please do not post final solutions / working code. The purpose of this board is to help people learn and simply providing/posting completed solutions is counterproductive to that goal. The best way to get assistance with a level that you’ve completed but want to improve would be to create a post - sans the code - and explain that you would like someone who can help improve it to respond so you can send a private message with your code to them. There are many people here willing and able to help.

Also, in the future when posting your non-working code and requesting assistance fixing it, copy it from the game and be sure to use the </> button so that it it is formatted properly. If you use the </> button correctly, your code should look like this:

while True:
    enemy = hero.findNearestEnemy()
    if enemy:
        hero.say("My code is formatted properly")

If it doesn’t look like the code above, you’re doing it wrong and we can’t see the structure of the code to troubleshoot whether or not that is the issue. Use the </> button and help us help you. This works when sending a private message as well. Thank you and welcome to the board.


to command soldiers,first you need to make a friends variable using hero.findFriends(), then you need to loop over your friends (i would recommend using a for loop) and in the loop do the following in order

make a friend variable and make it’s value friends[i]

make an enemy variable and make it’s value friend.findNearestEnemy()

check with and if condition that there is an enemy to attack it with the soldier using the command function which looks like this


and that’s it


Thank you, I will make sure not to do that again.


This is very helpful. Thanks