|
|
|
@ -17,13 +17,16 @@ class PlayerState: |
|
|
|
def add_condition(self, condition): |
|
|
|
self.conditions_met.add(condition) |
|
|
|
|
|
|
|
def find_path_to_goal(G, start_node, goal_condition, player_state): |
|
|
|
def find_path_to_goal(G, start_node, goal, player_state): |
|
|
|
# Priority queue elements: (total_cost, current_node, path, state) |
|
|
|
queue = [] |
|
|
|
initial_state = deepcopy(player_state) |
|
|
|
heapq.heappush(queue, (0, start_node, [start_node], initial_state)) |
|
|
|
visited = set() |
|
|
|
|
|
|
|
# Extract goal type and target |
|
|
|
goal_type, target = goal |
|
|
|
|
|
|
|
while queue: |
|
|
|
total_cost, current_node, path, state = heapq.heappop(queue) |
|
|
|
|
|
|
|
@ -36,12 +39,16 @@ def find_path_to_goal(G, start_node, goal_condition, player_state): |
|
|
|
visit_node(current_node, G, new_state) |
|
|
|
|
|
|
|
# Check if the goal condition is met |
|
|
|
if goal_condition in new_state.conditions_met: |
|
|
|
if goal_type == "condition" and target in new_state.conditions_met: |
|
|
|
# Commit the updated state to the player state |
|
|
|
player_state.visited_nodes = new_state.visited_nodes |
|
|
|
player_state.conditions_met = new_state.conditions_met |
|
|
|
return path |
|
|
|
elif goal_type == "node" and current_node == target: |
|
|
|
# Commit the updated state to the player state |
|
|
|
player_state.visited_nodes = new_state.visited_nodes |
|
|
|
player_state.conditions_met = new_state.conditions_met |
|
|
|
return path |
|
|
|
|
|
|
|
# Explore neighbors |
|
|
|
for neighbor in G.neighbors(current_node): |
|
|
|
edge_attrs = G[current_node][neighbor] |
|
|
|
@ -115,25 +122,25 @@ if __name__ == "__main__": |
|
|
|
|
|
|
|
# Define the ordered goals that the player must acquire |
|
|
|
goals = [ |
|
|
|
BOULDER_BADGE, |
|
|
|
CASCADE_BADGE, |
|
|
|
SS_ANNE_TICKET, |
|
|
|
CUT, |
|
|
|
THUNDER_BADGE, |
|
|
|
FLASH, |
|
|
|
SILPH_SCOPE, |
|
|
|
RAINBOW_BADGE, |
|
|
|
QUENCHED_THURST, |
|
|
|
POKE_FLUTE, |
|
|
|
GIOVANNI_FIGHT, |
|
|
|
MARSH_BADGE, |
|
|
|
SOUL_BADGE, |
|
|
|
VOLCANO_BADGE, |
|
|
|
ARCTICUNO, |
|
|
|
ZAPDOS, |
|
|
|
MOLTRES, |
|
|
|
CHAMPION, |
|
|
|
MEWTWO |
|
|
|
("condition", BOULDER_BADGE), |
|
|
|
("condition", CASCADE_BADGE), |
|
|
|
("condition", SS_ANNE_TICKET), |
|
|
|
("condition", CUT), |
|
|
|
("condition", THUNDER_BADGE), |
|
|
|
("condition", FLASH), |
|
|
|
("condition", SILPH_SCOPE), |
|
|
|
("condition", RAINBOW_BADGE), |
|
|
|
("condition", QUENCHED_THURST), |
|
|
|
("condition", POKE_FLUTE), |
|
|
|
("condition", GIOVANNI_FIGHT), |
|
|
|
("condition", MARSH_BADGE), |
|
|
|
("condition", SOUL_BADGE), |
|
|
|
("condition", VOLCANO_BADGE), |
|
|
|
("condition", ARCTICUNO), |
|
|
|
("condition", ZAPDOS), |
|
|
|
("condition", MOLTRES), |
|
|
|
("condition", CHAMPION), |
|
|
|
("condition", MEWTWO) |
|
|
|
] |
|
|
|
|
|
|
|
# Find the optimal path while fulfilling goals in succession |
|
|
|
|