Answered step by step
Verified Expert Solution
Link Copied!

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:1. The rover cannot move in the middle when the difference between regions is greater than 1.2. He also cannot climb over obstacles.3. 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 0(sea level).We have the following code.Every search algorithm says that it cant find and answer. Please help us to solve it.import matplotlib.pyplot as pltimport numpy as npimport randomfrom matplotlib.patches import Rectangleimport matplotlib.colors as mcolorsrows =15columns =30# Generate mapmap =[[random.choice(['0','1','2','3','4','5','*','~']) for _ in range(columns)] for _ in range(rows)]# Roverrover_row = random.randint(0, rows -1)rover_column = random.randint(0, columns -1)map[rover_row][rover_column]='R'# Colorscolor_dict ={'0': 'green', '1': 'lightgreen', '2': 'green', '3': 'green', '4': 'green', '5': 'darkgreen', '*': 'red', '~': 'blue', 'R': 'black'}# Rover = R# Water = ~# Obstacule =*fig, ax = plt.subplots()# Map with colorsfor i in range(rows): for j in range(columns): value = map[i][j] ax.text(j, i, value, ha='center', va='center', color='black') if value in color_dict: color = color_dict[value] if value.isdigit(): green_tone = int(value)/5.0 color = mcolors.hsv_to_rgb((120/360, green_tone, 0.8)) rect = Rectangle((j -0.5, i -0.5),1,1, linewidth=1, edgecolor='black', facecolor=color) ax.add_patch(rect)# Limitsax.set_xlim(-0.5, columns -0.5)ax.set_ylim(rows -0.5,-0.5)ax.set_xticks([])ax.set_yticks([])plt.show()from simpleai.search import ( SearchProblem, depth_first, breadth_first, astar, greedy, uniform_cost,)class RoverSearchProblem(SearchProblem): def __init__(self, initial_state, map): super(RoverSearchProblem, self).__init__(initial_state) self.map = map def actions(self, state): row, col = state possible_actions =[] for dr, dc in [(1,0),(-1,0),(0,1),(0,-1)]: new_row, new_col = row + dr, col + dc if (0<= new_row < len(self.map) and 0<= new_col < len(self.map[0]) and self.map[new_row][new_col] not in ['1','2','3','4','5'] and abs(int(self.map[row][col])- int(self.map[new_row][new_col]))<=1): possible_actions.append((new_row, new_col)) return possible_actions def result(self, state, action): return action def is_goal(self, state): row, col = state return self.map[row][col]=='*' def cost(self, state, action, state2): row, col = state row2, col2= state2 return abs(int(self.map[row][col])- int(self.map[row2][col2]))# Define initial state and mapinitial_state =(rover_row, rover_column)problem = RoverSearchProblem(initial_state, map)# Solve using different algorithmsdfs_solution = depth_first(problem)bfs_solution = breadth_first(problem)astar_solution = astar(problem, graph_search=True)greedy_solution = greedy(problem, graph_search=True)uniform_cost_solution = uniform_cost(problem)# Print solutions or analyze them furtherprint("DFS Solution:", dfs_solution.state)print("BFS Solution:", bfs_solution.state)print("A* Solution:", astar_solution.state)print("Greedy Solution:", greedy_solution.state)print("Uniform Cost Solution:", uniform_cost_solution.state)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beyond Big Data Using Social MDM To Drive Deep Customer Insight

Authors: Martin Oberhofer, Eberhard Hechler

1st Edition

0133509796, 9780133509793

More Books

Students also viewed these Databases questions