将网格位置增加一个数字,随机分配在X&amp上; y那个数字
continue
I have created an path finding algorithm visuliser using pygame, that shows A* Vs. Dijkstra's Algorith.
the start node,end node and obstacles are all randomly positioned as such
def generate_num(x, y):
return randint(x, y)
....
....
for x in range(0, density):
row_pos = generate_num(0, rows - 1)
col_pos = generate_num(0, rows - 1)
node = grid[row_pos][col_pos]
if not start and node != end:
start = node
start.makeStartNode()
elif not end and node != start:
end = node
end.makeEndNode()
elif node != end and node != start:
node.makeObstacle()
in order to evaluate, my algorithms I am constraining the distance between the start and end node (for small, medium and large) and thus need to make the end node eg (10,30,50) grid blocks away.
however i do not want it to be evenly spread across grid[x][y]
i would like it to be random.
so if distance is set to 50, grid[x][y]
could be grid[17][33]
or grid[10][40]
or grid[25][25]
but will always add up to being 50 nodes away
the makexxxNode()
function simply changed the colour of the the node to identify its type visually.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
it was as simple as what @hilberts_drinking_problem stated
y = 50 - x
as x is random number.