2022-04-11 19:18:03 +02:00
|
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
from dataclasses import dataclass, field
|
2022-04-11 19:49:32 +02:00
|
|
|
from enum import Enum, unique
|
|
|
|
from typing import Tuple, Optional, List
|
2022-04-11 19:18:03 +02:00
|
|
|
|
2022-04-11 19:49:32 +02:00
|
|
|
|
|
|
|
@unique
|
|
|
|
class Direction(Enum):
|
|
|
|
LEFT = (0, -1)
|
|
|
|
RIGHT = (0, 1)
|
|
|
|
UP = (-1, 0)
|
|
|
|
DOWN = (1, 0)
|
|
|
|
|
|
|
|
|
|
|
|
@unique
|
|
|
|
class Action(Enum):
|
|
|
|
TURN_LEFT = 'TURN_LEFT'
|
|
|
|
TURN_RIGHT = 'TURN_RIGHT'
|
|
|
|
FORWARD = 'FORWARD'
|
2022-04-11 19:18:03 +02:00
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
class State:
|
|
|
|
position: Tuple[int, int]
|
|
|
|
direction: Direction
|
|
|
|
|
|
|
|
|
|
|
|
@dataclass
|
|
|
|
class Node:
|
|
|
|
state: State
|
|
|
|
parent: Optional[Node]
|
2022-04-11 19:49:32 +02:00
|
|
|
action: Action
|
2022-04-11 19:18:03 +02:00
|
|
|
cost: int = field(init=False)
|
|
|
|
depth: int = field(init=False)
|
|
|
|
|
|
|
|
def __post_init__(self) -> None:
|
|
|
|
self.cost = 0 if not self.parent else self.parent.cost + 1
|
|
|
|
self.depth = self.cost
|
2022-04-11 19:49:32 +02:00
|
|
|
|
|
|
|
def __eq__(self, other: Node) -> bool:
|
|
|
|
return self.state == other.state
|
|
|
|
|
|
|
|
def __hash__(self) -> int:
|
|
|
|
return hash(self.state)
|
|
|
|
|
|
|
|
|
|
|
|
def child_node(action: Action) -> Node:
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
def actions(state: State) -> List[str]:
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
def result(state: State, action: Action) -> State:
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
def goal_test(state: State, goal_list: List[Tuple[int, int]]) -> bool:
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
def h(state: State) -> int:
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
def f(state: State) -> int:
|
|
|
|
pass
|