Answered step by step
Verified Expert Solution
Question
1 Approved Answer
In this second deliverable, the rover must find water on the planet. Remember that: 1 . The rover cannot move in the middle when the
In this second deliverable, the rover must find water on the planet. Remember that: The rover cannot move in the middle when the difference between regions is greater than He also cannot climb over obstacles The rover moves like any car.In addition, the rover has a greater fuel consumption cost the further it is from the initial level or level sea levelWe have the following code.Every search algorithm says that it cant find and answer. Please help us to solve itimport matplotlib.pyplot as pltimport numpy as npimport randomfrom matplotlib.patches import Rectangleimport matplotlib.colors as mcolorsrows columns # Generate mapmap randomchoice~ for in rangecolumns for in rangerows# Roverroverrow random.randint rows rovercolumn random.randint columns maproverrowrovercolumnR# Colorscolordict : 'green', : 'lightgreen', : 'green', : 'green', : 'green', : 'darkgreen', : 'red', ~: 'blue', R: 'black'# Rover R# Water ~# Obstacule fig ax pltsubplots# Map with colorsfor i in rangerows: for j in rangecolumns: value mapij axtextj i value, ha'center', va'center', color'black' if value in colordict: color colordictvalue if value.isdigit: greentone intvalue color mcolors.hsvtorgb greentone, rect Rectanglej i linewidth edgecolor'black', facecolorcolor axaddpatchrect# Limitsax.setxlim columns axsetylimrows axsetxticksaxsetytickspltshowfrom simpleai.search import SearchProblem, depthfirst, breadthfirst, astar, greedy, uniformcostclass RoverSearchProblemSearchProblem: def initself initialstate, map: superRoverSearchProblem selfinitinitialstate self.map map def actionsself state: row, col state possibleactions for dr dc in : newrow, newcol row dr col dc if newrow lenselfmap and newcol lenselfmap and self.mapnewrownewcol not in and absintselfmaprowcol intselfmapnewrownewcol: possibleactions.appendnewrow, newcol return possibleactions def resultself state, action: return action def isgoalself state: row, col state return self.maprowcol def costself state, action, state: row, col state row col state return absintselfmaprowcol intselfmaprowcol# Define initial state and mapinitialstate roverrow, rovercolumnproblem RoverSearchProbleminitialstate, map# Solve using different algorithmsdfssolution depthfirstproblembfssolution breadthfirstproblemastarsolution astarproblem graphsearchTruegreedysolution greedyproblem graphsearchTrueuniformcostsolution uniformcostproblem# Print solutions or analyze them furtherprintDFS Solution:", dfssolution.stateprintBFS Solution:", bfssolution.stateprintA Solution:", astarsolution.stateprintGreedy Solution:", greedysolution.stateprintUniform Cost Solution:", uniformcostsolution.state
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