Compare commits

...

115 Commits

Author SHA1 Message Date
Paweł Felcyn b19778b796 Merge pull request 'Zmiana błędu w konstruktorze successor' (#37) from minor_upgrades into master
Reviewed-on: #37
2023-06-19 11:54:22 +02:00
majkellll 15839b4bc4 Zmiana błędu w konstruktorze successor 2023-06-19 11:54:14 +02:00
Paweł Felcyn 216de52583 Merge pull request 'recognize_garbage_photos' (#36) from recognize_garbage_photos into master
Reviewed-on: #36
2023-06-19 11:52:43 +02:00
Pawel Felcyn 58b53f5817 recognizing garbage 2023-06-18 21:01:45 +02:00
Pawel Felcyn 2d7ed16185 neuron network model 2023-06-17 18:33:23 +02:00
Pawel Felcyn c267515ee1 rename test photos 2023-06-17 17:14:24 +02:00
Pawel Felcyn aefba8e784 move test photos up 2023-06-17 17:08:30 +02:00
Paweł Felcyn 0824aaa0cf Merge pull request 'added neural network and model' (#35) from neuralNetwork into master
Reviewed-on: #35
2023-06-17 17:00:52 +02:00
maks aa401ea87c added Neural network and model 2023-06-17 16:52:21 +02:00
Maksymilian Szygenda 73f6396a29 Delete 'machine_learning/neuralNetwork.py' 2023-06-17 16:52:17 +02:00
Maksymilian Szygenda a21aa44601 Upload files to 'machine_learning' 2023-06-17 16:52:17 +02:00
Paweł Felcyn 6a364be40e Merge pull request 'Added photos of outside of train set' (#34) from trash_photos into master
Reviewed-on: #34
Reviewed-by: Paweł Felcyn <pawfel1@st.amu.edu.pl>
2023-06-05 08:19:05 +02:00
Paweł Felcyn 2727588f82 Merge branch 'master' into trash_photos 2023-06-05 08:18:51 +02:00
majkellll aef7b97b28 Added photos of outside of train set 2023-06-04 20:06:33 +02:00
Paweł Felcyn d6ec2cda4c Merge pull request 'Added photos of garbage' (#33) from trash_photos into master
Reviewed-on: #33
Reviewed-by: Paweł Felcyn <pawfel1@st.amu.edu.pl>
2023-06-04 08:48:17 +02:00
majkellll def9f33cf4 Added photos of garbage 2023-06-03 23:00:06 +02:00
Paweł Felcyn b997927e5d Merge pull request 'collecting_garbage' (#32) from collecting_garbage into master
Reviewed-on: #32
2023-06-03 14:43:15 +02:00
Paweł Felcyn 38c66cea53 strip classes 2023-05-29 12:00:46 +02:00
Pawel Felcyn 43c13acdee recognizing garbage 2023-05-29 09:57:52 +02:00
Paweł Felcyn 26bcc9ddf1 Merge pull request 'training data update' (#30) from s464933-patch-1 into master
Reviewed-on: #30
Reviewed-by: Paweł Felcyn <pawfel1@st.amu.edu.pl>
2023-05-28 18:01:20 +02:00
Pawel Felcyn 301384ed80 model 2023-05-28 18:00:41 +02:00
Maksymilian Szygenda 5a56d61a5f training data update 2023-05-28 18:00:11 +02:00
Paweł Felcyn 5e2b673196 Merge pull request 'more trainig examples, model training' (#31) from decision_tree into master
Reviewed-on: #31
Reviewed-by: Paweł Felcyn <pawfel1@st.amu.edu.pl>
2023-05-28 17:32:37 +02:00
Wiktor Szynaka 5339fbbe82 more trainig examples, model training 2023-05-28 02:50:07 +02:00
Paweł Felcyn 24f4c60e37 Merge pull request 'filled each garbage can with 4 pieces of garbage' (#28) from cvs_wypelnienie_smietnika into master
Reviewed-on: #28
Reviewed-by: Paweł Felcyn <pawfel1@st.amu.edu.pl>
2023-05-27 14:58:33 +02:00
majkellll d8e34ad65b delated test methods 2023-05-27 13:46:44 +02:00
majkellll a1f2e4b298 garbage_pieces_counter 2023-05-27 13:45:31 +02:00
majkellll f79fa2ee66 dodany przecinek 2023-05-27 13:35:39 +02:00
majkellll 1e5a1b9254 filled each garbage can with 4 pieces of garbage 2023-05-27 13:16:41 +02:00
Paweł Felcyn c8bcea171e Merge pull request 'read csv with training data' (#27) from read_training_data into master
Reviewed-on: #27
2023-05-27 11:34:58 +02:00
Pawel Felcyn 6a05f59d97 read csv with training data 2023-05-27 11:34:26 +02:00
Paweł Felcyn f60ed5d28f Merge pull request 'add training data pf' (#26) from pf_training_data into master
Reviewed-on: #26
2023-05-27 11:02:51 +02:00
Pawel Felcyn 4589d3a49c add training data pf 2023-05-27 11:01:22 +02:00
Paweł Felcyn 9287f76ea3 Merge pull request 'A_star' (#25) from A_star into master
Reviewed-on: #25
Reviewed-by: Paweł Felcyn <pawfel1@st.amu.edu.pl>
2023-05-25 18:52:06 +02:00
majkellll 271e3365f9 A* gawor done 2023-05-25 18:18:11 +02:00
majkellll aacee0e493 Merge remote-tracking branch 'origin/A_star' into A_star
# Conflicts:
#	bfs.py
#	main.py
#	movement.py
2023-05-15 11:50:30 +02:00
majkellll 15638862d3 A* working ok 2023-05-15 11:49:58 +02:00
majkellll af32df4474 dodany A* - coś jeszcze nie działa 2023-05-15 11:04:09 +02:00
Pawel Felcyn 311a2d0757 astar for MIkołaj Gawor 2023-05-15 10:59:30 +02:00
majkellll 5440626353 dodany A* - coś jeszcze nie działa 2023-05-15 08:07:08 +02:00
Paweł Felcyn dd34b7341a Merge pull request 'add heuristics' (#24) from heuristics into master
Reviewed-on: #24
2023-05-13 23:07:17 +02:00
Pawel Felcyn c708663d39 add heuristics 2023-05-13 23:06:42 +02:00
Paweł Felcyn 65bef51958 Merge pull request 'SpeedBump' (#23) from SpeedBump into master
Reviewed-on: #23
Reviewed-by: Paweł Felcyn <pawfel1@st.amu.edu.pl>
2023-05-13 22:05:20 +02:00
Wiktor Szynaka a2d6cc688b correction 2023-05-13 21:17:30 +02:00
Wiktor Szynaka f7c91e92aa deleted empty can enum 2023-05-13 21:04:57 +02:00
Wiktor Szynaka b25a36e872 action costs 2023-05-13 21:00:13 +02:00
Wiktor Szynaka 76eb4771a2 add action cost function and remove node class 2023-05-13 20:20:04 +02:00
Wiktor Szynaka 4ab84deaf3 speed bumps 2023-05-13 20:02:42 +02:00
Wiktor Szynaka f0d6001efa speed bumps 2023-05-13 19:41:19 +02:00
Wiktor Szynaka af42c84186 speed bumps 2023-05-13 19:30:00 +02:00
Paweł Felcyn aec533956d Merge pull request 'landfill' (#22) from landfill into master
Reviewed-on: #22
2023-05-11 21:38:44 +02:00
Pawel Felcyn bb3fc2715f make dust car faster 2023-05-11 20:14:09 +02:00
Pawel Felcyn 94f301cae5 add landfill 2023-05-11 20:12:41 +02:00
Paweł Felcyn eb7857323c Merge pull request 'finish_bfs' (#21) from finish_bfs into master
Reviewed-on: #21
2023-04-23 16:45:17 +02:00
Pawel Felcyn 69ce36b4e2 remove comented code 2023-04-23 16:43:32 +02:00
Pawel Felcyn 2ce57ea190 visit all garbage cans with bfs 2023-04-23 16:42:45 +02:00
Paweł Felcyn ef1b0c23a9 Merge pull request 'garbageCan instantions' (#20) from s464933/sztuczna_inteligencja_2023_smieciarka:master into master
Reviewed-on: #20
2023-04-23 16:16:40 +02:00
Maksymilian Szygenda b78f3cfa7b Update 'startup.py' 2023-04-23 15:40:34 +02:00
Maksymilian Szygenda 2fbf2be1d7 Update 'startup.py' 2023-04-23 15:37:22 +02:00
Maksymilian Szygenda 9f7ca5d0ed Update 'city.py' 2023-04-23 15:35:37 +02:00
Maksymilian Szygenda cf525c5c4b Update 'city.py' 2023-04-23 15:34:29 +02:00
Maksymilian Szygenda ca91fd4726 Merge pull request 'master' (#1) from s473616/sztuczna_inteligencja_2023_smieciarka:master into master
Reviewed-on: s464933/sztuczna_inteligencja_2023_smieciarka#1
2023-04-23 15:33:38 +02:00
Paweł Felcyn 675df76bfe Merge pull request 'bfs' (#19) from bfs into master
Reviewed-on: #19
2023-04-22 18:08:26 +02:00
Pawel Felcyn c22e86e22b fix bfs 2023-04-22 18:06:50 +02:00
Pawel Felcyn c5e6eadcae add function for moving dust car 2023-04-22 17:46:08 +02:00
Pawel Felcyn d0d9fb0309 dust car instance 2023-04-22 16:36:13 +02:00
Pawel Felcyn 7c44d65347 implement bfs algorythm 2023-04-22 16:17:00 +02:00
Pawel Felcyn f12eb5ba0d implement bfs algorythm 2023-04-22 16:16:36 +02:00
Paweł Felcyn 7ef1ccb0a3 Merge pull request 'states' (#18) from states into master
Reviewed-on: #18
2023-04-22 12:12:32 +02:00
Pawel Felcyn 2b10bb8650 garbage can cell type 2023-04-22 12:11:06 +02:00
Pawel Felcyn 9323b5a507 add agent action type 2023-04-22 12:06:01 +02:00
Pawel Felcyn aba8285469 street grid cell type 2023-04-22 12:04:08 +02:00
Pawel Felcyn ac19577346 add dust car rotation imgs 2023-04-22 11:45:32 +02:00
Paweł Felcyn bdd5d1defb Merge pull request 'fix can and car imgs to be renerable' (#17) from dust_car_img_error into master
Reviewed-on: #17
2023-04-15 20:57:30 +02:00
Pawel Felcyn 5f1acbb6f8 fix can and car imgs to be renerable 2023-04-15 20:55:42 +02:00
Paweł Felcyn 77032672bc Merge pull request 'add method for rendering can' (#16) from render_can into master
Reviewed-on: #16
2023-04-15 19:46:05 +02:00
Pawel Felcyn fa3868746a add method for rendering can 2023-04-15 19:37:56 +02:00
Paweł Felcyn f937ce349f Merge pull request 'zmiana rozdzielczosci obrazkow' (#15) from imgs_update into master
Reviewed-on: #15
Reviewed-by: Paweł Felcyn <pawfel1@st.amu.edu.pl>
2023-04-05 19:32:11 +02:00
Wiktor Szynaka b4e77de22c zmiana rozdzielczosci obrazkow 2023-04-05 19:31:06 +02:00
Paweł Felcyn 9841406878 Merge pull request 'streets_rendering' (#14) from streets_rendering into master
Reviewed-on: #14
2023-04-03 19:52:09 +02:00
Pawel Felcyn 693121ac00 city streets rendering 2023-04-03 19:51:06 +02:00
Pawel Felcyn 4fe38e3afc render exapmple street 2023-04-03 19:26:56 +02:00
Pawel Felcyn b8280a3854 add render method in city class 2023-04-03 15:49:28 +02:00
Pawel Felcyn ba49049cc3 add street class 2023-04-03 15:43:03 +02:00
Pawel Felcyn 51fdebbc00 add imgs of street 2023-04-03 15:29:36 +02:00
Pawel Felcyn 9f0cdbc5ff add method for rendering img in cell 2023-04-03 15:29:22 +02:00
Paweł Felcyn 5976f41f12 Merge pull request 'background' (#13) from background into master
Reviewed-on: #13
2023-04-03 15:10:06 +02:00
Pawel Felcyn e1c7e6d6e7 render grass background 2023-04-03 15:08:26 +02:00
Pawel Felcyn 697a7cdebb add grass background img 2023-04-03 14:58:28 +02:00
Paweł Felcyn 5e3cce852e Merge pull request 'add missing references' (#12) from fix_garbage_truck into master
Reviewed-on: #12
2023-03-27 11:52:37 +02:00
Pawel Felcyn fec421a3b8 add missing references 2023-03-27 11:50:23 +02:00
Paweł Felcyn 490b170ee4 Merge pull request 'add class of a city' (#11) from city_class into master
Reviewed-on: #11
Reviewed-by: Mikołaj Gawor <mikgaw@st.amu.edu.pl>
2023-03-27 11:44:05 +02:00
Pawel Felcyn c41f2a27a5 add class of a city 2023-03-26 21:29:40 +02:00
Paweł Felcyn 8501e7e7b4 Merge pull request 'GarbageTruck' (#10) from s464933-patch-1 into master
Reviewed-on: #10
Reviewed-by: Paweł Felcyn <pawfel1@st.amu.edu.pl>
2023-03-26 21:13:49 +02:00
Maksymilian Szygenda 18cc38b3ff Update 'garbageTruck.py' 2023-03-26 21:13:05 +02:00
Maksymilian Szygenda bfd78aee90 Update 'garbageTruck.py' 2023-03-26 20:58:43 +02:00
Maksymilian Szygenda 298fba3f6d Upload files to '' 2023-03-26 16:33:42 +02:00
Paweł Felcyn 29fcb83d83 Merge pull request 'garbageCan' (#9) from garbagecan into master
Reviewed-on: #9
2023-03-26 15:25:11 +02:00
Wiktor Szynaka f3a26b9653 garbageCan 2023-03-26 14:51:05 +02:00
Paweł Felcyn 94e65feaa9 Merge pull request 'add garbage class' (#8) from garbage into master
Reviewed-on: #8
Reviewed-by: Mikołaj Gawor <mikgaw@st.amu.edu.pl>
2023-03-25 17:50:08 +01:00
Pawel Felcyn 9b3902a163 add garbage class 2023-03-25 10:53:19 +01:00
Paweł Felcyn 27a5589146 Merge pull request 'replace house with container' (#7) from container_img into master
Reviewed-on: #7
2023-03-25 10:35:32 +01:00
Pawel Felcyn d340f2cebe replace house with container 2023-03-25 10:30:52 +01:00
Paweł Felcyn a364695ff1 Merge pull request 'modify readme' (#6) from project_desc into master
Reviewed-on: #6
2023-03-18 13:23:19 +01:00
Pawel Felcyn 4dedaf57cb modify readme 2023-03-18 13:22:01 +01:00
Paweł Felcyn dd54ef193f Merge pull request 'changed stick man to dust car, renamed variables' (#5) from changing_stick_man_to_dust_car into master
Reviewed-on: #5
2023-03-13 09:53:56 +01:00
majkellll 58437a4854 changed stick man to dust car, renamed variables 2023-03-13 08:49:34 +01:00
Paweł Felcyn 4c385d0674 Merge pull request 'dust_car_img' (#4) from dust_car_img into master
Reviewed-on: #4
Reviewed-by: Paweł Felcyn <pawfel1@st.amu.edu.pl>
2023-03-12 18:32:05 +01:00
majkellll 5de5994519 "add smaller dust car image" 2023-03-12 17:08:37 +01:00
majkellll 454fb8dcce add dust car image 2023-03-12 16:59:15 +01:00
Paweł Felcyn ca41c47dd9 Merge pull request 'movement' (#3) from movement into master
Reviewed-on: #3
2023-03-12 16:51:41 +01:00
Pawel Felcyn b8b2e5e319 rename stick man file 2023-03-12 16:49:32 +01:00
Pawel Felcyn 853b025a84 add stick man movement 2023-03-12 16:47:18 +01:00
Pawel Felcyn 9f7bc7f3e1 display stick man in window 2023-03-12 16:08:54 +01:00
Pawel Felcyn 03e2aea285 add stick man img 2023-03-11 15:17:35 +01:00
13579 changed files with 1192 additions and 4 deletions

3
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
# Default ignored files
/shelf/
/workspace.xml

View File

@ -1,2 +1,3 @@
# sztuczna_inteligencja_2023_smieciarka
Symulacja inteligentnej śmieciarki. Śmieciarka zbiera śmieci z kubłów wystawionych przez mieszkańców, samodzielnie je segreguje i zawozi na wysypisko.

7
agentActionType.py Normal file
View File

@ -0,0 +1,7 @@
from enum import Enum
class AgentActionType (Enum):
MOVE_FORWARD = 0
TURN_LEFT = 1
TURN_RIGHT = 2
UNKNOWN = None

7
agentOrientation.py Normal file
View File

@ -0,0 +1,7 @@
from enum import Enum
class AgentOrientation (Enum):
UP = 0
RIGHT = 1
DOWN = 2
LEFT = 3

10
agentState.py Normal file
View File

@ -0,0 +1,10 @@
from agentOrientation import AgentOrientation
from typing import Tuple
class AgentState:
orientation: AgentOrientation
position: Tuple[int, int]
def __init__(self, position: Tuple[int, int], orientation: AgentOrientation) -> None:
self.orientation = orientation
self.position = position

165
bfs.py Normal file
View File

@ -0,0 +1,165 @@
from agentState import AgentState
from typing import Dict, Tuple, List
from city import City
from gridCellType import GridCellType
from agentActionType import AgentActionType
from agentOrientation import AgentOrientation
from queue import Queue, PriorityQueue
from turnCar import turn_left_orientation, turn_right_orientation
class Successor: # klasa reprezentuje sukcesora, stan i akcję którą można po nim podjąć
def __init__(self, state: AgentState, action: AgentActionType, cost: int, predicted_cost: int) -> None:
self.state = state
self.action = action
self.cost = cost
self.predicted_cost = predicted_cost
class SuccessorList: # lista sukcesorów, czyli możliwych ścieżek po danym stanie
succ_list: list[Successor]
def __init__(self, succ_list: list[Successor]) -> None:
self.succ_list = succ_list
def __gt__(self, other):
return self.succ_list[-1].predicted_cost > other.succ_list[-1].predicted_cost
def __lt__(self, other):
return self.succ_list[-1].predicted_cost < other.succ_list[-1].predicted_cost
def find_path_to_nearest_can(startState: AgentState, grid: Dict[Tuple[int, int], GridCellType], city: City) -> List[
AgentActionType]: # znajduje ścieżkę do najbliższego kosza na smieci
visited: List[AgentState] = []
queue: PriorityQueue[SuccessorList] = PriorityQueue() # kolejka priorytetowa przechodująca listę sukcesorów
queue.put(SuccessorList([Successor(startState, AgentActionType.UNKNOWN, 0, _heuristics(startState.position, city))]))
while not queue.empty(): # dopóki kolejka nie jest pusta, pobiera z niej aktualny element
current = queue.get()
previous = current.succ_list[-1]
visited.append(previous.state)
if is_state_success(previous.state, grid): # jeśli ostatni stan w liście jest stanem końcowym (agent dotarł do śmietnika)
return extract_actions(current)
successors = get_successors(previous, grid, city)
for s in successors:
already_visited = False
for v in visited:
if v.position == s.state.position and v.orientation == s.state.orientation:
already_visited = True
break
if already_visited:
continue
if is_state_valid(s.state, grid):
new_list = current.succ_list.copy()
new_list.append(s)
queue.put(SuccessorList(new_list))
return []
def extract_actions(successors: SuccessorList) -> list[AgentActionType]: # wyodrębnienie akcji z listy sukcesorów, z pominięciem uknown
output: list[AgentActionType] = []
for s in successors.succ_list:
if s.action != AgentActionType.UNKNOWN:
output.append(s.action)
return output
def get_successors(succ: Successor, grid: Dict[Tuple[int, int], GridCellType], city: City) -> List[Successor]:
result: List[Successor] = [] # generuje następników dla danego stanu,
turn_left_cost = 1 + succ.cost
turn_left_state = AgentState(succ.state.position, turn_left_orientation(succ.state.orientation))
turn_left_heuristics = _heuristics(succ.state.position, city)
result.append(
Successor(turn_left_state, AgentActionType.TURN_LEFT, turn_left_cost, turn_left_cost + turn_left_heuristics))
turn_right_cost = 1 + succ.cost
turn_right_state = AgentState(succ.state.position, turn_right_orientation(succ.state.orientation))
turn_right_heuristics = _heuristics(succ.state.position, city)
result.append(
Successor(turn_right_state, AgentActionType.TURN_RIGHT, turn_right_cost,
turn_right_cost + turn_right_heuristics))
state_succ = move_forward_succ(succ, city, grid)
if state_succ is not None:
result.append(state_succ)
return result
def move_forward_succ(succ: Successor, city: City, grid: Dict[Tuple[int, int], GridCellType]) -> Successor:
position = get_next_cell(succ.state)
if position is None:
return None
cost = get_cost_for_action(AgentActionType.MOVE_FORWARD, grid[position]) + succ.cost
predicted_cost = cost + _heuristics(position, city)
new_state = AgentState(position, succ.state.orientation)
return Successor(new_state, AgentActionType.MOVE_FORWARD, cost, predicted_cost)
def get_next_cell(state: AgentState) -> Tuple[int, int]:
x, y = state.position
orientation = state.orientation
if orientation == AgentOrientation.UP:
if y - 1 < 1:
return None
return x, y - 1
elif orientation == AgentOrientation.DOWN:
if y + 1 > 27:
return None
return x, y + 1
elif orientation == AgentOrientation.LEFT:
if x - 1 < 1:
return None
return x - 1, y
elif x + 1 > 27:
return None
else:
return x + 1, y
def is_state_success(state: AgentState, grid: Dict[Tuple[int, int], GridCellType]) -> bool:
next_cell = get_next_cell(state)
try:
return grid[next_cell] == GridCellType.GARBAGE_CAN # agent dotarł do śmietnika
except KeyError:
return False
def get_cost_for_action(action: AgentActionType, cell_type: GridCellType) -> int:
if action in [AgentActionType.TURN_LEFT, AgentActionType.TURN_RIGHT]:
return 1
if cell_type == GridCellType.SPEED_BUMP and action == AgentActionType.MOVE_FORWARD:
return -10000
if action == AgentActionType.MOVE_FORWARD:
return 3
def is_state_valid(state: AgentState, grid: Dict[Tuple[int, int], GridCellType]) -> bool:
try:
return grid[state.position] == GridCellType.STREET_HORIZONTAL or grid[
state.position] == GridCellType.STREET_VERTICAL or grid[state.position] == GridCellType.SPEED_BUMP
except KeyError:
return False
def _heuristics(position: Tuple[int, int], city: City):
min_distance: int = 300
found_nonvisited: bool = False
for can in city.cans:
if can.is_visited:
continue
found_nonvisited = True
distance = 3 * (abs(position[0] - can.position[0]) + abs(position[1] - can.position[1]))
if distance < min_distance:
min_distance = distance
if found_nonvisited:
return min_distance
return -1

44
city.py Normal file
View File

@ -0,0 +1,44 @@
from typing import List, Dict, Tuple
from garbageCan import GarbageCan
from speedBump import SpeedBump
from street import Street
from gameContext import GameContext
class City:
cans: List[GarbageCan]
bumps: List[SpeedBump]
streets: List[Street]
cans_dict: Dict[Tuple[int, int], GarbageCan] = {}
def __init__(self) -> None:
self.cans = []
self.streets = []
self.bumps = []
def add_can(self, can: GarbageCan) -> None:
self.cans.append(can)
self.cans_dict[can.position] = can
def add_street(self, street: Street) -> None:
self.streets.append(street)
def add_bump(self, bump: SpeedBump) -> None:
self.streets.append(bump)
def render_city(self, game_context: GameContext) -> None:
self._render_streets(game_context)
self._render_nodes(game_context)
self._render_bumps(game_context)
def _render_streets(self, game_context: GameContext) -> None:
for street in self.streets:
street.render(game_context)
def _render_nodes(self, game_context: GameContext) -> None:
for node in self.cans:
node.render(game_context)
def _render_bumps(self, game_context: GameContext) -> None:
for bump in self.bumps:
bump.render(game_context)

36
gameContext.py Normal file
View File

@ -0,0 +1,36 @@
from typing import Tuple, List, Dict
import pygame
from PIL import Image
from gridCellType import GridCellType
class GameContext:
dust_car_speed = 20
dust_car_position_x = 0
dust_car_position_y = 0
dust_car_pygame = None
dust_car_pil = None
canvas = None
_cell_size: int = 30
city = None
grid: Dict[Tuple[int, int], GridCellType] = {}
dust_car = None
landfill = None
def __init__(self) -> None:
self._init_grid()
def _init_grid(self) -> None:
for i in range(1, 28):
for j in range(1, 28):
self.grid[(i, j)] = GridCellType.NOTHING
def render_in_cell(self, cell: Tuple[int, int], img_path: str):
img = Image.open(img_path)
pygame_img = pygame.image.frombuffer(img.tobytes(), (self._cell_size,self._cell_size), 'RGB')
start_x = (cell[0] - 1) * self._cell_size
start_y = (cell[1] - 1) * self._cell_size
self.canvas.blit(pygame_img, (start_x, start_y))

View File

@ -1,4 +1,5 @@
import pygame
from gameContext import GameContext
def handle_game_event(event):
return
def handle_game_event(event, game_context: GameContext):
pass

41
garbage.py Normal file
View File

@ -0,0 +1,41 @@
from enum import Enum
class GarbageType(Enum):
PAPER = 0,
PLASTIC_AND_METAL = 1
GLASS = 3
BIO = 4
MIXED = 5
class Garbage:
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, shape: str, flexibility: str, does_smell: str, weight: str, size: str, color: str, softness: str, does_din: str) -> None:
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_type: GarbageType
src: Garbage
def __init__(self, src: Garbage, garbage_type: GarbageType) -> None:
self.garbage_type = garbage_type
self.src = src

26
garbageCan.py Normal file
View File

@ -0,0 +1,26 @@
from garbage import Garbage
from typing import List, Tuple
from gameContext import GameContext
from gridCellType import GridCellType
class GarbageCan:
position: Tuple[int, int]
garbage: List[Garbage]
is_visited: bool
def __init__(self, position: Tuple[int, int]) -> None:
self.position = position
self.garbage = []
self.is_visited = False
def add_garbage(self, garbage: Garbage) -> None:
self.garbage.append(garbage)
def remove_garbage(self, garbage: Garbage) -> None:
self.garbage.remove(garbage)
def render(self, game_context: GameContext) -> None:
game_context.render_in_cell(self.position, "imgs/container.png")
game_context.grid[self.position] = GridCellType.GARBAGE_CAN

50
garbageTruck.py Normal file
View File

@ -0,0 +1,50 @@
from typing import List, Tuple
from agentOrientation import AgentOrientation
from garbage import GarbageType, RecognizedGarbage
from gameContext import GameContext
class GarbageTruck:
position: Tuple[int, int]
paper: List[RecognizedGarbage]
plastic_and_metal: List[RecognizedGarbage]
glass: List[RecognizedGarbage]
bio: List[RecognizedGarbage]
mixed: List[RecognizedGarbage]
orientation: AgentOrientation = AgentOrientation.RIGHT
def __init__(self, position: Tuple[int, int]) -> None:
self.position = position
self.paper = []
self.plastic_and_metal = []
self.glass = []
self.bio = []
self.mixed = []
def sort_garbage(self, RecognizedGarbage) -> None:
if RecognizedGarbage.garbage_type == GarbageType.PAPER:
self.paper.append(RecognizedGarbage)
elif RecognizedGarbage.garbage_type == GarbageType.PLASTIC_AND_METAL:
self.plastic_and_metal.append(RecognizedGarbage)
elif RecognizedGarbage.garbage_type == GarbageType.GLASS:
self.glass.append(RecognizedGarbage)
elif RecognizedGarbage.garbage_type == GarbageType.BIO:
self.bio.append(RecognizedGarbage)
elif RecognizedGarbage.garbage_type == GarbageType.MIXED:
self.mixed.append(RecognizedGarbage)
def render(self, game_context: GameContext) -> None:
path = None
if self.orientation == AgentOrientation.LEFT:
path = 'imgs/dust_car_left.png'
elif self.orientation == AgentOrientation.RIGHT:
path = 'imgs/dust_car_right.png'
elif self.orientation == AgentOrientation.UP:
path = 'imgs/dust_car_up.png'
elif self.orientation == AgentOrientation.DOWN:
path = 'imgs/dust_car_down.png'
game_context.render_in_cell(self.position, path)

11
gridCellType.py Normal file
View File

@ -0,0 +1,11 @@
from enum import Enum
class GridCellType(Enum):
NOTHING = 0
STREET_VERTICAL = 1
STREET_HORIZONTAL = 2
GARBAGE_CAN = 3
VISITED_GARBAGE_CAN = 4
LANDFILL = 5
SPEED_BUMP = 6
UNKNOWN = None

BIN
imgs/background.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 238 KiB

BIN
imgs/container.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 750 B

BIN
imgs/dust_car_down.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

BIN
imgs/dust_car_left.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 751 B

BIN
imgs/dust_car_right.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 751 B

BIN
imgs/dust_car_up.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.3 KiB

BIN
imgs/landfill.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 857 B

BIN
imgs/speed_bump.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 293 B

BIN
imgs/street_horizontal.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 165 B

BIN
imgs/street_vertical.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 166 B

39
landfill.py Normal file
View File

@ -0,0 +1,39 @@
from typing import Tuple
from gameContext import GameContext
from garbage import RecognizedGarbage
from gridCellType import GridCellType
class Landfill:
position: Tuple[int, int] = []
paper: list[RecognizedGarbage]
plastic_and_metal: list[RecognizedGarbage] = []
glass: list[RecognizedGarbage] = []
bio: list[RecognizedGarbage] = []
mixed: list[RecognizedGarbage] = []
def __init__(self, position: Tuple[int, int]) -> None:
self.position = position
def add_paper(self, paper: list[RecognizedGarbage]) -> None:
for p in paper:
self.paper.append(p)
def add_plastic_and_metal(self, plastic_and_metal: list[RecognizedGarbage]) -> None:
for p in plastic_and_metal:
self.plastic_and_metal.append(p)
def add_glass(self, glass: list[RecognizedGarbage]) -> None:
for g in glass:
self.glass.append(g)
def add_paper(self, bio: list[RecognizedGarbage]) -> None:
for b in bio:
self.bio.append(b)
def add_mixed(self, mixed: list[RecognizedGarbage]) -> None:
for m in mixed:
self.mixed.append(m)
def render(self, game_context: GameContext) -> None:
game_context.render_in_cell(self.position, 'imgs/landfill.png')
game_context.grid[self.position] = GridCellType.LANDFILL

View File

@ -0,0 +1,95 @@
import os
from trainingData import TrainingData
from sklearn import tree
import joblib
from sklearn.preprocessing import LabelEncoder, OneHotEncoder
import numpy as np
def _read_training_data() -> TrainingData:
attributes = []
classes = []
location = os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__)))
file = open(os.path.join(location, 'training_data.csv'))
lines = file.readlines()[1:]
file.close()
for line in lines:
actual_row = line.replace('\n', '')
values = actual_row.split(',')
line_attributes = values[:-1]
line_class = values[-1]
attributes.append(line_attributes)
classes.append(line_class.strip())
return TrainingData(attributes, classes)
def _attributes_to_floats(attributes: list[str]) -> list[float]:
output: list[float] = []
if attributes[0] == 'Longitiudonal':
output.append(0)
elif attributes[0] == 'Round':
output.append(1)
elif attributes[0] == 'Flat':
output.append(2)
elif attributes[0] == 'Irregular':
output.append(3)
if attributes[1] == 'Low':
output.append(0)
elif attributes[1] == 'Medium':
output.append(1)
elif attributes[1] == 'High':
output.append(2)
if attributes[2] == "Yes":
output.append(0)
else:
output.append(1)
if attributes[3] == 'Low':
output.append(0)
elif attributes[3] == 'Medium':
output.append(1)
elif attributes[3] == 'High':
output.append(2)
if attributes[4] == 'Low':
output.append(0)
elif attributes[4] == 'Medium':
output.append(1)
elif attributes[4] == 'High':
output.append(2)
if attributes[5] == 'Transparent':
output.append(0)
elif attributes[5] == 'Light':
output.append(1)
elif attributes[5] == 'Dark':
output.append(2)
elif attributes[5] == "Colorful":
output.append(3)
if attributes[6] == 'Low':
output.append(0)
elif attributes[6] == 'Medium':
output.append(1)
elif attributes[6] == 'High':
output.append(2)
if attributes[7] == "Yes":
output.append(0)
else:
output.append(1)
return output
trainning_data = _read_training_data()
X = trainning_data.attributes
Y = trainning_data.classes
model = tree.DecisionTreeClassifier()
encoded = [_attributes_to_floats(x) for x in X]
dtc = model.fit(encoded, Y)
joblib.dump(model, 'model.pkl')

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Some files were not shown because too many files have changed in this diff Show More