fixed a_star (new priority bug)

This commit is contained in:
s452645 2021-05-09 19:39:00 +02:00
parent cf4b3f9027
commit 346fe641d4
3 changed files with 7 additions and 7 deletions

View File

@ -72,8 +72,8 @@ class Coords(Enum):
class Terrain(Enum):
CONCRETE = 2
GRASS = 10
MUD = 20
GRASS = 5
MUD = 8
# =============== #

View File

@ -173,7 +173,7 @@
"mine": null
},
"3,5": {
"terrain": "MUD",
"terrain": "GRASS",
"mine": null
},
"3,6": {

View File

@ -152,7 +152,7 @@ def graphsearch(initial_state: State,
fringe_states.add((new_node.state.row, new_node.state.column, new_node.state.direction))
# update weight if it's lower
elif successor_state in fringe and entry_finder[successor_state][0] > priority:
elif successor_state in fringe_states and entry_finder[successor_state][0] > priority:
update_priority(fringe, new_node, priority)
else:
@ -184,7 +184,7 @@ counter = itertools.count() # unique sequence count
def add_node(heap, node: Node, priority):
count = next(counter)
entry = [priority, count, node]
entry_finder[node.state] = entry
entry_finder[(node.state.row, node.state.column, node.state.direction)] = entry
heappush(heap, entry)
@ -192,12 +192,12 @@ def pop_node(heap):
while heap:
priority, count, node = heappop(heap)
if node is not REMOVED:
del entry_finder[node.state]
del entry_finder[(node.state.row, node.state.column, node.state.direction)]
return node
return None
def update_priority(heap, new_node, new_priority):
old_entry = entry_finder.pop(new_node.state)
old_entry = entry_finder.pop((new_node.state.row, new_node.state.column, new_node.state.direction))
old_entry[-1] = REMOVED
add_node(heap, new_node, new_priority)