My maze solver won’t backtrack!

Project link:

1-sentence description of the issue:

My maze solver won’t backtrack!

What do you want your code to do?

My maze solver to backtrack.

What is the code currently doing?

Not backtracking and getting stuck.

Screenshots:

11 Likes

My maze solver goes into debug mode when it gets stuck. Also can someone add comments to it as it’s been so long since I started this that I don’t remember how it all works. :man_shrugging:
Ps. I started this before comment blocks or the new inputs to custom blocks were added. PPs. Sorry my code is messy.
Also @omtl look at the post rite above this.

7 Likes

I saw that it got to a dead end. It should recognize going up, down, left and right.
If it gets stuck, it should go the opposite direction it was going before.
:green_square: |
—— |
:hatched_chick: |

In this example, this is a problem. The chick would move forward one tile, then another. There is a empty space so the chick would go up. It repeats until it sees the end. Your so should use both of these examples in the maze. If it gets stuck, start over.

5 Likes

Read how to use.

3 Likes

no offence but how are we supposed to understand your code if you dont even understand? /nm /lh

2 Likes

I know right but I tried to make it as easy to understand as possible without comment blocks. Just look at the code.

2 Likes

That’s what I’m trying to do. It’s supposed to go backwards until it can try another direction then go in that new direction.

3 Likes

try @/CodeHelp next time

7 Likes

Ok @CodeHelp please see op.

5 Likes

What does backtrack mean?

3 Likes

go back in the already run track

3 Likes

Ok, I haven’t looked at the code of your project, but if it helps, I’ll show you a maze project I made before. It’s a little different from yours, as it’s generating a maze instead of solving one, but maybe you’re looking for a similar tracking system where a dot knows where it’s been

In this project, you can set the DEBUG MODE to 1 in the “Path Draw” object to see how the maze is generated instead of playing the game.

@Mathematics2 is this the right topic, btw?

4 Likes

Yes this is the right topic. Also the solver already knows where it’s been. I need help using that data.

3 Likes

So, this is going to be more conceptual (as you understand the code of your project better than I do), but here’s what you need to do.

  1. The solver object (I’ll refer to as “solver”) reaches a dead end.
  2. Solver will see which tile it came from, and move to that tile.
  3. Solver will check if it hasn’t visited any of those tiles. If any tile has not been visited, clear that and restart process. If all tiles have been visited, proceed to step 4
  4. Now that all tiles around solver have been visited or backtracked, solver will see the tile it came to get to the current tile, and go to that tile.

So, what you need it seems is 3 different tracking states:

  1. Never visited.
  2. When going over a path the first time, “visited”
  3. When backtracking, leaving a visited tile should turn that tile into a “back-tracked” tile.

This way, you can go back by going back over visited tiles, but you will never touch a tile if it has been backtracked.

Hopefully that makes sense

4 Likes