Commit bde0d618 authored by Adrien Simon's avatar Adrien Simon
Browse files
parents 2eef5bea eb9a1f5e
......@@ -183,21 +183,21 @@ def free_factory(map_rules):
def updating_state(
map_rules: Dict[str, List[int]],
state: State,
newHero: List[int],
mobs: List[Tuple[int, int]] = [],
blocks: List[Tuple[int, int]] = [],
newHero: Tuple[int],
mobs: FrozenSet[Tuple[int, int]] = [],
blocks: FrozenSet[Tuple[int, int]] = [],
keyFinded: bool = False,
lockOpenable: bool = False,
mobCleared: bool = False,
):
# KILLINGS MOBS
newMobs = list(state.mobs)
newMobs = state.mobs
if mobs or mobCleared:
newMobs = list(mobs)
newMobs = frozenset(mobs)
for mob in newMobs:
if (mob in state.safeTraps) or (mob in map_rules["S"]):
newMobs.remove(mob)
newMobs = moving_frozenset(newMobs, supr=mob)
# KEY AND CHEST INTERACTIONS
newLock = state.lock
......@@ -342,6 +342,8 @@ def succ_factory(map_rules: Dict[str, set]) -> Callable[[State], Dict[State, Act
# DEFINING HEURISTIC
# GLOUTON
def manhattan_distance_factory(map_rules: Dict[str, set]) -> Callable:
def dist_to_closest_demon(state: State) -> int:
return min(
......@@ -352,22 +354,26 @@ def manhattan_distance_factory(map_rules: Dict[str, set]) -> Callable:
return dist_to_closest_demon
# A*
def manhattan_distance_astar_factory(map_rules: Dict[str, set]) -> Callable:
def dist_to_closest_demon(state: State) -> int:
keyFactor = 0
def dist_to_closest_demon(state: State, action: Action) -> int:
passedCost = (1/(1 + map_rules["max"] - state.steps))
booster = 1
manDist = 0
if state.key:
keyFactor = 4
lockFactor = 0
manDist = abs(state.key[0] - state.hero[0]) + abs(state.key[1] - state.hero[1])
if action:
booster = (0.8, 0.6)[action.verb == "unlock/key"]
if state.lock and not state.key:
lockFactor = -1
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)*0.7
+ keyFactor + lockFactor
)
manDist = abs(state.lock[0] - state.hero[0]) + abs(state.lock[1] - state.hero[1])
if action:
booster = (0.4, 0.2)[action.verb == "unlock/key"]
else:
manDist = min(
abs(state.hero[0] - demon[0]) + abs(state.hero[1] - demon[1])
for demon in map_rules["D"]
)
return manDist*1 + passedCost*1.5
return dist_to_closest_demon
......@@ -381,7 +387,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:
......@@ -397,7 +403,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
......
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