Where is a good place to start with programing a random path on a grid?

前端 未结 2 678
暖寄归人
暖寄归人 2021-01-27 01:30

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

相关标签:
2条回答
  • 2021-01-27 02:04

    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).

    0 讨论(0)
  • 2021-01-27 02:17

    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.

    0 讨论(0)
提交回复
热议问题