Question: MazeProblems in this scenario will be constructed from a list of strings a 2 D maze of characters indicating the contents of each cell in
MazeProblems in this scenario will be constructed from a list of strings a D maze of characters indicating the contents of each cell in the for rownum,
maze.
In particular, the following table describes what constitutes a valid properly formatted maze in this modified version of our Pathfinder:
Each MazeState location will include exactly of the above categories, meaning that the initial state cannot also be a target cannot also be on
a mud tile, etc. and mazes provided as input will be validly formatted so you need not check for validity.
i In addition to the standard movement choices of UDLR to navigate to each Target, your agent will have the special action S
to shoot, which has the following effects:
All targets that are in the player's lineofsight in each of the four cardinal directions North, South, East, and West are destroyed, regardless of
how far away they are how do you shoot in all directions at once? Practice..
The catch: walls X will block your shots, BUT your shots will penetrate targets, hitting any targets that may be behind another in the same
direction.
Shooting has a cost of and your agent will remain inplace in the maze while shooting.
Important Notes:
In any maze for which there a solution, the agent MUST shoot ALL Targets.
If there are solutions, your procedure should return any one of the cost solutions, and can shoot targets in order
to solve it
If a maze has solution, your procedure should be able to handle this and return None.
CODE TO EDIT:
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 mazeproblem import MazeProblem
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
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:
The main workhorse method of the package that performs A graph search to find the optimal
sequence of actions that takes the agent from its initial state and shoots all targets in
the given MazeProblem's maze, or determines that the problem is unsolvable.
Parameters:
problem MazeProblem:
The MazeProblem object constructed on the maze that is to be solved or determined
unsolvable by this method.
Returns:
Optionalliststr:
A solution to the problem: a sequence of actions leading from the
initial state to the goal a maze with all targets destroyed If no such solution is
possible, returns None.
# TODO: Implement A Graph Search for the Pathfinding Biathlon!
return None
This is my old code that uses breadthfirst tree search!
Modify only this file as part of your submission, as it will contain all of the logic
necessary for implementing the breadthfirst tree search that solves the basic maz
pathfinding problem.
from queue import Queue
from mazeproblem import
from dataclasses import
@dataclass
class SearchTreeNode:
SearchTreeNodes contain the following attributes to be used in generation of
the Search tree:
Attributes:
playerloc tupleint int:
The player's location in this node.
action str:
The action taken to reach this node from its parent or empty if the root
parent OptionalSearchTreeNode:
The parent node from which this node was generated or None if the root
playerloc: tupleint int
action: str
parent: OptionalSearchTreeNode
def strself str:
return @: strselfplayerloc
frontier: Queue Queuemaxsize # initialize queue
initialstate SearchTreeNodeproblemgetinitialloc None # intialize the init state
frontier.putinitialstate# put init state into queuefrontier
while not frontier.empty:
currentnode frontier.get
children problem.gettransitionscurrentnode.playerloc #get dictionary of all possible movesstates
for transition in children:
child SearchTreeNodechildrentransition transition, currentnode #create child node for possible moves and pass parent
if child.playerloc problem.getgoal
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
