From 10485ce39d6264ca46c6362049ec53be3325a05d Mon Sep 17 00:00:00 2001 From: korzepadawid Date: Mon, 11 Apr 2022 19:49:32 +0200 Subject: [PATCH] feat: enums --- algorithms/a_star.py | 50 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/algorithms/a_star.py b/algorithms/a_star.py index d3e3077..c593f69 100644 --- a/algorithms/a_star.py +++ b/algorithms/a_star.py @@ -1,9 +1,23 @@ from __future__ import annotations from dataclasses import dataclass, field -from typing import Tuple, Optional +from enum import Enum, unique +from typing import Tuple, Optional, List -from common.constants import Direction + +@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' @dataclass @@ -16,10 +30,40 @@ class State: class Node: state: State parent: Optional[Node] - action: str + action: Action 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 + + 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