refactor bfs;

This commit is contained in:
Angelika Iskra 2022-04-11 13:13:03 +02:00
parent e98a4da2aa
commit 404eb8e70d
2 changed files with 4 additions and 7 deletions

View File

@ -1,11 +1,7 @@
from __future__ import annotations
from typing import List
# temporary goal for testing
from common.constants import ACTION, Direction, ROWS, COLUMNS
from common.helpers import castle_neighbors
GOAL_LIST = []
class State:
@ -46,13 +42,12 @@ def get_successors(state: State, map):
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
if fringe is None:
fringe = list()
if explored is None:
explored = list()
goal_list = castle_neighbors(map, goal_cords[0], goal_cords[1])
explored_states = set()
fringe_states = set()

View File

@ -4,6 +4,7 @@ import pygame
from algorithms.bfs import graphsearch, State
from common.constants import *
from common.helpers import castle_neighbors
from logic.knights_queue import KnightsQueue
from logic.spawner import Spawner
from models.castle import Castle
@ -108,7 +109,8 @@ class Level:
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])
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)
if len(action_list) == 0: