Amable-Valdes / Prolog-Mazes

Algorithms to solve small mazes with prolog

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

When input other mazes an error is produced.

Manopphysics opened this issue · comments

The mazes that you have given in your example file works perfectly, but when I download other maze images from google such as this:
mazeC

The python Maze Manipulation Script produces this error:
Traceback (most recent call last): File "<pyshell#17>", line 1, in <module> translate_image_into_rules("mazes/mazeC.png") File "C:\Users\name\Desktop\python\Project\Prolog-Mazes-master\Mazes Manipulation Script.py", line 189, in translate_image_into_rules maze = translate_image_to_maze(img) File "C:\Users\name\Desktop\python\Project\Prolog-Mazes-master\Mazes Manipulation Script.py", line 155, in translate_image_to_maze maze[i][j] = float(label) TypeError: float() argument must be a string or a number, not 'NoneType'

This is understandable there might be some problems with the image quality and the color from other sources.

My question is, How to generate other mazes like in your example that works perfectly with the program?

Thanks a lot!

Hi!

These questions were answered by email long ago. Now I will answer it on Github for everyone.

Bug

Bug solved: There was a function that did not return anything when we expected to return a value.
The function was translate(vectorRGB), which translates an RGB vector into a label that the program can understand.

Considerations when running this program

You can test other internet mazes or make them by yourself, but you must count on this:

Only 4 colors are allowed:
vectorRGB[0] > 150, vectorRGB[1] > 150, vectorRGB[2] > 150 -> White, empty space where you can move.
vectorRGB[0] < 150, vectorRGB[1] > 150, vectorRGB[2] < 150 -> Green, the end of the maze.
vectorRGB[0] < 150, vectorRGB[1] < 150, vectorRGB[2] > 150 -> Blue, the beginning of the maze.
vectorRGB[0] == 0, vectorRGB[1] == 0, vectorRGB[2] == 0 -> Black, a wall.
none of that -> Wall

I recommend that you have only 1 pixel of blue, otherwise there could be problems in the execution of the program.

If you have other colors (several green or blue with more or less intensity) strange things will happen. This was the case you presented; The program did not expect a green value (closer to the white value) and translated into an error. Now the label is a Wall if the value is not expected.

The maze path width must be 1 pixel thick. This is important because in this program every maze with generated movements is a state and we move to one state or another every movement:

tree_normal (1)
Figure 1: The states generated are a tree.

If it is 2 pixels thick, the states that can be generated increase and it is a real problem because each state it creates has a similarity to another state, contaminating the memory. Even worse, because each state that it creates can go backwards and that can be considered a new state, when we know that we will not find the solution on that path.

tree2 (3)
Figure 2: Tree generated that has similar states that don't help the program to solve the maze.

New mazes

You can generate new mazes here with a path width of 1 pixel. If you have your own mazes, you must translate those mazes to a thickness of 1 pixel, and this has several difficulties...

Other solutions (not implemented in this project)

The spacial representacion of a maze can be represented like a Quadtree, and in this way it can perform other operations with the maze. Unfortunately, this project in Prolog is simple and we only work on matrix representations. In addition, in prolog the spatial representation of a quadtree could be a challenge because in prolog the memory is easily terminated. I would implement this in a imperative language, but not in prolog.

Another easier option is to implement the A * algorithm and look for a useful heuristic that eliminates useless states (such as Euclidean distance, for example). Implementing the A * algorithm in prolog is a bit more difficult than what was implemented in this project, but it is possible.

I hope all this information has helped you, if you have any other questions, I will be happy to answer you.

Thanks a lot for solving this issue and posting it on GitHub although you already answered in the email, Thanks, I shall close this issue now.