2023-06-10 23:53:24 +02:00
|
|
|
import pygame as pg
|
|
|
|
import random
|
2023-05-26 19:08:22 +02:00
|
|
|
from request import Request
|
|
|
|
|
|
|
|
|
2023-06-10 23:53:24 +02:00
|
|
|
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
|
2023-05-26 19:08:22 +02:00
|
|
|
request_list = []
|
|
|
|
field_array_1 = []
|
|
|
|
field_array_2 = []
|
2023-06-01 23:44:09 +02:00
|
|
|
imgpath_array = [[0 for x in range(16)] for x in range(16)]
|
2023-05-26 19:08:22 +02:00
|
|
|
field_priority = []
|
2023-06-10 23:53:24 +02:00
|
|
|
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'],
|
|
|
|
]
|
|
|
|
|
2023-05-26 19:08:22 +02:00
|
|
|
for i in range(16):
|
|
|
|
temp_priority = []
|
|
|
|
for j in range(16):
|
2023-06-10 23:53:24 +02:00
|
|
|
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)
|
2023-05-26 19:08:22 +02:00
|
|
|
temp_priority.append(1)
|
2023-06-10 23:53:24 +02:00
|
|
|
elif map_array[i][j] == 'gr':
|
|
|
|
field_array_2.append(BASE)
|
|
|
|
temp_priority.append(1000)
|
2023-05-26 19:08:22 +02:00
|
|
|
else:
|
|
|
|
prob = random.uniform(0, 100)
|
2023-06-10 23:53:24 +02:00
|
|
|
if 0 <= prob <= 20:
|
2023-06-01 23:44:09 +02:00
|
|
|
garbage_type = random.choice(['glass', 'mixed', 'paper', 'plastic'])
|
|
|
|
garbage_image_number = random.randrange(1, 100)
|
2023-06-10 23:53:24 +02:00
|
|
|
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))
|
2023-06-01 23:44:09 +02:00
|
|
|
field_array_2.append(GARBAGE)
|
2023-06-10 23:53:24 +02:00
|
|
|
imgpath_array[i][j] = (
|
|
|
|
f"./model_training/test_dataset/{garbage_type}/{garbage_type} ({str(garbage_image_number)}).jpg")
|
2023-06-01 23:44:09 +02:00
|
|
|
|
2023-05-26 19:08:22 +02:00
|
|
|
temp_priority.append(100)
|
|
|
|
request_list.append(Request(
|
2023-06-10 23:53:24 +02:00
|
|
|
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
|
2023-05-26 19:08:22 +02:00
|
|
|
))
|
|
|
|
else:
|
2023-06-10 23:53:24 +02:00
|
|
|
field_array_2.append(BASE)
|
|
|
|
temp_priority.append(1000)
|
2023-05-26 19:08:22 +02:00
|
|
|
field_array_1.append(field_array_2)
|
|
|
|
field_array_2 = []
|
|
|
|
field_priority.append(temp_priority)
|
2023-06-10 23:53:24 +02:00
|
|
|
return field_array_1, field_priority, request_list, imgpath_array
|