add action cost function and remove node class
This commit is contained in:
parent
4ab84deaf3
commit
76eb4771a2
8
bfs.py
8
bfs.py
@ -9,10 +9,12 @@ 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()
|
||||||
@ -88,6 +90,12 @@ def is_state_success(state: AgentState, grid: Dict[Tuple[int, int], GridCellType
|
|||||||
except:
|
except:
|
||||||
return False
|
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:
|
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 or grid[state.position] == GridCellType.SPEED_BUMP
|
||||||
|
14
city.py
14
city.py
@ -2,19 +2,7 @@ from typing import List
|
|||||||
from garbageCan import GarbageCan
|
from garbageCan import GarbageCan
|
||||||
from speedBump import SpeedBump
|
from speedBump import SpeedBump
|
||||||
from street import Street
|
from street import Street
|
||||||
from gameContext import GameContext
|
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
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class City:
|
class City:
|
||||||
nodes: List[GarbageCan]
|
nodes: List[GarbageCan]
|
||||||
|
Loading…
Reference in New Issue
Block a user