Answered step by step
Verified Expert Solution
Question
1 Approved Answer
This Motion planning code doesn't print anything out besides the Easy Trial 1 . What am I not printing out correctly for the grids:
This Motion planning code doesn't print anything out besides the "Easy Trial What am I not printing out correctly for the grids:
Motion planning on a rectangular grid using A search
from random import random
from random import seed
from queue import PriorityQueue
from copy import deepcopy
class Stateobject:
def initself startposition, goalposition, startgrid:
self.position startposition
self.goal goalposition
self.grid startgrid
self.totalmoves
def manhattandistanceself:
Calculates the Manhattan distance to the goal
return absselfposition self.goal absselfposition self.goal
def getpossiblemovesself:
Returns a list of possible moves from the current position
moves
for dx in :
newr self.position dx
if newr numrows :
for dy in :
newc self.position dy
if newc numcols and self.gridnewrnewc:
moves.appendnewr newc
return moves
def ltself other:
Overloads the operator for priority queue comparison
return selftotalmoves self.manhattandistanceothertotalmoves other.manhattandistance
def creategrid:
# Code for creating a randomized grid
Create and return a randomized grid
s in the grid indcate free squares
s indicate obstacles
DON'T MODIFY THIS ROUTINE.
DON'T MODIFY THIS ROUTINE.
DON'T MODIFY THIS ROUTINE.
DON'T MODIFY THIS ROUTINE.
ARE YOU MODIFYING THIS ROUTINE?
IF SO STOP IT
# Start with a numrows by numcols grid of all zeros
grid for c in rangenumcols for r in rangenumrows
# Put ones around the boundary
grid for c in rangenumcols
gridnumrows for c in rangenumcols
for r in rangenumrows:
gridr
gridrnumcols
# Sprinkle in obstacles randomly
for r in range numrows :
for c in range numcols :
if random obstacleprob:
gridrc;
# Make sure the goal and start spaces are clear
grid
gridnumrows numcols
return grid
def printgridgrid:
# Code for printing the grid
Print a grid, putting spaces in place of zeros for readability
DON'T MODIFY THIS ROUTINE.
DON'T MODIFY THIS ROUTINE.
DON'T MODIFY THIS ROUTINE.
DON'T MODIFY THIS ROUTINE.
ARE YOU MODIFYING THIS ROUTINE?
IF SO STOP IT
for r in rangenumrows:
for c in rangenumcols:
if gridrc:
print end
else:
printgridrc end
print
print
return
def main:
seed
# Easy mode
# Global variables
# Saves us the trouble of continually passing them as parameters
numrows
numcols
obstacleprob
for trial in range:
print
Easy trial strtrial
main
# Uncomment the following sets of trials when you're ready
# Hard mode
numrows
numcols
obstacleprob
for trial in range:
print
Harder trial strtrial
###main
# INSANE mode
numrows
numcols
obstacleprob
for trial in range:
print
INSANE trial strtrial
###main
if namemain:
seed
# Easy mode
# Global variables
# Saves us the trouble of continually passing them as parameters
numrows
numcols
obstacleprob
for trial in range:
print
Easy trial strtrial
main
# Uncomment the following sets of trials when you're ready
# Hard mode
numrows
numcols
obstacleprob
for trial in range:
print
Harder trial strtrial
###main
# INSANE mode
numrows
numcols
obstacleprob
for trial in range:
print
INSANE trial strtrial
###main
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started