filled each garbage can with 4 pieces of garbage

This commit is contained in:
majkellll 2023-05-27 13:16:41 +02:00
parent c8bcea171e
commit 1e5a1b9254
5 changed files with 134 additions and 9 deletions

View File

@ -1,21 +1,43 @@
from enum import Enum from enum import Enum
class GarbageType (Enum):
class GarbageType(Enum):
PAPER = 0, PAPER = 0,
PLASTIC_AND_METAL = 1 PLASTIC_AND_METAL = 1
GLASS = 3 GLASS = 3
BIO = 4 BIO = 4
MIXED = 5 MIXED = 5
class Garbage: class Garbage:
img: str img: str
shape: str
flexibility: str
does_smell: str
weight: str
size: str
color: str
softness: str
does_din: str
def __init__(self, img: str) -> None: def __init__(self, img: str, shape: str, flexibility: str, does_smell: str, weight: str, size: str, color: str, softness: str, does_din: str) -> None:
self.img = img self.img = img
self.shape = shape
self.flexibility = flexibility
self.does_smell = does_smell
self.weight = weight
self.size = size
self.color = color
self.softness = softness
self.does_din = does_din
class RecognizedGarbage (Garbage): def xxx(self):
return self.shape
class RecognizedGarbage(Garbage):
garbage_type: GarbageType garbage_type: GarbageType
def __init__(self, src: Garbage, garbage_type: GarbageType) -> None: def __init__(self, src: Garbage, garbage_type: GarbageType) -> None:
super().__init__(src.img) super().__init__(src.img)
self.garbage_type = garbage_type self.garbage_type = garbage_type

View File

@ -3,6 +3,7 @@ from typing import List, Tuple
from gameContext import GameContext from gameContext import GameContext
from gridCellType import GridCellType from gridCellType import GridCellType
class GarbageCan: class GarbageCan:
position: Tuple[int, int] position: Tuple[int, int]
garbage: List[Garbage] garbage: List[Garbage]
@ -19,6 +20,7 @@ class GarbageCan:
def remove_garbage(self, garbage: Garbage) -> None: def remove_garbage(self, garbage: Garbage) -> None:
self.garbage.remove(garbage) self.garbage.remove(garbage)
def render(self, game_context: GameContext) -> None: def render(self, game_context: GameContext) -> None:
game_context.render_in_cell(self.position, "imgs/container.png") game_context.render_in_cell(self.position, "imgs/container.png")
game_context.grid[self.position] = GridCellType.GARBAGE_CAN game_context.grid[self.position] = GridCellType.GARBAGE_CAN

View File

