a_star #21

Merged
s464961 merged 15 commits from a_star into master 2022-04-27 19:50:51 +02:00
Showing only changes of commit 10485ce39d - Show all commits

View File

@ -1,9 +1,23 @@
from __future__ import annotations from __future__ import annotations
from dataclasses import dataclass, field 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 @dataclass
@ -16,10 +30,40 @@ class State:
class Node: class Node:
state: State state: State
parent: Optional[Node] parent: Optional[Node]
action: str action: Action
cost: int = field(init=False) cost: int = field(init=False)
depth: int = field(init=False) depth: int = field(init=False)
def __post_init__(self) -> None: def __post_init__(self) -> None:
self.cost = 0 if not self.parent else self.parent.cost + 1 self.cost = 0 if not self.parent else self.parent.cost + 1
self.depth = self.cost 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