Question: Complete algo function in following below code from lib.agents import * import numpy as npclass Wall ( Thing ) : passclass Goal ( Thing )

Complete algo function in following below code
from lib.agents import *import numpy as npclass Wall(Thing): passclass Goal(Thing): passfrom random import choiceclass OurAgent(Agent): location =[0,1] direction = Direction("down") def moveforward(self, loc): self.location[0]+= loc[0] self.location[1]+= loc[1] def turn(self, d): self.direction = Direction(d) def program(percepts): global it '''Returns an action based on it's percepts''' for p in percepts: if isinstance(p, Wall): print("Cannot move in a wall
Implement the algorithm again") it +=1 return steps[it]class Maze(GraphicEnvironment): def percept(self, agent): '''return a list of things that are in our agent's location''' things = self.list_things_at(agent.location) for thing in self.list_things_at(agent.location): if not isinstance(thing, OurAgent): things.append(thing) return things def execute_action(self, agent, action): '''changes the state of the environment based on what the agent does.''' if action == 'right': agent.moveforward([1,0]) elif action == 'left': agent.moveforward([-1,0]) elif action =='up': agent.moveforward([0,-1]) elif action == 'down': agent.moveforward([0,1]) def is_done(self): things =[] for agent in self.agents: for thing in self.list_things_at(agent.location): things.append(thing) for thing in things: if isinstance(thing, Goal): return True return Falsemaze_layout =[[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1],[1,3,0,1,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,1],[1,0,0,1,0,1,1,1,0,1,0,1,1,1,0,1,1,1,0,1],[1,0,0,1,0,1,0,1,0,0,0,0,0,1,0,0,0,1,0,1],[1,0,0,1,0,1,1,1,1,0,1,1,1,1,1,1,0,1,0,1],[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],[1,1,1,1,1,1,0,0,1,0,1,1,1,1,1,1,1,1,1,1],[1,0,0,0,0,1,1,1,1,0,1,1,1,0,0,0,0,0,0,1],[1,0,1,1,0,0,0,0,1,0,0,1,0,0,1,1,1,0,0,1],[1,0,1,1,0,1,1,0,1,0,0,0,0,1,1,0,1,1,0,1],[1,0,0,0,0,1,1,0,1,0,1,1,0,1,1,0,0,0,0,1],[1,1,1,1,1,1,1,0,1,0,1,1,0,1,1,1,1,1,1,1],[1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,1],[1,1,1,1,1,0,1,1,1,1,1,1,0,1,1,0,1,1,0,1],[1,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,1,0,1],[1,0,1,0,1,1,1,1,1,1,0,1,1,0,1,1,0,1,0,1],[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1],[1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1,1],[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,1],[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]]maze_instance = Maze(20,20, color={'Goal': (0,128,0), 'Wall': (165,42,42), 'OurAgent': (255,255,0)})def algo(maze): """ implement this function using the maze from input 3 in the maze represents the location of the agent 2 represents the goal 1 represents the wall 0 represent the free space in which our agent can walk return and array of moves like this e.g.["down", "right", "up", "left", "left", "down"] so that the agent will be at the goal use maze

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!