refactor bfs;
This commit is contained in:
parent
e98a4da2aa
commit
404eb8e70d
@ -1,11 +1,7 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
# temporary goal for testing
|
|
||||||
from common.constants import ACTION, Direction, ROWS, COLUMNS
|
from common.constants import ACTION, Direction, ROWS, COLUMNS
|
||||||
from common.helpers import castle_neighbors
|
|
||||||
|
|
||||||
GOAL_LIST = []
|
|
||||||
|
|
||||||
|
|
||||||
class State:
|
class State:
|
||||||
@ -46,13 +42,12 @@ def get_successors(state: State, map):
|
|||||||
return successors
|
return successors
|
||||||
|
|
||||||
|
|
||||||
def graphsearch(initial_state: State, map, goal_cords, fringe: List[Node] = None, explored: List[Node] = None):
|
def graphsearch(initial_state: State, map, goal_list, fringe: List[Node] = None, explored: List[Node] = None):
|
||||||
# fringe and explored initialization
|
# fringe and explored initialization
|
||||||
if fringe is None:
|
if fringe is None:
|
||||||
fringe = list()
|
fringe = list()
|
||||||
if explored is None:
|
if explored is None:
|
||||||
explored = list()
|
explored = list()
|
||||||
goal_list = castle_neighbors(map, goal_cords[0], goal_cords[1])
|
|
||||||
explored_states = set()
|
explored_states = set()
|
||||||
fringe_states = set()
|
fringe_states = set()
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ import pygame
|
|||||||
|
|
||||||
from algorithms.bfs import graphsearch, State
|
from algorithms.bfs import graphsearch, State
|
||||||
from common.constants import *
|
from common.constants import *
|
||||||
|
from common.helpers import castle_neighbors
|
||||||
from logic.knights_queue import KnightsQueue
|
from logic.knights_queue import KnightsQueue
|
||||||
from logic.spawner import Spawner
|
from logic.spawner import Spawner
|
||||||
from models.castle import Castle
|
from models.castle import Castle
|
||||||
@ -108,7 +109,8 @@ class Level:
|
|||||||
state = State(knight_pos_y, knight_pos_x, current_knight.direction)
|
state = State(knight_pos_y, knight_pos_x, current_knight.direction)
|
||||||
|
|
||||||
castle_cords = (self.list_castles[0].position[0], self.list_castles[0].position[1])
|
castle_cords = (self.list_castles[0].position[0], self.list_castles[0].position[1])
|
||||||
action_list = graphsearch(state, self.map, castle_cords)
|
goal_list = castle_neighbors(self.map, castle_cords[0], castle_cords[1]) # list of castle neighbors
|
||||||
|
action_list = graphsearch(state, self.map, goal_list)
|
||||||
print(action_list)
|
print(action_list)
|
||||||
|
|
||||||
if len(action_list) == 0:
|
if len(action_list) == 0:
|
||||||
|
Loading…
Reference in New Issue
Block a user