WMICraft/algorithms/a_star.py
2022-04-11 19:18:03 +02:00

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