speed bumps

This commit is contained in:
Wiktor Szynaka 2023-05-13 19:30:00 +02:00
parent aec533956d
commit af42c84186
7 changed files with 51 additions and 4 deletions

2
bfs.py
View File

@ -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

24
city.py
View File

@ -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)
node.render(game_context)
def _render_bumps(self, game_context: GameContext) -> None:
for bump in self.bumps:
bump.render(game_context)

View File

@ -6,4 +6,5 @@ class GridCellType(Enum):
STREET_HORIZONTAL = 2
GARBAGE_CAN = 3
VISITED_GARBAGE_CAN = 4
LANDFILL = 5
LANDFILL = 5
SPEED_BUMP = 6

BIN
imgs/speed_bump.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 293 B

View File

@ -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)

13
speedBump.py Normal file
View File

@ -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

View File

@ -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)