在网格上编程随机路径的最佳起点是哪里? [英] Where is a good place to start with programing a random path on a grid?

查看:81
本文介绍了在网格上编程随机路径的最佳起点是哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不确定从哪里开始,我不要求别人为我做这件事,但是我不确定如何做到这一点,所以如果有人可以指出正确的方向,那将是很棒的事情,我什么也找不到使用Google,这是我需要的:

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:

我需要创建一条从网格的一侧到另一侧的路径,但不是以最短的方式以最短的方式创建一条路径,我需要确保如果该路径与该路径的另一部分平行,则该路径至少是平行的相隔2个单位.

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.

提前感谢

推荐答案

我曾经编写过一个迷宫生成器,该迷宫生成器的创建过程如下:

I wrote a maze generator once, which started by creating the path through the maze as follows:

在y轴上拾取两个随机偏移,每边分别是y1和y2,然后在x轴上拾取随机偏移x.然后用(0,y1)到(x,y1),(x,y1)到(x,y2),(x,y2)到(w-1,y2)的直线连接两个点,其中w是宽度:

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.

凹凸看起来像这样:

之前:

 .....
 XXXXX
 .....
 .....

之后:

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

(我的ASCII艺术技能还有很多不足之处-希望您能理解.)

(My ASCII art skills leave a lot to be desired - I hope you get the idea).

这篇关于在网格上编程随机路径的最佳起点是哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