Compare commits
No commits in common. "65bef5195862b60988850507d52ddc8372f68cd8" and "aec533956d171d8296f376e7ffe420d72675ccda" have entirely different histories.
65bef51958
...
aec533956d
@ -4,4 +4,5 @@ class AgentActionType (Enum):
|
|||||||
MOVE_FORWARD = 0
|
MOVE_FORWARD = 0
|
||||||
TURN_LEFT = 1
|
TURN_LEFT = 1
|
||||||
TURN_RIGHT = 2
|
TURN_RIGHT = 2
|
||||||
|
EMPTY_CAN = 3
|
||||||
UNKNOWN = None
|
UNKNOWN = None
|
14
bfs.py
14
bfs.py
@ -9,12 +9,10 @@ from turnCar import turn_left_orientation, turn_right_orientation
|
|||||||
class Succ:
|
class Succ:
|
||||||
state: AgentState
|
state: AgentState
|
||||||
action: AgentActionType
|
action: AgentActionType
|
||||||
##cost: int
|
|
||||||
|
|
||||||
def __init__(self, state: AgentState, action: AgentActionType) -> None:
|
def __init__(self, state: AgentState, action: AgentActionType) -> None:
|
||||||
self.state = state
|
self.state = state
|
||||||
self.action = action
|
self.action = action
|
||||||
##self.cost = cost
|
|
||||||
|
|
||||||
def find_path_to_nearest_can(startState: AgentState, grid: Dict[Tuple[int, int], GridCellType]) -> list[AgentActionType]:
|
def find_path_to_nearest_can(startState: AgentState, grid: Dict[Tuple[int, int], GridCellType]) -> list[AgentActionType]:
|
||||||
q: Queue[list[Succ]] = Queue()
|
q: Queue[list[Succ]] = Queue()
|
||||||
@ -90,18 +88,8 @@ def is_state_success(state: AgentState, grid: Dict[Tuple[int, int], GridCellType
|
|||||||
except:
|
except:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
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:
|
def is_state_valid(state: AgentState, grid: Dict[Tuple[int, int], GridCellType]) -> bool:
|
||||||
try:
|
try:
|
||||||
return grid[state.position] == GridCellType.STREET_HORIZONTAL or grid[state.position] == GridCellType.STREET_VERTICAL or grid[state.position] == GridCellType.SPEED_BUMP
|
return grid[state.position] == GridCellType.STREET_HORIZONTAL or grid[state.position] == GridCellType.STREET_VERTICAL
|
||||||
except:
|
except:
|
||||||
return False
|
return False
|
25
city.py
25
city.py
@ -1,32 +1,33 @@
|
|||||||
from typing import List
|
from typing import List
|
||||||
from garbageCan import GarbageCan
|
from garbageCan import GarbageCan
|
||||||
from speedBump import SpeedBump
|
|
||||||
from street import Street
|
from street import Street
|
||||||
from gameContext import GameContext
|
from gameContext import GameContext
|
||||||
|
|
||||||
|
class Node:
|
||||||
|
garbageCan: GarbageCan
|
||||||
|
id: int
|
||||||
|
|
||||||
|
def __init__(self, id: int, can: GarbageCan) -> None:
|
||||||
|
self.id
|
||||||
|
self.can = can
|
||||||
|
|
||||||
class City:
|
class City:
|
||||||
nodes: List[GarbageCan]
|
nodes: List[GarbageCan]
|
||||||
bumps: List[SpeedBump]
|
|
||||||
streets: List[Street]
|
streets: List[Street]
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self.nodes = []
|
self.nodes = []
|
||||||
self.streets = []
|
self.streets = []
|
||||||
self.bumps = []
|
|
||||||
|
|
||||||
def add_node(self, node: GarbageCan) -> None:
|
def add_node(self, node: GarbageCan) -> None:
|
||||||
self.nodes.append(node)
|
self.nodes.append(node)
|
||||||
|
|
||||||
def add_street(self, street: Street) -> None:
|
def add_street(self, street: Street) -> None:
|
||||||
self.streets.append(street)
|
self.streets.append(street)
|
||||||
|
|
||||||
def add_bump(self, bump: SpeedBump) -> None:
|
|
||||||
self.streets.append(bump)
|
|
||||||
|
|
||||||
def render_city(self, game_context: GameContext) -> None:
|
def render_city(self, game_context: GameContext) -> None:
|
||||||
self._render_streets(game_context)
|
self._render_streets(game_context)
|
||||||
self._render_nodes(game_context)
|
self._render_nodes(game_context)
|
||||||
self._render_bumps(game_context)
|
|
||||||
|
|
||||||
def _render_streets(self, game_context: GameContext) -> None:
|
def _render_streets(self, game_context: GameContext) -> None:
|
||||||
for street in self.streets:
|
for street in self.streets:
|
||||||
@ -34,8 +35,4 @@ class City:
|
|||||||
|
|
||||||
def _render_nodes(self, game_context: GameContext) -> None:
|
def _render_nodes(self, game_context: GameContext) -> None:
|
||||||
for node in self.nodes:
|
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)
|
|
@ -6,5 +6,4 @@ class GridCellType(Enum):
|
|||||||
STREET_HORIZONTAL = 2
|
STREET_HORIZONTAL = 2
|
||||||
GARBAGE_CAN = 3
|
GARBAGE_CAN = 3
|
||||||
VISITED_GARBAGE_CAN = 4
|
VISITED_GARBAGE_CAN = 4
|
||||||
LANDFILL = 5
|
LANDFILL = 5
|
||||||
SPEED_BUMP = 6
|
|
Binary file not shown.
Before Width: | Height: | Size: 293 B |
@ -38,8 +38,6 @@ def move_dust_car(actions: list[AgentActionType], game_context: GameContext) ->
|
|||||||
game_context.render_in_cell(street_position, "imgs/street_horizontal.png")
|
game_context.render_in_cell(street_position, "imgs/street_horizontal.png")
|
||||||
elif game_context.grid[street_position] == GridCellType.STREET_VERTICAL:
|
elif game_context.grid[street_position] == GridCellType.STREET_VERTICAL:
|
||||||
game_context.render_in_cell(street_position, "imgs/street_vertical.png")
|
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()
|
pygame.display.update()
|
||||||
time.sleep(0.15)
|
time.sleep(0.15)
|
||||||
|
|
||||||
|
13
speedBump.py
13
speedBump.py
@ -1,13 +0,0 @@
|
|||||||
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
|
|
11
startup.py
11
startup.py
@ -6,7 +6,6 @@ from typing import Tuple, List
|
|||||||
from street import Street, StreetType
|
from street import Street, StreetType
|
||||||
from garbageTruck import GarbageTruck
|
from garbageTruck import GarbageTruck
|
||||||
from garbageCan import GarbageCan
|
from garbageCan import GarbageCan
|
||||||
from speedBump import SpeedBump
|
|
||||||
from landfill import Landfill
|
from landfill import Landfill
|
||||||
|
|
||||||
|
|
||||||
@ -31,13 +30,10 @@ 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()
|
|
||||||
for s in streets:
|
for s in streets:
|
||||||
city.add_street(s)
|
city.add_street(s)
|
||||||
for t in trashcans:
|
for t in trashcans:
|
||||||
city.add_node(t)
|
city.add_node(t)
|
||||||
for b in bumps:
|
|
||||||
city.add_bump(b)
|
|
||||||
return city
|
return city
|
||||||
|
|
||||||
def create_streets() -> List[Street]:
|
def create_streets() -> List[Street]:
|
||||||
@ -65,13 +61,6 @@ 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]:
|
|
||||||
bumps = []
|
|
||||||
bumps.append(SpeedBump((10, 9)))
|
|
||||||
bumps.append(SpeedBump((12, 16)))
|
|
||||||
return bumps
|
|
||||||
|
|
||||||
|
|
||||||
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)
|
||||||
|
Loading…
Reference in New Issue
Block a user