Added placing objects

This commit is contained in:
Magdalena Wilczyńska 2019-05-19 18:15:25 +02:00
parent 7664888597
commit b567eec536

View File

@ -1,4 +1,4 @@
import random, datetime
import random, datetime, itertools
def GenerateMap():
#generate random empty map
@ -137,28 +137,57 @@ def GenerateMap():
print("Route: "+str(route))
print("Intersections after modification: "+str(intersections))
#EXPERIMENTAL
#decide if modified route should disappear or just have some field removed
f = random.randint(0,100)
"""f = random.randint(0,100)
if(not(f % 2 or f % 5)):
route.remove(random.choice(route))
route.remove(random.choice(route))"""
#remove modified route from roads
roads = [c for c in roads if c not in route]
print("----------------------------")
print(width, height)
print(x_roads_count, y_roads_count)
#insert roads into the grid
for coord in roads:
#print(coord)
grid[coord[1]][coord[0]] = "R"
for g in grid: print(g)
"""OBJECTS BE HERE"""
#Select area that possibly could hold objects
objects_area = []
for r in roads:
objects_area.extend(([r[0]+1,r[1]],[r[0]-1,r[1]],[r[0],r[1]+1],[r[0],r[1]-1]))
objects_area = [c for c in objects_area if c not in roads] #remove coords that contain roads
objects_area.sort()
objects_area = [objects_area[i] for i in range(len(objects_area)) if i == 0 or objects_area[i] != objects_area[i-1]] #remove duplicates
houses_area = [i.copy() for i in objects_area]
for o in objects_area:
if(o[0] < 0 or o[1] < 0 or o[0] >= width or o[1] >= height):
houses_area.remove(o) #remove coords outside borders
#place dumps
dumps_to_place = ["B","Y","G"]
while(len(dumps_to_place) > 0):
dump_coords = random.choice(houses_area)
houses_area.remove(dump_coords)
grid[dump_coords[1]][dump_coords[0]] = dumps_to_place[0]
dumps_to_place.remove(dumps_to_place[0])
#leave random coordinates
houses_to_leave_count = len(houses_area)//4
while(len(houses_area) > houses_to_leave_count):
houses_area.remove(random.choice(houses_area))
print("================================")
#insert houses into the grid
for coord in houses_area:
print(coord)
grid[coord[1]][coord[0]] = "H"
#Select position for GC
GC_position = random.choice(roads)