forked from s464965/WMICraft
feat: models
This commit is contained in:
parent
05fcfc76f3
commit
f4ec5b5869
25
algorithms/a_star.py
Normal file
25
algorithms/a_star.py
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
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
|
@ -114,7 +114,7 @@ def go(row, column, direction):
|
|||||||
|
|
||||||
|
|
||||||
def is_valid_move(map, target_row, target_column):
|
def is_valid_move(map, target_row, target_column):
|
||||||
if 0 <= target_row < ROWS and 0 <= target_column < COLUMNS and map[target_row][target_column] == ' ':
|
if 0 <= target_row < ROWS and 0 <= target_column < COLUMNS and map[target_row][target_column] in ['g', 's', ' ']:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
@ -29,6 +29,7 @@ CASTLE_SPAWN_FIRST_COL = 9
|
|||||||
NBR_OF_WATER = 16
|
NBR_OF_WATER = 16
|
||||||
NBR_OF_TREES = 20
|
NBR_OF_TREES = 20
|
||||||
NBR_OF_MONSTERS = 2
|
NBR_OF_MONSTERS = 2
|
||||||
|
NBR_OF_SANDS = 15
|
||||||
|
|
||||||
TILES = [
|
TILES = [
|
||||||
'grass1.png',
|
'grass1.png',
|
||||||
|
@ -8,7 +8,7 @@ class Spawner:
|
|||||||
self.map = map
|
self.map = map
|
||||||
|
|
||||||
def __is_free_field(self, field):
|
def __is_free_field(self, field):
|
||||||
return field == ' '
|
return field in ['g', 's', ' ']
|
||||||
|
|
||||||
def spawn_in_area(self, objects: list, spawn_area_pos_row=0, spawn_area_pos_column=0, spawn_area_width=0,
|
def spawn_in_area(self, objects: list, spawn_area_pos_row=0, spawn_area_pos_column=0, spawn_area_width=0,
|
||||||
spawn_area_height=0, size=1):
|
spawn_area_height=0, size=1):
|
||||||
|
Loading…
Reference in New Issue
Block a user