How to check if a randomly generated level is possible to complete?

I am making a maze game where the player navigates randomly generated mazes. I have manage to create a level generation system (with simple code as i am new to coding) where it has a 50% chance of spawning squares in each space in the grid. The player then has to get to the other side like a classic maze.
You may be noticing that if i generate every level with a 50% chance of an obstacle spawning on each square - it will be impossible for the player to reach the end every time. However, i want there to be a mechanic where the player has a limit amount of ‘dashes’ where they can pass through an obstacle of one block thick to reach the end. This will allow the player to create their own path but still keeping a level of difficulty as larger obstacles/diagonals will not be bypassable.
The problem with normal, randomly generated mazes is that not every level is possible, a block might be blocking the start or end, there might not be a possible path to the end etc. I was trying to implement a system of checking if a level was possible using a tester which detected if a block was blocking it etc. but soon gave up as the preview kept freezing on a black screen. I then tried pathfinding but i wasn’t able to make it work either. Additionally, all these methods did not take into account the mechanic i want there to be which adds another level of difficulty to the code.
I was wondering if there was a simpler way to check if a level is possible in general, but also if someone really smart could help me devise some code to not only see if a level is physically passable, but also see if there is at least one path possible using my mechanic of bypassing 3 or so obstacles per level.
I apologise for my ignorance, and welcome any help, In addition i have attached a screenshot of an example level.
(Player in grey, End in green, Obstacles in red).

1 Like

*Player is in yellow

Or it would figure out the amount of ‘dashes’ needed to complete the level this way, and give the player that same amount. This way it could range from 7 dashes to 3 per level and if the player doesn’t find the ‘perfect way’ A.K.A. the way the system figured the level out, they would’ve failed the level.
Eg. in the screenshot i have attached to the first post, the level can be beat by passing through 7 blocks without going through diagonals or blocks that are more than 1 tile thick. This would mean the player would be given 7 ‘dashes’ to beat the level and find the optimal path.

Are you or have you used the maze generator extension?

https://wiki.gdevelop.io/gdevelop5/extensions/maze-generator/

I think you’d need some type of AI to run through the maze and figure out the most efficient way.

But maybe approach it a different way - create a solvable maze and then plonk on a few extra blocks along the solution route.

Fool question: physic engine in GD don’t go with water, isn’t it?
Otherwise, it should be easier to use water descending in the labyrinth to indicate if the solution exists or not.
But i am dreaming!

In classic programmation, in the past, we used BackTracking method.

Xierra

1 Like

The thing is, i don’t want it to be a classic maze. Think of my idea to be more of a puzzle, randomly generated where the player has to solve it with certain moves, not a ‘follow a path’ kind of maze. It would still need to check if levels are possible.
Thanks for the suggestion though.

@MrMen Is there a way to create such an AI in Gdevelop?
Otherwise i could try your other suggestion.
Thanks for your help.

Possibly, but it’d probably take a lot of work. And I wouldn’t know where to start on that one.

1 Like

You could start with the maze extension. If you don’t use it then maybe you can study it’s functions. It has a builder and solver.

The pathfinder might be one way. Add blocks, check for path, add blocks check for path. You could add a certain minimum number of blocks and also add a certain number of blocking blocks.

It might be easier to create a path with temporary objects and then place blocks around it. Add extra blocks as needed.

1 Like