Question: That was wrong. Here is some of my code: ' ' ' CMSI 2 1 3 0 - Homework 1 Author: Modify only this file
That was wrong. Here is some of my code:
CMSI Homework
Author:
Modify only this file as part of your submission, as it will contain all of the logic
necessary for implementing the A pathfinder that solves the target practice problem.
import queue
from dataclasses import
from typing import
import heapq
from mazeproblem import MazeProblem
from dataclasses import dataclass
from typing import Optional, List, Tuple, Dict
from typing import List, Tuple
@dataclass
class SearchTreeNode:
playerloc: Tupleint int
action: str
parent: OptionalSearchTreeNode
# TODO: Add any other attributes and method overrides as necessary!
cost: int
totalcost: int # gn path cost hn future cost
def ltself other bool:
return self.totalcost other.totalcost
def eqself other bool:
return self.totalcost other.totalcost # and self.playerloc other.playerloc
def strself str:
return f@: selfplayerloc cost: selfcost
def heuristiccurrent: Tupleint int goal: Tupleint int int:
return abscurrent goal abscurrent goal
def pathfindproblem: "MazeProblem" Optionalliststr:
targetsleft problem.getinitialtargets
frontier: ListSearchTreeNode
initialstate SearchTreeNodeproblemgetinitialloc None,
frontier.appendinitialstate
graveyard: SetTupleTupleint int int set
while frontier:
currentnode frontier.pop
# Process neighbors
neighbors problem.gettransitionscurrentnode.playerloc, targetsleft
for action, transition in neighbors.items:
nextloc transitionnextloc"
cost currentnode.cost transitioncost
targetshit transitiontargetshit"
# Update remaining targets
newtargetsleft targetsleft targetshit
# Check if all targets are destroyed
if not newtargetsleft:
solutionpath: Liststr
while currentnode.parent is not None:
solutionpath.insert currentnode.action
currentnode currentnode.parent
return solutionpath
# Calculate total cost with heuristic
totalcost cost heuristicnextloc, currentnode.playerloc
# Create a new search tree node
newnode SearchTreeNodenextloc, action, currentnode, cost, totalcost
# Check if this state has been visited before
statesignature newnode.playerloc, lennewtargetsleft
if statesignature not in graveyard:
frontier.appendnewnode
graveyard.addstatesignature
return None # If no solution found
Now please edit my code to have the tests come out right. I only go the nosoultions tests passed but need to be passed.
DO NOT MODFIY ANYTHING FROM BELOW. Just above code
mazeproblem.py
def getinitialloc self tupleint int:
Returns the player"s starting position in the maze g
Returns:
tupleint int:
The player's starting location in the maze: col rowxy
n
def getgoalloc self tupleint int:
Returns the location of the goal that must be reached.
Returns:
tupleint int:
The goal's location tuple: col rowxy
n
def gettransitionsself playerloc: tupleint int dict:
Returns a dictionary describing all possible transitions that a player may take from their
given position.
Parameters:
playerloctupleint int:
The current location of the player in the maze.
Returns:
dict:
A dictionary whose keys are the possible actions fron the given playerloc, with mapped
values nextloc tupleint int values that show the player's location after taking that action.
Exanple:
For example, if only the actions DU and L were possible from the current playerloc of
we might see an output of:
D:
U:
L:
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
