'Increase Grid position by a number, randomly split over x & y that equal that number
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.
Solution 1:[1]
it was as simple as what @hilberts_drinking_problem stated y = 50 - x as x is random number.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Xray25 |
