Browse Source

- Update goals to allow for straight nodes to be included as well

rough-outline
Dan 1 year ago
parent
commit
239685d026
  1. 15
      .vscode/launch.json
  2. 51
      red_blue_goal_path.py

15
.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"
}
]
}

51
red_blue_goal_path.py

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

Loading…
Cancel
Save