Skip to main content
added 8 characters in body
Source Link
Theraot
  • 27.5k
  • 4
  • 52
  • 79

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.

 

Crucially, the dictionary won't store to 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 array 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 continues. 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 each point).

In fact, we are not in a hurry to check positions ahead. When the loop gets to them they can connect back (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. there are maze generation algorithms that can guarantee to generate a valid maze.

Crucially, the dictionary won't store two 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 id 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 continous. 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, we can connect them (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. There are maze generation algorithms that can guarantee to generate a valid maze.

 
fixed typos
Source Link
Pikalek
  • 12.5k
  • 5
  • 45
  • 52

Be aware that I came up with this approach becasebecause:

  • I'm keeping the savesame vein of what you were doing.
  • I think there is plenty for you to learn from it.

Be aware that I came up with this approach becase:

  • I'm keeping the save vein of what you were doing.
  • I think there is plenty for you to learn from it.

Be aware that I came up with this approach because:

  • I'm keeping the same vein of what you were doing.
  • I think there is plenty for you to learn from it.
added 559 characters in body
Source Link
Theraot
  • 27.5k
  • 4
  • 52
  • 79

Addendum: The random-walk is random™. Nothing prevents it from going over cells it already went over. So keeping a list of visited cells (similar to breath-first search) can allow you prevent that. Similarly, if you use a weighted random (look it up), you can make it more likely for it to pick a position that is closer to the source (by vector distance). And the closer is a cell to the source the more likely there is a path from to source to that cell (that, by the way, is an heuristic). This improvements will make the carving process go faster.

Addendum: The random-walk is random™. Nothing prevents it from going over cells it already went over. So keeping a list of visited cells (similar to breath-first search) can allow you prevent that. Similarly, if you use a weighted random (look it up), you can make it more likely for it to pick a position that is closer to the source (by vector distance). And the closer is a cell to the source the more likely there is a path from to source to that cell (that, by the way, is an heuristic). This improvements will make the carving process go faster.

Source Link
Theraot
  • 27.5k
  • 4
  • 52
  • 79
Loading