Here’s the problem: every time my hero collected 73 coins, the lower area on the right stopped producing coins. My hero could only attack the ogres.
Even if I’m able to solve this problem through placing flags, but I want to achieve this goal by writing code.
So I finished the function “notWait()”. The coordinate inside the function is the coordinate of the middle of the map. After hero walked there, he can find other coins and go to that part.
But this made a infinity loop. I don’t understand.
Please tell me why. Or just offer another idea which can solve the problem~ Thanks!
Hi @Hammer, could you message me your whole solution so I could have a better understanding of your code? it’s hard for me to tell what went wrong from the screenshot.
Please do not post final solutions. This is counter-productive toward the goal of this forum. Posting answers takes the whole point out of the game. Also, please format your code correctly. It should look like this:
while True:
enemy = hero.findNearestEnemy()
if enemy:
hero.say("Run to the nearest corner.")
else:
hero.say("My code is formatted properly!")
Hi @Hammer, like @TheDemonPrince said, it is not encouraged to post solution code directly, (If it’s a code that is not working I think it should be fine. However, you didn’t format your code properly I guess that’s why it gets edited even if it’s not a solution.
Use pre-formatted text to post the code. You can find it in the toolbar above the input area.
Also it helps to add the level link to the post, it will take some time to locate the level you mentioned, like this https://cn.codecombat.com/play/level/backwoods-treasure?
OK, The way I did this level is by defining 3 functions:
collect coins by certain priority
if there is not any coin the hero can see, let the hero move to the center of the map where he/she can have a clear view of the whole area (you mentioned that you have the google with infinity range, so maybe define a range for it? )
a function which allow the hero to attack nearest enemy whenever they spwan
I suggest you re-write your solution and change the function “notWait()”, it feels to me that this add un-necessary complexity to the level.
The second one is exactly what I want! “let the hero move to the center of the map where he/she can have a clear view of the whole area”. You inspired me that I could set a range because I can SEE the coin but unable to COLLECT it.
Thank you very much.