From af42c841862a607850be57d6557b008048d8828e Mon Sep 17 00:00:00 2001 From: Wiktor Szynaka Date: Sat, 13 May 2023 19:30:00 +0200 Subject: [PATCH 1/7] speed bumps --- bfs.py | 2 +- city.py | 24 ++++++++++++++++++++++-- gridCellType.py | 3 ++- imgs/speed_bump.png | Bin 0 -> 293 bytes movement.py | 2 ++ speedBump.py | 13 +++++++++++++ startup.py | 11 +++++++++++ 7 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 imgs/speed_bump.png create mode 100644 speedBump.py diff --git a/bfs.py b/bfs.py index 2c7c646..12c09f4 100644 --- a/bfs.py +++ b/bfs.py @@ -90,6 +90,6 @@ def is_state_success(state: AgentState, grid: Dict[Tuple[int, int], GridCellType 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 + return grid[state.position] == GridCellType.STREET_HORIZONTAL or grid[state.position] == GridCellType.STREET_VERTICAL or grid[state.position] == GridCellType.SPEED_BUMP except: return False \ No newline at end of file diff --git a/city.py b/city.py index b16c6ab..7360207 100644 --- a/city.py +++ b/city.py @@ -1,5 +1,6 @@ from typing import List from garbageCan import GarbageCan +from speedBump import SpeedBump from street import Street from gameContext import GameContext @@ -10,24 +11,39 @@ class Node: def __init__(self, id: int, can: GarbageCan) -> None: self.id self.can = can - + +class Bump: + speedBump: SpeedBump + id: int + + def __init__(self, id: int, bump: SpeedBump) -> None: + self.id + self.bump = bump + + class City: nodes: List[GarbageCan] + bumps: List[SpeedBump] streets: List[Street] def __init__(self) -> None: self.nodes = [] self.streets = [] + self.bumps = [] def add_node(self, node: GarbageCan) -> None: self.nodes.append(node) 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: @@ -35,4 +51,8 @@ class City: def _render_nodes(self, game_context: GameContext) -> None: for node in self.nodes: - node.render(game_context) \ No newline at end of file + node.render(game_context) + + def _render_bumps(self, game_context: GameContext) -> None: + for bump in self.bumps: + bump.render(game_context) \ No newline at end of file diff --git a/gridCellType.py b/gridCellType.py index fd88aab..f8a637c 100644 --- a/gridCellType.py +++ b/gridCellType.py @@ -6,4 +6,5 @@ class GridCellType(Enum): STREET_HORIZONTAL = 2 GARBAGE_CAN = 3 VISITED_GARBAGE_CAN = 4 - LANDFILL = 5 \ No newline at end of file + LANDFILL = 5 + SPEED_BUMP = 6 \ No newline at end of file diff --git a/imgs/speed_bump.png b/imgs/speed_bump.png new file mode 100644 index 0000000000000000000000000000000000000000..0c7114c9c40e72af9f18c211613a4c3328f061a7 GIT binary patch literal 293 zcmeAS@N?(olHy`uVBq!ia0vp^av;pX1SGcvS$+jljKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBugD~Uq{1quc!Cjs%jv*f2d(S&^9Wmf>zIgBdj^f5Eu1YMY z^WHc-Ul{w5f3Mq%^0n2+g#*2kCFgax-4c7$`C_SIyZR%Q+~|)kGRty>{ayY%w44yO zW3tJPfIUalc=tV>rm^&(_;aD&Egu7QE_xqs&$RHl?Re2sYW0K88%wnLKe$Y}v`ySb z@Tv*eu-q>7MRSjZ*$B30zBz0%{YUk$pT6b)H@VDWi|3qvW68nocZ8Oj{CE_zXrh^2 jmugk!4+GxWUnI=UBTYolswVFQ`hvmJ)z4*}Q$iB}|DJVg literal 0 HcmV?d00001 diff --git a/movement.py b/movement.py index 8b8fe07..8cee448 100644 --- a/movement.py +++ b/movement.py @@ -38,6 +38,8 @@ def move_dust_car(actions: list[AgentActionType], game_context: GameContext) -> game_context.render_in_cell(street_position, "imgs/street_horizontal.png") elif game_context.grid[street_position] == GridCellType.STREET_VERTICAL: game_context.render_in_cell(street_position, "imgs/street_vertical.png") + elif game_context.grid[street_position] == GridCellType.SPEED_BUMP: + game_context.render_in_cell(street_position, "imgs/speed_bump.png") pygame.display.update() time.sleep(0.15) diff --git a/speedBump.py b/speedBump.py new file mode 100644 index 0000000..07119b8 --- /dev/null +++ b/speedBump.py @@ -0,0 +1,13 @@ +from typing import List, Tuple +from gameContext import GameContext +from gridCellType import GridCellType + +class SpeedBump: + position: Tuple[int, int] + + def __init__(self, position: Tuple[int, int]) -> None: + self.position = position + + def render(self, game_context: GameContext) -> None: + game_context.render_in_cell(self.position, "imgs/speed_bump.png") + game_context.grid[self.position] = GridCellType.SPEED_BUMP \ No newline at end of file diff --git a/startup.py b/startup.py index f5b7279..de8657b 100644 --- a/startup.py +++ b/startup.py @@ -6,6 +6,7 @@ from typing import Tuple, List from street import Street, StreetType from garbageTruck import GarbageTruck from garbageCan import GarbageCan +from speedBump import SpeedBump from landfill import Landfill @@ -30,10 +31,13 @@ def create_city() -> City: city: City = City() streets = create_streets() trashcans = create_trashcans() + bumps = create_speed_bumps() for s in streets: city.add_street(s) for t in trashcans: city.add_node(t) + for b in bumps: + city.add_bump(b) return city def create_streets() -> List[Street]: @@ -61,6 +65,13 @@ def create_trashcans() -> List[GarbageCan]: trashcans.append(GarbageCan((26, 4))) return trashcans +def create_speed_bumps() -> List[SpeedBump]: + bumps = [] + bumps.append(SpeedBump((10, 10))) + bumps.append(SpeedBump((12, 16))) + return bumps + + def _create_landfill(game_context: GameContext) -> None: landfil_position = (23,24) landfill = Landfill(landfil_position) -- 2.20.1 From f0d6001efa9ede71bea09abb383058ed2a1167ed Mon Sep 17 00:00:00 2001 From: Wiktor Szynaka Date: Sat, 13 May 2023 19:41:19 +0200 Subject: [PATCH 2/7] speed bumps --- startup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/startup.py b/startup.py index de8657b..30c2740 100644 --- a/startup.py +++ b/startup.py @@ -67,7 +67,7 @@ def create_trashcans() -> List[GarbageCan]: def create_speed_bumps() -> List[SpeedBump]: bumps = [] - bumps.append(SpeedBump((10, 10))) + bumps.append(SpeedBump((10, 9))) bumps.append(SpeedBump((12, 16))) return bumps -- 2.20.1 From 4ab84deaf3e658ed770375a8cd44b2a2ecb803bf Mon Sep 17 00:00:00 2001 From: Wiktor Szynaka Date: Sat, 13 May 2023 20:02:42 +0200 Subject: [PATCH 3/7] speed bumps --- city.py | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/city.py b/city.py index 7360207..74e7483 100644 --- a/city.py +++ b/city.py @@ -6,19 +6,14 @@ from gameContext import GameContext class Node: garbageCan: GarbageCan - id: int - - def __init__(self, id: int, can: GarbageCan) -> None: - self.id - self.can = can - -class Bump: speedBump: SpeedBump id: int - - def __init__(self, id: int, bump: SpeedBump) -> None: + + def __init__(self, id: int, can: GarbageCan, bump: SpeedBump) -> None: self.id + self.can = can self.bump = bump + class City: -- 2.20.1 From 76eb4771a2fae2ad7b2d0a24a924806d2d87301a Mon Sep 17 00:00:00 2001 From: Wiktor Szynaka Date: Sat, 13 May 2023 20:20:04 +0200 Subject: [PATCH 4/7] add action cost function and remove node class --- bfs.py | 8 ++++++++ city.py | 14 +------------- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/bfs.py b/bfs.py index 12c09f4..a1cc10a 100644 --- a/bfs.py +++ b/bfs.py @@ -9,10 +9,12 @@ from turnCar import turn_left_orientation, turn_right_orientation class Succ: state: AgentState action: AgentActionType + cost: int def __init__(self, state: AgentState, action: AgentActionType) -> None: self.state = state self.action = action + self.cost = cost def find_path_to_nearest_can(startState: AgentState, grid: Dict[Tuple[int, int], GridCellType]) -> list[AgentActionType]: q: Queue[list[Succ]] = Queue() @@ -88,6 +90,12 @@ def is_state_success(state: AgentState, grid: Dict[Tuple[int, int], GridCellType except: return False +def get_cost_for_cell_type(cell_type: GridCellType) -> int: + if cell_type == GridCellType.SPEED_BUMP: + return 10 + else: + return 1 + 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 diff --git a/city.py b/city.py index 74e7483..2cd1a1f 100644 --- a/city.py +++ b/city.py @@ -2,19 +2,7 @@ from typing import List from garbageCan import GarbageCan from speedBump import SpeedBump from street import Street -from gameContext import GameContext - -class Node: - garbageCan: GarbageCan - speedBump: SpeedBump - id: int - - def __init__(self, id: int, can: GarbageCan, bump: SpeedBump) -> None: - self.id - self.can = can - self.bump = bump - - +from gameContext import GameContext class City: nodes: List[GarbageCan] -- 2.20.1 From b25a36e8725df6cab2cdf7825eaa923fbd4f7786 Mon Sep 17 00:00:00 2001 From: Wiktor Szynaka Date: Sat, 13 May 2023 21:00:13 +0200 Subject: [PATCH 5/7] action costs --- bfs.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/bfs.py b/bfs.py index a1cc10a..6a709c0 100644 --- a/bfs.py +++ b/bfs.py @@ -90,11 +90,15 @@ def is_state_success(state: AgentState, grid: Dict[Tuple[int, int], GridCellType except: return False -def get_cost_for_cell_type(cell_type: GridCellType) -> int: - if cell_type == GridCellType.SPEED_BUMP: - return 10 - else: +def get_cost_for_action(action: AgentActionType, cell_type: GridCellType) -> int: + if action == AgentActionType.TURN_LEFT or action == AgentActionType.TURN_RIGHT: return 1 + if cell_type == GridCellType.SPEED_BUMP: + if action == AgentActionType.MOVE_FORWARD: + return 10 + if action == AgentActionType.MOVE_FORWARD: + return 3 + def is_state_valid(state: AgentState, grid: Dict[Tuple[int, int], GridCellType]) -> bool: try: -- 2.20.1 From f7c91e92aa956f3eb408351c6f89f17789b19c77 Mon Sep 17 00:00:00 2001 From: Wiktor Szynaka Date: Sat, 13 May 2023 21:04:57 +0200 Subject: [PATCH 6/7] deleted empty can enum --- agentActionType.py | 1 - 1 file changed, 1 deletion(-) diff --git a/agentActionType.py b/agentActionType.py index 10fe0d8..abbf382 100644 --- a/agentActionType.py +++ b/agentActionType.py @@ -4,5 +4,4 @@ class AgentActionType (Enum): MOVE_FORWARD = 0 TURN_LEFT = 1 TURN_RIGHT = 2 - EMPTY_CAN = 3 UNKNOWN = None \ No newline at end of file -- 2.20.1 From a2d6cc688b9472b3c5cc4471623a1b8e47a63fde Mon Sep 17 00:00:00 2001 From: Wiktor Szynaka Date: Sat, 13 May 2023 21:17:30 +0200 Subject: [PATCH 7/7] correction --- bfs.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bfs.py b/bfs.py index 6a709c0..6766491 100644 --- a/bfs.py +++ b/bfs.py @@ -9,12 +9,12 @@ from turnCar import turn_left_orientation, turn_right_orientation class Succ: state: AgentState action: AgentActionType - cost: int + ##cost: int def __init__(self, state: AgentState, action: AgentActionType) -> None: self.state = state self.action = action - self.cost = cost + ##self.cost = cost def find_path_to_nearest_can(startState: AgentState, grid: Dict[Tuple[int, int], GridCellType]) -> list[AgentActionType]: q: Queue[list[Succ]] = Queue() -- 2.20.1