The Labyrinth - Puzzle discussion

Just like others, I passed all the tests in the IDE but failed the 2nd when submitting. It just crashed instantly but works on more complex positions.

I tried a few things but it’s really hard to debug so I’ll give up for now and accept the 87%

Did you try watching the replay of that validator, get its input parameters there, and debug offline? You will not be able to see any simulations, but at least you can see the paths, outputs and maybe errors which your code generates.

1 Like

I actually didn’t think about this. I spent some time recreating the conditions and I found the bug !
(Just an out of bounds bug due to Rick being in the before last row which never occur in other tests)

Thank you very much for your advice, I finally hit 100% !

2 Likes

I don’t know why, my code passed all test cases and all validators, except validator 7.
I saw map of the problem and I tried myself pathfinding is works well as i expected. Then i saw replay of the game Shortpath is not works as i expected . Any ideas?

Not sure what you mean by “shortpath is not works as i expected”.

Perhaps you can share the replay of the failed case here?

1 Like

Sure, Coding Games and Programming Challenges to Code Better
But, the path i got when i tried myself from the map.

Screenshot (500)

‘*’ - represents the path i got.
(sorry for my bad english)

The issue is that you did not return to the starting position using the shortest path, which is via the first row in the last part of the return journey. And the reason is that you did not explore the whole maze fully before you reached the control room, so you had no idea that the top path existed.

Bear in mind that you have ample time to explore the maze fully, to clear out all the question marks, before returning to the starting position. So, explore fully first, before calculating the shortest path.

1 Like

Thank you very much, finally I realised my mistake…

1 Like

Hi there! I choose to first explore till he finds the control room and then try a path planning algorithm to join ‘C’. But while exploring it always hit the ground or the ceiling no matter the conditions (even if 0 <= kr <R-5). Did anyone have the same problem? Do you have an idea on this?

You may refer to my comment above: https://forum.codingame.com/t/the-labyrinth-puzzle-discussion/59/113

Hi. I have almost completed this puzzle.
My code fails only in 4 5 6 tests.
Code seeks the closest ? and moves the player next to it if C is not visible
as soon as C is visible code switches the target to C and moves there
If there is a clear path at the time of C is first visible there is no problem
But if there is no clear path between them code acts weirdly and tries to pass the walls
I coded : if it cant find a valid path change to search ? and this time it does not seek the closest ? but tries to search ? behind the walls next to C
the code gets longer and i started to gel lost :slight_smile:
any help appreciated

Two suggestions for you:

  1. Clear out all the question marks first. You don’t have to rush to the control room, because once you do that, the timer for the journey back will start. If you have not fully cleared out all the question marks yet, you may not know the existence of a shorter path for you to beat the timer.

  2. You may want to debug your code offline. That way you can use your local IDE instead of CG IDE, which probably provides more flexibility for debugging, e.g. stepping into the code line by line, and keeping track of how the code is executed and how the variables change.

1 Like

How do you chek if all fog of war (?) has cleared and map has been explored ?
There are some ? outer border of map that cannot be reached. So i can t use
if there are no more “?” goto Control room

If there are no more reachable “?” goto Control room

I have completed it. Thanks.

On test 6, the allowed time before the alarm is not enough: depending on the actual version of the map and the neighboring order used in the code to explore the map (while searching the control command), it may happen that the user triggers the alarm on his way back while it’s technically not possible anymore to go back in time.
I got a case where I’d have needed 2-3 more rounds, but this could have been even more, because there was still a lot of unknown area. This means that, currently, this test succeeds/fails randomly by just changing the neighboring order in the search… This is a bad test, so.

The allowed time is always enough, if you explore all the unexplored area in the most efficient way. Don’t go to the control room unless you have fully explored wherever you can go.

oh, right, I forgot the countdown starts only when acquiring the control room. :+1:

At the moment I start my third week trying to solve this.
When I locally try out stuff, I can see the reachable nodes being found by my implementation of the BFS.

However when applying my code online, it somehow doesn’t work. I started over countless times, asked a lot of question with Co Pilot.

So in short a few questions, that will maybe clarify some things:

  • do I need to initialize my graph object in or outside the infinite loop?
  • do I need a ‘recursive approach’ with BFS? passing in a ‘pathfind queue’
    since we are discovering per each iteration I can never know what lies ahead.

for the most simple case it’s T… that is visible.

  • should I ‘navigate’ to the last . (hollow) or the first seen from my position? Since when the point coordinates from, to result into a string direction that I push to the stack, I just can read 1 from the stack before the iteration(while) continues.

Maybe I am thinking to difficult and this is not all to difficult. To me at least it is and fortunately I have learned a lot more from graphs, BFS and likewise algorithms since the last time I attended my education facility back in the 2000’s.

Any pointers (pun intended) are appreciated.

Have a nice day,

Best regards,

Thuredrith078

  • do I need to initialize my graph object in or outside the infinite loop?

Either way may work, depending on how you deal with the graph object.

  • do I need a ‘recursive approach’ with BFS? passing in a ‘pathfind queue’
    since we are discovering per each iteration I can never know what lies ahead.

When you are still exploring the area and you haven’t moved to the control room, you’re given plenty of time to explore the area to the most possible extent. So, you just have to explore the nearby unknown cells; you don’t have to know what lies far ahead.

  • should I ‘navigate’ to the last . (hollow) or the first seen from my position? Since when the point coordinates from, to result into a string direction that I push to the stack, I just can read 1 from the stack before the iteration(while) continues.

Before you arrive at the control room, explore as much as you can, because once you actually go to the control room, you must go there using the shortest path or it’s likely you’ll run out of time. If you don’t explore adequately, you may find a suboptimal path instead. So, the target is: clear out as much ‘?’ as you can unless that spot is unreachable. Whether it’s the first . or the last . is irrelevant, just move to the nearest ‘?’.