@ -0,0 +1,29 @@
Shape,Flexibility,DoesSmell,Weight,Size,Color,Softness,DoesDin
Irregular,High,No,High,Medium,Dark,Low,Yes
Longitiudonal,Low,No,Low,Low,Light,Medium,Yes
Longitiudonal,Medium,No,Medium,Low,Dark,High,No
Longitiudonal,Low,No,Medium,Low,Dark,High,Yes
Round,Low,Yes,High,High,Transparent,High,Yes
Irregular,Medium,Yes,High,Low,Transparent,Medium,No
Longitiudonal,Medium,Yes,Low,High,Colorful,Medium,Yes
Longitiudonal,Low,No,Low,Medium,Dark,Medium,Yes
Flat,Medium,Yes,High,Low,Transparent,Low,Yes
Irregular,Medium,Yes,High,Medium,Dark,Low,No
Longitiudonal,High,No,Low,High,Colorful,Low,Yes
Round,Medium,No,Medium,Medium,Dark,Low,No
Longitiudonal,Medium,No,Medium,Medium,Transparent,High,No
Flat,Medium,Yes,Low,Low,Light,Medium,No
Flat,Medium,Yes,Medium,High,Light,Medium,No
Flat,Low,No,High,Low,Dark,High,No
Longitiudonal,Medium,Yes,High,High,Dark,Low,Yes
Flat,Low,Yes,Low,Low,Transparent,Low,No
Flat,Low,No,Medium,Low,Colorful,Low,No
Longitiudonal,Low,Yes,High,Medium,Transparent,Low,No
Longitiudonal,Low,No,Medium,High,Dark,Low,Yes
Irregular,Medium,No,Medium,Medium,Light,Low,Yes
Longitiudonal,High,No,High,High,Colorful,Low,No
Flat,Low,No,Low,Low,Dark,High,No
Flat,Low,Yes,Low,High,Dark,Low,Yes
Irregular,Medium,Yes,High,High,Dark,Low,No
Flat,High,No,High,Low,Dark,Medium,Yes
Longitiudonal,High,Yes,Low,Medium,Colorful,Low,Yes
1 Shape Flexibility DoesSmell Weight Size Color Softness DoesDin
2 Irregular High No High Medium Dark Low Yes
3 Longitiudonal Low No Low Low Light Medium Yes
4 Longitiudonal Medium No Medium Low Dark High No
5 Longitiudonal Low No Medium Low Dark High Yes
6 Round Low Yes High High Transparent High Yes
7 Irregular Medium Yes High Low Transparent Medium No
8 Longitiudonal Medium Yes Low High Colorful Medium Yes
9 Longitiudonal Low No Low Medium Dark Medium Yes
10 Flat Medium Yes High Low Transparent Low Yes
11 Irregular Medium Yes High Medium Dark Low No
12 Longitiudonal High No Low High Colorful Low Yes
13 Round Medium No Medium Medium Dark Low No
14 Longitiudonal Medium No Medium Medium Transparent High No
15 Flat Medium Yes Low Low Light Medium No
16 Flat Medium Yes Medium High Light Medium No
17 Flat Low No High Low Dark High No
18 Longitiudonal Medium Yes High High Dark Low Yes
19 Flat Low Yes Low Low Transparent Low No
20 Flat Low No Medium Low Colorful Low No
21 Longitiudonal Low Yes High Medium Transparent Low No
22 Longitiudonal Low No Medium High Dark Low Yes
23 Irregular Medium No Medium Medium Light Low Yes
24 Longitiudonal High No High High Colorful Low No
25 Flat Low No Low Low Dark High No
26 Flat Low Yes Low High Dark Low Yes
27 Irregular Medium Yes High High Dark Low No
28 Flat High No High Low Dark Medium Yes
29 Longitiudonal High Yes Low Medium Colorful Low Yes

View File

