fixed a_star (new priority bug)
This commit is contained in:
parent
cf4b3f9027
commit
346fe641d4
@ -72,8 +72,8 @@ class Coords(Enum):
|
|||||||
|
|
||||||
class Terrain(Enum):
|
class Terrain(Enum):
|
||||||
CONCRETE = 2
|
CONCRETE = 2
|
||||||
GRASS = 10
|
GRASS = 5
|
||||||
MUD = 20
|
MUD = 8
|
||||||
|
|
||||||
|
|
||||||
# =============== #
|
# =============== #
|
||||||
|
@ -173,7 +173,7 @@
|
|||||||
"mine": null
|
"mine": null
|
||||||
},
|
},
|
||||||
"3,5": {
|
"3,5": {
|
||||||
"terrain": "MUD",
|
"terrain": "GRASS",
|
||||||
"mine": null
|
"mine": null
|
||||||
},
|
},
|
||||||
"3,6": {
|
"3,6": {
|
||||||
|
@ -152,7 +152,7 @@ def graphsearch(initial_state: State,
|
|||||||
fringe_states.add((new_node.state.row, new_node.state.column, new_node.state.direction))
|
fringe_states.add((new_node.state.row, new_node.state.column, new_node.state.direction))
|
||||||
|
|
||||||
# update weight if it's lower
|
# 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)
|
update_priority(fringe, new_node, priority)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
@ -184,7 +184,7 @@ counter = itertools.count() # unique sequence count
|
|||||||
def add_node(heap, node: Node, priority):
|
def add_node(heap, node: Node, priority):
|
||||||
count = next(counter)
|
count = next(counter)
|
||||||
entry = [priority, count, node]
|
entry = [priority, count, node]
|
||||||
entry_finder[node.state] = entry
|
entry_finder[(node.state.row, node.state.column, node.state.direction)] = entry
|
||||||
heappush(heap, entry)
|
heappush(heap, entry)
|
||||||
|
|
||||||
|
|
||||||
@ -192,12 +192,12 @@ def pop_node(heap):
|
|||||||
while heap:
|
while heap:
|
||||||
priority, count, node = heappop(heap)
|
priority, count, node = heappop(heap)
|
||||||
if node is not REMOVED:
|
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 node
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def update_priority(heap, new_node, new_priority):
|
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
|
old_entry[-1] = REMOVED
|
||||||
add_node(heap, new_node, new_priority)
|
add_node(heap, new_node, new_priority)
|
||||||
|
Loading…
Reference in New Issue
Block a user