2024-03-25 00:05:56 +01:00
|
|
|
import pygame
|
2024-03-25 14:26:41 +01:00
|
|
|
from classes.Household import *
|
2024-03-25 00:05:56 +01:00
|
|
|
|
|
|
|
|
2024-03-19 18:52:31 +01:00
|
|
|
class Garbagetruck:
|
|
|
|
|
2024-04-11 13:55:55 +02:00
|
|
|
def __init__(self, mult):
|
|
|
|
self.mult = mult
|
2024-03-19 18:52:31 +01:00
|
|
|
self.capacity: int = 20
|
|
|
|
self.trash: list = []
|
|
|
|
self.trashweight: int = 0
|
2024-04-11 13:55:55 +02:00
|
|
|
self.image = pygame.image.load("sprites/smieciara.png").convert_alpha()
|
|
|
|
self.image = pygame.transform.scale(self.image, (mult, mult))
|
2024-03-25 11:39:10 +01:00
|
|
|
self.position = [3, 3]
|
2024-03-25 14:57:24 +01:00
|
|
|
self.houses: list = []
|
|
|
|
self.trashcans: list = []
|
|
|
|
self.state = None
|
|
|
|
self.segregation = {"Papier": "paper",
|
|
|
|
"MetalPlastik": "metals_and_plastics",
|
|
|
|
"Mixed": "mixed",
|
|
|
|
"Bio": "bio_waste",
|
|
|
|
"Szklo": "glass"}
|
2024-03-19 18:52:31 +01:00
|
|
|
self.route = None
|
|
|
|
self.scanner = None
|
|
|
|
self.planner = None
|
|
|
|
self.driver = None
|
2024-04-11 13:55:55 +02:00
|
|
|
self.orientation = 3 # Niech numery będą tak: N - 0, W - 1, S - 2, E - 3 -- po prostu odwrotnie do zegara
|
2024-03-25 14:57:24 +01:00
|
|
|
self.runningtime = 0
|
2024-04-11 20:30:06 +02:00
|
|
|
self.movesequence = []
|
2024-03-19 18:52:31 +01:00
|
|
|
|
2024-04-11 13:55:55 +02:00
|
|
|
def getOrientation(self):
|
|
|
|
return self.orientation
|
|
|
|
|
|
|
|
def setOrientation(self, orientation):
|
|
|
|
self.orientation = orientation % 4
|
|
|
|
return self
|
|
|
|
|
2024-03-25 14:57:24 +01:00
|
|
|
def getRunningtime(self):
|
|
|
|
return self.runningtime
|
2024-03-25 11:39:10 +01:00
|
|
|
|
2024-03-25 14:57:24 +01:00
|
|
|
def setRunningtime(self, runningtime):
|
|
|
|
self.runningtime = runningtime
|
2024-03-25 11:39:10 +01:00
|
|
|
return self
|
|
|
|
|
2024-03-25 14:57:24 +01:00
|
|
|
def incrRunningtime(self):
|
|
|
|
self.runningtime += 1
|
2024-03-25 11:21:23 +01:00
|
|
|
return self
|
|
|
|
|
2024-03-25 14:57:24 +01:00
|
|
|
def getTrashcans(self):
|
|
|
|
return self.trashcans
|
|
|
|
|
|
|
|
def setTrashcans(self, others):
|
|
|
|
self.trashcans = others
|
|
|
|
return self
|
|
|
|
|
|
|
|
def setHouses(self, houses):
|
|
|
|
self.houses = houses
|
|
|
|
return self
|
|
|
|
|
|
|
|
def getHouses(self):
|
|
|
|
return self.houses
|
2024-03-25 11:21:23 +01:00
|
|
|
|
2024-03-19 18:52:31 +01:00
|
|
|
def getCapacity(self) -> int:
|
|
|
|
return self.capacity
|
|
|
|
|
|
|
|
def getTrash(self) -> list:
|
|
|
|
return self.trash
|
|
|
|
|
|
|
|
def setTrash(self, trash: list) -> None:
|
|
|
|
self.trash = trash
|
|
|
|
for item in trash:
|
2024-03-25 11:39:10 +01:00
|
|
|
self.addTrashweight(item.getWaga)
|
2024-03-19 18:52:31 +01:00
|
|
|
|
2024-03-25 11:39:10 +01:00
|
|
|
def addTrash(self, trash: Trash) -> None:
|
2024-03-19 18:52:31 +01:00
|
|
|
self.trash.append(trash)
|
2024-03-25 11:39:10 +01:00
|
|
|
self.addTrashweight(trash.getWaga())
|
2024-03-19 18:52:31 +01:00
|
|
|
|
|
|
|
def getTrashweight(self) -> int:
|
|
|
|
return self.trashweight
|
|
|
|
|
|
|
|
def setTrashweight(self, weight: int) -> None:
|
|
|
|
self.trashweight = weight
|
|
|
|
|
|
|
|
def addTrashweight(self, weight: int) -> None:
|
|
|
|
self.trashweight += weight
|
|
|
|
|
|
|
|
def getImage(self) -> object:
|
|
|
|
return self.image
|
|
|
|
|
|
|
|
def setImage(self, image: object) -> None:
|
|
|
|
self.image = image
|
|
|
|
|
2024-03-25 11:39:10 +01:00
|
|
|
def getPosition(self) -> list:
|
2024-03-19 18:52:31 +01:00
|
|
|
return self.position
|
|
|
|
|
2024-03-25 11:39:10 +01:00
|
|
|
def setPosition(self, position: list) -> object:
|
2024-03-19 18:52:31 +01:00
|
|
|
self.position = position
|
2024-03-25 11:39:10 +01:00
|
|
|
return self
|
|
|
|
|
|
|
|
def modPosiotion(self, modX, modY):
|
|
|
|
x = self.getPosition()[0] + modX
|
|
|
|
y = self.getPosition()[1] + modY
|
|
|
|
self.setPosition([x, y])
|
2024-03-19 18:52:31 +01:00
|
|
|
|
|
|
|
def getRoute(self):
|
|
|
|
return self.route
|
|
|
|
|
|
|
|
def setRoute(self, route) -> None:
|
|
|
|
self.route = route
|
|
|
|
|
|
|
|
def getScanner(self):
|
|
|
|
return self.scanner
|
|
|
|
|
|
|
|
def setScanner(self, scanner) -> None:
|
|
|
|
self.route = scanner
|
|
|
|
|
|
|
|
def getPlanner(self):
|
|
|
|
return self.planner
|
|
|
|
|
|
|
|
def setPlanner(self, planner) -> None:
|
|
|
|
self.route = planner
|
|
|
|
|
|
|
|
def getDriver(self):
|
|
|
|
return self.driver
|
|
|
|
|
|
|
|
def setDriver(self, driver) -> None:
|
|
|
|
self.route = driver
|
2024-03-25 11:39:10 +01:00
|
|
|
|
|
|
|
def distance(self, object1, object2) -> int:
|
|
|
|
lok1 = object1.getPosition()
|
|
|
|
lok2 = object2.getPosition()
|
|
|
|
|
|
|
|
dist = abs(lok1[0] - lok2[0]) + abs(lok1[1] - lok2[1])
|
|
|
|
return dist
|
2024-03-25 14:26:41 +01:00
|
|
|
|
2024-04-11 20:30:06 +02:00
|
|
|
def selfdistance(self, target) -> int:
|
|
|
|
lok = target.getPosition()
|
|
|
|
own = self.getPosition()
|
|
|
|
|
|
|
|
dist = abs(lok[0] - own[0]) + abs(lok[1] - own[1])
|
|
|
|
return dist
|
|
|
|
|
2024-03-25 14:26:41 +01:00
|
|
|
def scanTile(self):
|
2024-03-25 14:57:24 +01:00
|
|
|
self.state = None
|
|
|
|
temp = self.houses[:]
|
|
|
|
temp.append(self.trashcans[:])
|
|
|
|
for loc in temp:
|
2024-03-25 14:26:41 +01:00
|
|
|
if tuple(self.position) == loc.getPosition():
|
|
|
|
self.state = loc
|
|
|
|
return
|
|
|
|
|
|
|
|
def printme(self):
|
|
|
|
x, y = self.getPosition()
|
2024-04-11 13:55:55 +02:00
|
|
|
return self.mult*x, self.mult*y
|
2024-03-25 14:57:24 +01:00
|
|
|
|
|
|
|
def throwGarbage(self, trash):
|
|
|
|
if self.segregation[trash.getTtype()] == self.state.getTrashtype():
|
|
|
|
self.addTrashweight(trash.getWeight * (-1))
|
|
|
|
self.trash.remove(trash)
|
|
|
|
|
2024-04-11 13:55:55 +02:00
|
|
|
def rotateImage(self, arg):
|
|
|
|
self.image = pygame.transform.rotate(self.image, 90*arg)
|
|
|
|
|
|
|
|
def rotateLeft(self):
|
|
|
|
self.setOrientation(self.getOrientation()+1)
|
|
|
|
self.rotateImage(1)
|
|
|
|
|
|
|
|
def rotateRight(self):
|
|
|
|
self.setOrientation(self.getOrientation()-1)
|
|
|
|
self.rotateImage(-1)
|
|
|
|
|
|
|
|
def moveForward(self):
|
|
|
|
ort = self.orientation
|
|
|
|
x, y = self.getPosition()
|
|
|
|
stepX = 0
|
|
|
|
stepY = 0
|
|
|
|
if ort == 0 and y != 0:
|
|
|
|
stepY = -1
|
|
|
|
elif ort == 1 and x != 0:
|
|
|
|
stepX = -1
|
|
|
|
elif ort == 2 and y != 20:
|
|
|
|
stepY = 1
|
|
|
|
elif ort == 3 and x != 30:
|
|
|
|
stepX = 1
|
|
|
|
self.modPosiotion(stepX, stepY)
|
|
|
|
|
2024-04-11 20:30:06 +02:00
|
|
|
def graphsearch(self, target):
|
|
|
|
fringe = []
|
|
|
|
explored = []
|
|
|
|
result = []
|
|
|
|
initial = self.getPosition()
|
|
|
|
initial.append(self.getOrientation())
|
|
|
|
fringe.append(tuple(initial))
|
|
|
|
|
|
|
|
while True:
|
|
|
|
if not fringe:
|
|
|
|
return False
|
|
|
|
|
|
|
|
elem = fringe.pop(0)
|
|
|
|
if self.selfdistance(target) == 0:
|
|
|
|
return result
|
|
|
|
|
|
|
|
explored.append(elem)
|
|
|
|
|
|
|
|
# KONIECZNIE SKOŃCZYĆ!!!
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-03-25 14:57:24 +01:00
|
|
|
def classifyTrash(self):
|
|
|
|
pass
|
|
|
|
# Tutaj jest plan żeby dopiero napisać funkcję jak już będzie klasyfikator
|
|
|
|
# ogólnie to myślałem żeby po prostu zklasyfikować śmieć i zmienić mu trashtype na rozpoznany, żeby śmieciarka go tak posegreowała
|