@ -48,4 +48,54 @@ Irregular,Low,No,Low,Medium,Light,Medium,No,PAPER
Flat,Low,No,High,Low,Dark,Low,No,PLASTIC_AND_METAL Flat,Low,No,High,Low,Dark,Low,No,PLASTIC_AND_METAL
Irregular,Low,Yes,Low,Low,Transparent,Medium,Yes,MIXED Irregular,Low,Yes,Low,Low,Transparent,Medium,Yes,MIXED
Flat,Low,No,High,High,Light,Low,No,PLASTIC_AND_METAL Flat,Low,No,High,High,Light,Low,No,PLASTIC_AND_METAL
Longitiudonal,Medium,No,High,Medium,Dark,Low,Yes,PLASTIC_AND_METAL Longitiudonal,Medium,No,High,Medium,Dark,Low,Yes,PLASTIC_AND_METAL
Round,Low,Yes,High,High,Transparent,High,No,MIXED
Flat,Medium,No,Medium,Low,Transparent,Low,Yes,GLASS
Longitiudonal,Low,No,High,Medium,Colorful,Medium,No,PLASTIC_AND_METAL
Longitiudonal,Low,Yes,High,Medium,Colorful,High,No,BIO
Longitiudonal,High,No,High,Medium,Transparent,Medium,Yes,PLASTIC_AND_METAL
Irregular,Medium,No,Medium,Medium,Dark,High,No,PAPER
Irregular,Low,No,Low,Medium,Light,Medium,Yes,PLASTIC_AND_METAL
Round,High,No,Medium,Medium,Colorful,Low,Yes,PLASTIC_AND_METAL
Irregular,High,No,High,High,Colorful,Low,No,MIXED
Round,High,Yes,Medium,Medium,Transparent,High,Yes,PLASTIC_AND_METAL
Flat,Medium,Yes,High,Medium,Colorful,Medium,Yes,BIO
Round,High,No,Medium,Medium,Light,High,No,MIXED
Flat,Low,Yes,Low,Low,Transparent,Medium,No,PLASTIC_AND_METAL
Flat,Low,No,Medium,High,Light,High,Yes,MIXED
Round,Medium,Yes,Medium,High,Transparent,High,No,MIXED
Irregular,Medium,Yes,Medium,Medium,Colorful,Low,No,MIXED
Flat,Low,Yes,Low,High,Light,Medium,No,BIO
Flat,Low,Yes,Medium,Medium,Dark,Medium,No,MIXED
Irregular,Low,No,High,High,Transparent,High,No,PLASTIC_AND_METAL
Irregular,Low,Yes,Low,Medium,Dark,Low,Yes,GLASS
Flat,Low,Yes,Low,Medium,Light,Low,No,GLASS
Longitiudonal,Medium,Yes,Low,Medium,Dark,Low,Yes,PLASTIC_AND_METAL
Irregular,Medium,No,Low,Low,Colorful,Medium,Yes,PAPER
Round,High,No,Medium,Medium,Dark,High,No,MIXED
Round,High,Yes,Low,High,Colorful,Low,No,MIXED
Longitiudonal,Low,Yes,Low,Low,Transparent,Medium,Yes,MIXED
Flat,Low,No,High,Medium,Light,Low,No,PLASTIC_AND_METAL
Irregular,High,No,Low,Low,Colorful,High,Yes,PAPER
Round,High,No,Medium,Medium,Colorful,High,No,MIXED
Irregular,High,Yes,High,Low,Transparent,Medium,No,MIXED
Round,Low,No,Medium,Low,Colorful,Low,No,GLASS
Flat,Low,No,High,Low,Light,Low,No,MIXED
Irregular,High,No,High,Medium,Light,Low,No,PLASTIC_AND_METAL
Flat,Medium,Yes,High,Low,Dark,Low,No,MIXED
Round,Medium,No,High,High,Colorful,Medium,No,PAPER
Flat,Low,Yes,Medium,Low,Transparent,Medium,No,PLASTIC_AND_METAL
Flat,Medium,No,Low,Medium,Transparent,High,NoMIXED
Flat,Low,Yes,Medium,High,Colorful,Low,No,GLASS
Longitiudonal,Low,Yes,High,Medium,Dark,High,No,BIO
Longitiudonal,Medium,Yes,Low,High,Dark,High,Yes,BIO
Round,High,No,Low,Low,Colorful,Medium,No,PAPER
Longitiudonal,Medium,Yes,Medium,Low,Colorful,Low,Yes,PLASTIC_AND_METAL
Longitiudonal,High,Yes,Low,Medium,Light,Medium,Yes,BIO
Round,Medium,No,High,Low,Transparent,Low,Yes,GLASS
Longitiudonal,High,No,Medium,High,Dark,High,Yes,MIXED
Irregular,Medium,No,High,High,Dark,Low,Yes, PLASTIC_AND_METAL
Flat,High,Yes,Medium,Medium,Colorful,Low,Yes,PAPER
Longitiudonal,Low,Yes,Medium,Medium,Light,Medium,Yes,MIXED
Round,Medium,Yes,High,Low,Light,Medium,Yes,PLASTIC_AND_METAL
Longitiudonal,High,No,Medium,Low,Light,Low,Yes,PLASTIC_AND_METAL
Can't render this file because it has a wrong number of fields in line 88.

