Commit 19a1661a authored by Leo Peron's avatar Leo Peron
Browse files

added levels and update main filepath

parent bd46516f
......@@ -357,18 +357,44 @@ def manhattan_distance_astar_factory(map_rules: Dict[str, set]) -> Callable:
if state.key:
keyFactor = 3
return (
min(
abs(state.hero[0] - demon[0]) + abs(state.hero[1] - demon[1])
for demon in map_rules["D"]
)
+ (map_rules["max"] - state.steps)
+ keyFactor
min(
abs(state.hero[0] - demon[0]) + abs(state.hero[1] - demon[1])
for demon in map_rules["D"]
)
+ (map_rules["max"] - state.steps)
+ keyFactor
)
return dist_to_closest_demon
# NEW VERSION OF HEURISTIC
def manhattan_distance_proto_factory(map_rules: Dict[str, set]) -> Callable:
def dist_to_closest_demon(state: State, action: Action) -> int:
keyFactor = 0
if state.key:
keyFactor = 3
killFactor = 0
if action and action.verb == "kill":
killFactor = 3
pushFactor = 0
if action and action.verb == "push":
pushFactor = -2
unlockFactor = 0
if action and action.verb == "unlock/key" and not state.key:
unlockFactor = -2.5
return (
min(
abs(state.hero[0] - demon[0]) + abs(state.hero[1] - demon[1])
for demon in map_rules["D"]
)
+ (map_rules["max"] - state.steps)
+ keyFactor + killFactor + pushFactor + unlockFactor
)
return dist_to_closest_demon
# SEARCH ALGO (GREEDY)
# SEARCH ALGO (GREEDY & A*)
def search_heuristic(
s0: State,
goals: Callable,
......@@ -378,7 +404,7 @@ def search_heuristic(
) -> Tuple[State, Dict[State, Action]]:
l = []
heapq.heapify(l)
heapq.heappush(l, (heuristic(s0), s0))
heapq.heappush(l, (heuristic(s0, None), s0))
save = {s0: None}
heapq.heapify(l)
while l:
......@@ -394,7 +420,7 @@ def search_heuristic(
save[s2] = (s, a)
if goals(s2):
return s2, save
heapq.heappush(l, (heuristic(s2), s2))
heapq.heappush(l, (heuristic(s2, a), s2))
return None, save
......@@ -465,7 +491,7 @@ def main():
s0,
goal_factory(map_rules),
succ_factory(map_rules),
manhattan_distance_astar_factory(map_rules),
manhattan_distance_proto_factory(map_rules),
debug=False,
)
if method == "greedy":
......@@ -512,4 +538,4 @@ def main():
if __name__ == "__main__":
main()
main()
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment