jeudi 10 octobre 2019

How could I generate 100 grid map?

I have built a map that generates obstacles, start point and endpoint randomly for pathfinding algorithm. As shown below:

import random
import numpy as np

x = [[random.uniform(0,1) for i in range(50)]for j in range(50)]
grid = np.array([[0 for i in range(len(x[0]))]for j in range(len(x))])

for i in range(len(x)):
    for j in range(len(x[0])):
        if x[i][j] <= 0.7:
            grid[i][j] = 0
        else:
            grid[i][j] = 1

init = np.random.randint(0, high = 49, size = 2) #Start location 
goal = np.random.randint(0, high = 49, size = 2) #Our goal 

# clear starting and end point of potential obstacles
def clear_grid(grid, x, y):
    if x != 0 and y != 0:
        grid[x-1:x+2,y-1:y+2]=0
    elif x == 0 and y != 0:
        grid[x:x+2,y-1:y+2]=0
    elif x != 0 and y == 0:
        grid[x-1:x+2,y:y+2]=0
    elif x ==0 and y == 0:
        grid[x:x+2,y:y+2]=0

clear_grid(grid, init[0], init[1])
clear_grid(grid, goal[0], goal[1]) 

As shown above, this snippet will give me one environment (grid map) with random obstacles, start point and endpoint. I need to create 100 environments (grid maps) and every environment of these 100 gives me random obstacles, start point and endpoint. Could I get any assistance, please?.




Aucun commentaire:

Enregistrer un commentaire