Started road generator
This commit is contained in:
parent
b6bcb8be46
commit
4c9b2e95c5
44
MapGenerator.py
Normal file
44
MapGenerator.py
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
import random
|
||||||
|
|
||||||
|
#generate random empty map
|
||||||
|
width = random.randint(4,7) #up to 15
|
||||||
|
height = random.randint(4,7) #up to 10
|
||||||
|
grid = []
|
||||||
|
|
||||||
|
row = []
|
||||||
|
for i in range(width):
|
||||||
|
row.append('G')
|
||||||
|
for i in range(height):
|
||||||
|
grid.append(row.copy())
|
||||||
|
|
||||||
|
#define number of roads for each axis
|
||||||
|
x_roads_count = random.randint(2, max(width//2.3,2))
|
||||||
|
y_roads_count = random.randint(2, max(height//2.3,2))
|
||||||
|
|
||||||
|
#select coords of roads for x
|
||||||
|
x_roads_coordinates = [] #output coords
|
||||||
|
possible_coordiantes = [i for i in range(width)] #coords to choose from
|
||||||
|
|
||||||
|
for i in range(x_roads_count):
|
||||||
|
coordinate = random.choice(possible_coordiantes)
|
||||||
|
road_area = [coordinate-1, coordinate, coordinate+1]
|
||||||
|
possible_coordiantes = [i for i in possible_coordiantes if i not in road_area] #removes road and surrounding coords (total 3 coords) from possible coords
|
||||||
|
x_roads_coordinates.append(coordinate)
|
||||||
|
print(x_roads_coordinates)
|
||||||
|
|
||||||
|
#select coords of roads for y
|
||||||
|
y_roads_coordinates = [] #output coords
|
||||||
|
possible_coordiantes = [i for i in range(height)] #coords to choose from
|
||||||
|
|
||||||
|
for i in range(y_roads_count):
|
||||||
|
coordinate = random.choice(possible_coordiantes)
|
||||||
|
road_area = [coordinate-1, coordinate, coordinate+1]
|
||||||
|
possible_coordiantes = [i for i in possible_coordiantes if i not in road_area] #removes road and surrounding coords (total 3 coords) from possible coords
|
||||||
|
y_roads_coordinates.append(coordinate)
|
||||||
|
print(y_roads_coordinates)
|
||||||
|
|
||||||
|
print(width, height)
|
||||||
|
print(x_roads_count, y_roads_count)
|
||||||
|
for g in grid: print(g)
|
||||||
|
|
||||||
|
print("++++++++++++++++++++++++")
|
Loading…
Reference in New Issue
Block a user