26 lines
523 B
Python
26 lines
523 B
Python
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass, field
|
|
from typing import Tuple, Optional
|
|
|
|
from common.constants import Direction
|
|
|
|
|
|
@dataclass
|
|
class State:
|
|
position: Tuple[int, int]
|
|
direction: Direction
|
|
|
|
|
|
@dataclass
|
|
class Node:
|
|
state: State
|
|
parent: Optional[Node]
|
|
action: str
|
|
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
|