128 lines
6.7 KiB
Python
128 lines
6.7 KiB
Python
import pygame as pg
|
|
import random
|
|
from request import Request
|
|
|
|
|
|
STRAIGHT_IMG = pg.image.load("Tiles/Straight.jpg")
|
|
STRAIGHT_VERTICAL = pg.transform.scale(STRAIGHT_IMG, (50, 50))
|
|
STRAIGHT_HORIZONTAL = pg.transform.rotate(STRAIGHT_VERTICAL, 270)
|
|
BASE_IMG = pg.image.load("Tiles/Base.jpg")
|
|
BASE = pg.transform.scale(BASE_IMG, (50, 50))
|
|
BEND_IMG = pg.image.load("Tiles/Bend.jpg")
|
|
BEND1 = pg.transform.scale(BEND_IMG, (50, 50))
|
|
BEND2 = pg.transform.rotate(BEND1, 90)
|
|
BEND3 = pg.transform.rotate(pg.transform.flip(pg.transform.rotate(BEND1, 180), True, True), 180)
|
|
BEND4 = pg.transform.rotate(BEND1, -90)
|
|
INTERSECTION_IMG = pg.image.load("Tiles/Intersection.jpg")
|
|
INTERSECTION = pg.transform.scale(INTERSECTION_IMG, (50, 50))
|
|
JUNCTION_IMG = pg.image.load("Tiles/Junction.jpg")
|
|
JUNCTION_SOUTH = pg.transform.scale(JUNCTION_IMG, (50, 50))
|
|
JUNCTION_NORTH = pg.transform.rotate(pg.transform.flip(JUNCTION_SOUTH, True, False), 180)
|
|
JUNCTION_EAST = pg.transform.rotate(JUNCTION_SOUTH, -90)
|
|
JUNCTION_WEST = pg.transform.rotate(JUNCTION_SOUTH, 90)
|
|
END_IMG = pg.image.load("Tiles/End.jpg")
|
|
END1 = pg.transform.flip(pg.transform.rotate(pg.transform.scale(END_IMG, (50, 50)), 180), False, True)
|
|
END2 = pg.transform.rotate(END1, 90)
|
|
DIRT_IMG = pg.image.load("Tiles/dirt.jpg")
|
|
DIRT = pg.transform.scale(DIRT_IMG, (50, 50))
|
|
GRASS_IMG = pg.image.load("Tiles/grass.png")
|
|
GRASS = pg.transform.scale(GRASS_IMG, (50, 50))
|
|
SAND_IMG = pg.image.load("Tiles/sand.jpeg")
|
|
SAND = pg.transform.scale(SAND_IMG, (50, 50))
|
|
COBBLE_IMG = pg.image.load("Tiles/cobble.jpeg")
|
|
COBBLE = pg.transform.scale(COBBLE_IMG, (50, 50))
|
|
|
|
|
|
def randomize_map(): # tworzenie mapy z losowymi polami
|
|
request_list = []
|
|
field_array_1 = []
|
|
field_array_2 = []
|
|
imgpath_array = [[0 for x in range(16)] for x in range(16)]
|
|
field_priority = []
|
|
map_array = [['b', 'sh', 'sh', 'sh', 'sh', 'jw', 'sh', 'sh', 'sh', 'sh', 'jw', 'sh', 'sh', 'sh', 'b3', 'g'],
|
|
['sv', 'g', 'g', 'g', 'g', 'sv', 'g', 'g', 'g', 'g', 'sv', 'g', 'g', 'g', 'sv', 'g'],
|
|
['sv', 'g', 'g', 'g', 'g', 'sv', 'g', 'g', 'g', 'g', 'sv', 'g', 'gr', 'g', 'sv', 'g'],
|
|
['js', 'sh', 'sh', 'sh', 'sh', 'i', 'sh', 'sh', 'sh', 'sh', 'jn', 'g', 'gr', 'g', 'sv', 'g'],
|
|
['sv', 'g', 'g', 'g', 'g', 'sv', 'g', 'g', 'g', 'g', 'sv', 'g', 'gr', 'g', 'sv', 'g'],
|
|
['sv', 'g', 'gr', 'gr', 'g', 'sv', 'g', 'g', 'g', 'g', 'sv', 'g', 'g', 'g', 'sv', 'g'],
|
|
['sv', 'g', 'gr', 'gr', 'g', 'js', 'sh', 'sh', 'sh', 'sh', 'i', 'sh', 'sh', 'sh', 'jn', 'g'],
|
|
['sv', 'g', 'g', 'g', 'g', 'sv', 'g', 'g', 'g', 'g', 'sv', 'g', 'g', 'g', 'sv', 'g'],
|
|
['b1', 'sh', 'jw', 'sh', 'sh', 'jn', 'g', 'gr', 'gr', 'g', 'sv', 'g', 'gr', 'g', 'sv', 'g'],
|
|
['g', 'g', 'sv', 'g', 'g', 'sv', 'g', 'gr', 'gr', 'g', 'sv', 'g', 'g', 'g', 'sv', 'g'],
|
|
['gr', 'g', 'sv', 'g', 'g', 'sv', 'g', 'gr', 'gr', 'g', 'js', 'sh', 'sh', 'sh', 'jn', 'g'],
|
|
['gr', 'g', 'sv', 'g', 'g', 'sv', 'g', 'g', 'g', 'g', 'sv', 'g', 'g', 'g', 'sv', 'g'],
|
|
['gr', 'g', 'js', 'sh', 'sh', 'i', 'sh', 'sh', 'sh', 'sh', 'jn', 'g', 'gr', 'g', 'sv', 'g'],
|
|
['gr', 'g', 'sv', 'g', 'g', 'sv', 'g', ' g', 'g', 'g', 'sv', 'g', 'gr', 'g', 'sv', 'g'],
|
|
['gr', 'g', 'sv', 'g', 'g', 'sv', 'g', 'g', 'g', 'g', 'sv', 'g', 'g', 'g', 'sv', 'g'],
|
|
['gr', 'g', 'b1', 'sh', 'sh', 'je', 'sh', 'sh', 'sh', 'sh', 'je', 'sh', 'sh', 'sh', 'b4', 'g'],
|
|
]
|
|
|
|
for i in range(16):
|
|
temp_priority = []
|
|
for j in range(16):
|
|
if map_array[i][j] == 'b':
|
|
field_array_2.append(BASE)
|
|
temp_priority.append(1)
|
|
elif map_array[i][j] == 'b3':
|
|
field_array_2.append(BEND3)
|
|
temp_priority.append(1)
|
|
elif map_array[i][j] == 'b4':
|
|
field_array_2.append(BEND4)
|
|
temp_priority.append(1)
|
|
elif map_array[i][j] == 'b1':
|
|
field_array_2.append(BEND1)
|
|
temp_priority.append(1)
|
|
elif map_array[i][j] == 'sh':
|
|
field_array_2.append(STRAIGHT_VERTICAL)
|
|
temp_priority.append(1)
|
|
elif map_array[i][j] == 'sv':
|
|
field_array_2.append(STRAIGHT_HORIZONTAL)
|
|
temp_priority.append(1)
|
|
elif map_array[i][j] == 'i':
|
|
field_array_2.append(INTERSECTION)
|
|
temp_priority.append(1)
|
|
elif map_array[i][j] == 'je':
|
|
field_array_2.append(JUNCTION_EAST)
|
|
temp_priority.append(1)
|
|
elif map_array[i][j] == 'jw':
|
|
field_array_2.append(JUNCTION_WEST)
|
|
temp_priority.append(1)
|
|
elif map_array[i][j] == 'js':
|
|
field_array_2.append(JUNCTION_SOUTH)
|
|
temp_priority.append(1)
|
|
elif map_array[i][j] == 'jn':
|
|
field_array_2.append(JUNCTION_NORTH)
|
|
temp_priority.append(1)
|
|
elif map_array[i][j] == 'gr':
|
|
field_array_2.append(BASE)
|
|
temp_priority.append(1000)
|
|
else:
|
|
prob = random.uniform(0, 100)
|
|
if 0 <= prob <= 20:
|
|
garbage_type = random.choice(['glass', 'mixed', 'paper', 'plastic'])
|
|
garbage_image_number = random.randrange(1, 100)
|
|
GARBAGE_IMG = pg.image.load(
|
|
f"./model_training/test_dataset/{garbage_type}/{garbage_type} ({str(garbage_image_number)}).jpg")
|
|
GARBAGE = pg.transform.scale(GARBAGE_IMG, (50, 50))
|
|
field_array_2.append(GARBAGE)
|
|
imgpath_array[i][j] = (
|
|
f"./model_training/test_dataset/{garbage_type}/{garbage_type} ({str(garbage_image_number)}).jpg")
|
|
|
|
temp_priority.append(100)
|
|
request_list.append(Request(
|
|
i * 50, j * 50, # lokacja
|
|
random.randint(0, 3), # typ śmieci
|
|
random.random(), # objętość śmieci
|
|
random.randint(0, 30), # ostatni odbiór
|
|
random.randint(0, 1), # czy opłacone w terminie
|
|
random.random() * 10, # intensywność odoru
|
|
random.random() * 50 # waga śmieci
|
|
))
|
|
else:
|
|
field_array_2.append(BASE)
|
|
temp_priority.append(1000)
|
|
field_array_1.append(field_array_2)
|
|
field_array_2 = []
|
|
field_priority.append(temp_priority)
|
|
return field_array_1, field_priority, request_list, imgpath_array
|