Compare commits

..

No commits in common. "dd34b7341aba9b9cf3ad9181fa115cf928ea2242" and "65bef5195862b60988850507d52ddc8372f68cd8" have entirely different histories.

7 changed files with 7 additions and 31 deletions

16
bfs.py
View File

@ -1,6 +1,5 @@
from agentState import AgentState
from typing import Dict, Tuple
from city import City
from gridCellType import GridCellType
from agentActionType import AgentActionType
from agentOrientation import AgentOrientation
@ -106,18 +105,3 @@ def is_state_valid(state: AgentState, grid: Dict[Tuple[int, int], GridCellType])
return grid[state.position] == GridCellType.STREET_HORIZONTAL or grid[state.position] == GridCellType.STREET_VERTICAL or grid[state.position] == GridCellType.SPEED_BUMP
except:
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

10
city.py
View File

@ -1,23 +1,21 @@
from typing import List, Dict, Tuple
from typing import List
from garbageCan import GarbageCan
from speedBump import SpeedBump
from street import Street
from gameContext import GameContext
class City:
cans: List[GarbageCan]
nodes: List[GarbageCan]
bumps: List[SpeedBump]
streets: List[Street]
cans_dict: Dict[Tuple[int, int], GarbageCan] = {}
def __init__(self) -> None:
self.nodes = []
self.streets = []
self.bumps = []
def add_can(self, can: GarbageCan) -> None:
self.nodes.append(can)
self.cans_dict[can.position] = can
def add_node(self, node: GarbageCan) -> None:
self.nodes.append(node)
def add_street(self, street: Street) -> None:
self.streets.append(street)

View File

@ -16,8 +16,6 @@ class GameContext:
dust_car = None
landfill = None
def __init__(self) -> None:
self._init_grid()

View File

@ -6,12 +6,10 @@ 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)

View File

@ -8,4 +8,3 @@ class GridCellType(Enum):
VISITED_GARBAGE_CAN = 4
LANDFILL = 5
SPEED_BUMP = 6
UNKNOWN = None

View File

@ -19,7 +19,6 @@ def collect_garbage(game_context: GameContext) -> None:
move_dust_car(path, game_context)
next_position = calculate_next_position(game_context.dust_car)
game_context.grid[next_position] = GridCellType.VISITED_GARBAGE_CAN
game_context.city.cans_dict[next_position].is_visited = True
pass
def move_dust_car(actions: list[AgentActionType], game_context: GameContext) -> None:

View File

@ -35,7 +35,7 @@ def create_city() -> City:
for s in streets:
city.add_street(s)
for t in trashcans:
city.add_can(t)
city.add_node(t)
for b in bumps:
city.add_bump(b)
return city