fix: resolve comparing object with list; add fringe_state

This commit is contained in:
mikoMaz 2023-04-16 18:42:56 +02:00
parent d2f973307f
commit 3a8a7fdb14

View File

@ -29,6 +29,7 @@ class Search:
angle = istate[2]
fringe = [Node([x, y, angle])] # queue (moves/states to check)
fringe_state = [fringe[0].state]
explored = []
while True:
@ -36,13 +37,13 @@ class Search:
return False
elem = fringe.pop(0)
fringe_state.pop(0)
# if goal_test(elem.state):
# return
# print(elem.state[0], elem.state[1], elem.state[2])
if elem.state[0] == goaltest[0] and elem.state[1] == goaltest[1]: # checks if we reached the given point
steps = []
while elem.parent != '':
steps.append([elem.action, elem.state[0], elem.state[1]]) # should return only elem.action in prod
elem = elem.parent
@ -51,17 +52,19 @@ class Search:
print(steps) # only for dev
return steps
explored.append(elem)
explored.append(elem.state)
for (action, state_x, state_y, state_angle) in self.succ(elem.state):
if state_x < 0 or state_y < 0: # check if any of the values is negative
if state_x < 0 or state_y < 0: # check if any of the values are negative
continue
if [state_x, state_y, state_angle] not in fringe and [state_x, state_y, state_angle] not in explored:
if [state_x, state_y, state_angle] not in fringe_state and \
[state_x, state_y, state_angle] not in explored:
x = Node([state_x, state_y, state_angle])
x.parent = elem
x.action = action
fringe.append(x)
fringe_state.append(x.state)
se = Search(50)
se.graphsearch(istate=[50, 50, 0], goaltest=[250, 100])
se.graphsearch(istate=[50, 50, 0], goaltest=[150, 250])