From 239685d02607bdbbe4517ecb733b04f2e68a1223 Mon Sep 17 00:00:00 2001 From: Dan Date: Tue, 26 Nov 2024 13:07:55 +0000 Subject: [PATCH] - Update goals to allow for straight nodes to be included as well --- .vscode/launch.json | 15 +++++++++++++ red_blue_goal_path.py | 51 ++++++++++++++++++++++++------------------- 2 files changed, 44 insertions(+), 22 deletions(-) create mode 100644 .vscode/launch.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..6b76b4f --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,15 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "Python Debugger: Current File", + "type": "debugpy", + "request": "launch", + "program": "${file}", + "console": "integratedTerminal" + } + ] +} \ No newline at end of file diff --git a/red_blue_goal_path.py b/red_blue_goal_path.py index fc22eb5..977f8ff 100644 --- a/red_blue_goal_path.py +++ b/red_blue_goal_path.py @@ -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