View File

@ -8,6 +8,7 @@ from garbageTruck import GarbageTruck
from garbageCan import GarbageCan from garbageCan import GarbageCan
from speedBump import SpeedBump from speedBump import SpeedBump
from landfill import Landfill from landfill import Landfill
from garbage import Garbage
def startup(game_context: GameContext): def startup(game_context: GameContext):
@ -19,26 +20,45 @@ def startup(game_context: GameContext):
game_context.dust_car = car game_context.dust_car = car
_create_landfill(game_context) _create_landfill(game_context)
def create_dust_car(game_context: GameContext) -> GarbageTruck: def create_dust_car(game_context: GameContext) -> GarbageTruck:
return GarbageTruck((3, 3)) return GarbageTruck((3, 3))
def render_background(game_context: GameContext): def render_background(game_context: GameContext):
bg_img = Image.open("imgs/background.jpg") bg_img = Image.open("imgs/background.jpg")
pygame_bg_image = pygame.image.frombuffer(bg_img.tobytes(), bg_img.size, 'RGB') pygame_bg_image = pygame.image.frombuffer(bg_img.tobytes(), bg_img.size, 'RGB')
game_context.canvas.blit(pygame_bg_image, (0, 0)) game_context.canvas.blit(pygame_bg_image, (0, 0))
def create_city() -> City: def create_city() -> City:
city: City = City() city: City = City()
streets = create_streets() streets = create_streets()
trashcans = create_trashcans() trashcans = create_trashcans()
bumps = create_speed_bumps() bumps = create_speed_bumps()
garbage_pieces = create_garbage_pieces()
garbage_pieces_counter = 0
for s in streets: for s in streets:
city.add_street(s) city.add_street(s)
for t in trashcans: for t in trashcans:
for i in range(4):
t.add_garbage(garbage_pieces[0])
garbage_pieces_counter = garbage_pieces_counter + 1
city.add_can(t) city.add_can(t)
for b in bumps: for b in bumps:
city.add_bump(b) city.add_bump(b)
return city
def create_garbage_pieces() -> List[Garbage]:
garbage_pieces = []
with open('machine_learning/garbage_infill.csv', 'r') as file:
lines = file.readlines()
for line in lines[1:]:
param = line.strip().split(',')
garbage_pieces.append(
Garbage('img', param[0], param[1], param[2], param[3], param[4], param[5], param[6], param[7]))
return garbage_pieces
def create_streets() -> List[Street]: def create_streets() -> List[Street]:
streets = [] streets = []
@ -54,6 +74,7 @@ def create_streets() -> List[Street]:
streets.append(Street(17, 23, 25, StreetType.VERTICAL)) streets.append(Street(17, 23, 25, StreetType.VERTICAL))
return streets return streets
def create_trashcans() -> List[GarbageCan]: def create_trashcans() -> List[GarbageCan]:
trashcans = [] trashcans = []
trashcans.append(GarbageCan((9, 4))) trashcans.append(GarbageCan((9, 4)))
@ -65,6 +86,7 @@ def create_trashcans() -> List[GarbageCan]:
trashcans.append(GarbageCan((26, 4))) trashcans.append(GarbageCan((26, 4)))
return trashcans return trashcans
def create_speed_bumps() -> List[SpeedBump]: def create_speed_bumps() -> List[SpeedBump]:
bumps = [] bumps = []
bumps.append(SpeedBump((10, 9))) bumps.append(SpeedBump((10, 9)))
@ -73,7 +95,7 @@ def create_speed_bumps() -> List[SpeedBump]:
def _create_landfill(game_context: GameContext) -> None: def _create_landfill(game_context: GameContext) -> None:
landfil_position = (23,24) landfil_position = (23, 24)
landfill = Landfill(landfil_position) landfill = Landfill(landfil_position)
game_context.landfill = landfill game_context.landfill = landfill
landfill.render(game_context) landfill.render(game_context)