Added new fields and reconfigured map
BIN
Tiles/Base.jpg
Normal file
After Width: | Height: | Size: 209 KiB |
BIN
Tiles/Bend.jpg
Normal file
After Width: | Height: | Size: 192 KiB |
BIN
Tiles/End.jpg
Normal file
After Width: | Height: | Size: 193 KiB |
BIN
Tiles/Intersection.jpg
Normal file
After Width: | Height: | Size: 187 KiB |
BIN
Tiles/Junction.jpg
Normal file
After Width: | Height: | Size: 178 KiB |
BIN
Tiles/Straight.jpg
Normal file
After Width: | Height: | Size: 186 KiB |
Before Width: | Height: | Size: 9.3 KiB After Width: | Height: | Size: 9.3 KiB |
Before Width: | Height: | Size: 3.5 KiB After Width: | Height: | Size: 3.5 KiB |
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 26 KiB |
Before Width: | Height: | Size: 9.8 KiB After Width: | Height: | Size: 9.8 KiB |
@ -1,3 +1,2 @@
|
||||
def heuristicfn(startx, starty, goalx, goaly):
|
||||
return abs(startx - goalx) + abs(starty - goaly)
|
||||
# return pow(((startx//50)-(starty//50)),2) + pow(((goalx//50)-(goaly//50)),2)
|
10
main.py
@ -1,8 +1,6 @@
|
||||
import pygame
|
||||
from treelearn import treelearn
|
||||
import loadmodel
|
||||
|
||||
|
||||
from astar import astar
|
||||
from state import State
|
||||
import time
|
||||
@ -10,6 +8,7 @@ from garbage_truck import GarbageTruck
|
||||
from heuristicfn import heuristicfn
|
||||
from map import randomize_map
|
||||
|
||||
|
||||
pygame.init()
|
||||
WIDTH, HEIGHT = 800, 800
|
||||
window = pygame.display.set_mode((WIDTH, HEIGHT))
|
||||
@ -19,9 +18,9 @@ AGENT = pygame.transform.scale(AGENT_IMG, (50, 50))
|
||||
FPS = 10
|
||||
FIELDCOUNT = 16
|
||||
FIELDWIDTH = 50
|
||||
BASE_IMG = pygame.image.load("Tiles/Base.jpg")
|
||||
BASE = pygame.transform.scale(BASE_IMG, (50, 50))
|
||||
|
||||
GRASS_IMG = pygame.image.load("grass.png")
|
||||
GRASS = pygame.transform.scale(GRASS_IMG, (50, 50))
|
||||
def draw_window(agent, fields, flip):
|
||||
if flip:
|
||||
direction = pygame.transform.flip(AGENT, True, False)
|
||||
@ -74,10 +73,9 @@ def main():
|
||||
garbage_type = loadmodel.classify(imgpath_array[agent.rect.x // 50][agent.rect.y // 50])
|
||||
low_space = agent.collect(garbage_type)
|
||||
|
||||
fields[agent.rect.x//50][agent.rect.y//50] = GRASS
|
||||
fields[agent.rect.x//50][agent.rect.y//50] = BASE
|
||||
priority_array[agent.rect.x//50][agent.rect.y//50] = 1
|
||||
time.sleep(0.5)
|
||||
|
||||
|
||||
pygame.quit()
|
||||
|
||||
|
129
map.py
@ -1,52 +1,127 @@
|
||||
import pygame, random
|
||||
import pygame as pg
|
||||
import random
|
||||
from request import Request
|
||||
|
||||
DIRT_IMG = pygame.image.load("dirt.jpg")
|
||||
DIRT = pygame.transform.scale(DIRT_IMG, (50, 50))
|
||||
GRASS_IMG = pygame.image.load("grass.png")
|
||||
GRASS = pygame.transform.scale(GRASS_IMG, (50, 50))
|
||||
SAND_IMG = pygame.image.load("sand.jpeg")
|
||||
SAND = pygame.transform.scale(SAND_IMG, (50, 50))
|
||||
COBBLE_IMG = pygame.image.load("cobble.jpeg")
|
||||
COBBLE = pygame.transform.scale(COBBLE_IMG, (50, 50))
|
||||
|
||||
def randomize_map(): # tworzenie mapy z losowymi polami
|
||||
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 i in (0, 1) and j in (0, 1):
|
||||
field_array_2.append(GRASS)
|
||||
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 <= 12:
|
||||
if 0 <= prob <= 20:
|
||||
garbage_type = random.choice(['glass', 'mixed', 'paper', 'plastic'])
|
||||
garbage_image_number = random.randrange(1, 100)
|
||||
GARBAGE_IMG = pygame.image.load(f"./model_training/test_dataset/{garbage_type}/{garbage_type} ({str(garbage_image_number)}).jpg")
|
||||
GARBAGE = pygame.transform.scale(GARBAGE_IMG, (50, 50))
|
||||
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)
|
||||
#field_array_2.append(COBBLE)
|
||||
imgpath_array[i][j] = (f"./model_training/test_dataset/{garbage_type}/{garbage_type} ({str(garbage_image_number)}).jpg")
|
||||
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
|
||||
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(GRASS)
|
||||
temp_priority.append(1)
|
||||
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
|
||||
return field_array_1, field_priority, request_list, imgpath_array
|
||||
|