问题
Im not sure where to start with this, Im not asking for someone else to do it for me but im not sure how to do it so if anyone can point me in the right direction that would be great, i cant find anything using google, here is what i need:
I need to create a path from one side of the grid to the other, but not in the shortest in a random way, i need to make sure that if the path is parallel to another part of the path that it is atleast 2 units apart.
thanks in advance
回答1:
I wrote a maze generator once, which started by creating the path through the maze as follows:
Pick two random offset on the y axis one on each side, y1 and y2, then pick a random offset on the x axis, x. Then connect the two points with straight lines from (0, y1) to (x, y1), (x, y1) to (x, y2), (x, y2) to (w-1, y2) where w is the width:
x
.....
y1 XXX..
..X..
..XXX y2
.....
|-w-|
Then, I repeatedly added 'bumps' to the initial path until it had a desired length, e.g. twice the original length.
A bump looks like this:
Before:
.....
XXXXX
.....
.....
After:
.....
XX.XX
.XXX.
.....
This type of transformation can be applied anywhere on the current path in any of the four directions where there's space available.
(My ASCII art skills leave a lot to be desired - I hope you get the idea).
回答2:
This appears to be a good starting point: http://www.csharpcity.com/reusable-code/a-path-finding-library/ It is a good foundation that can likely be easily applied to your needs.
来源:https://stackoverflow.com/questions/11165910/where-is-a-good-place-to-start-with-programing-a-random-path-on-a-grid