silverua / slay-the-spire-map-in-unity

Implementation of the Slay the Spire Map in Unity3d
MIT License
288 stars 68 forks source link

Suggestion #18

Closed hojjatjafary closed 1 year ago

hojjatjafary commented 1 year ago

Hi, Thank you for sharing your code, We wanted to generate similar map in our project and found this project but seems the path generation algorithm has some issues, the first one is that the generation can be failed after 100 attempts, also this attempts is not good from the performance point of view. We designed an algorithm that resolves these issues. Here is our algorithm: Generate some random starting nodes.(same way you generate preBossPoints) Generate some random ending nodes. Connect these starting and ending points together by a random path. Algorithm ends when all starting and ending points connected to each other.

The core point of the algorithm is that how to connect two predetermined nodes with random path. We can generate candidate Xs such a way that the generated path finally land in specified location by imposing a simple rule. The rule is that the horizontal distance of candidate position to ending node should be lesser or equal to the vertical distance of it to the ending node. In this way the points that the ending node is not reachable from will not be a valid candidate and will not contributed in random selection. Our Path code is written with a simple for loop from the level of starting point to the level of ending point. Hope this help you improve your code, Good luck.

silverua commented 1 year ago

Thanks for the tip. I think, rewriting that would be great. I will look into it. If you have some code snippets, please share. Algorithm description that you posted is really good. Appreciate it.

hojjatjafary commented 1 year ago

Our code is written in C++ for the Unreal Engine but I will try to write it in C# too, and will send you a pull request.

silverua commented 1 year ago

Thank you!!!