Crucially, the dictionary won't store totwo elements on the same key. There will not be duplicated keys. If I do this:
If you want to make sure you get the shortest one, you want to implement ]Dijkstra's algorithm. The reason you don't see game developers talking about Dijkstra's algorithm as much is because it is exhaustive, in fact it compute the shortest path between all the points.
Here the arrayid is the number of the row multiplied by the length of the row (which gives you how many elements were before the start of the row) plus the position inside the row.
That also highlights that ids don't need to be continuescontinous. It is more important to be able to compute the id from the coordinates (which is why I didn't just have an id variable start at zero and increment it with each point).
In fact, we are not in a hurry to check positions ahead. When the loop gets to them they, we can connect backthem (the connection is bidirectional by default). Thus, we can limit ourselves to position that we have already passed.
You are checking if the maze is valid. thereThere are maze generation algorithms that can guarantee to generate a valid maze.