{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# THE VACUUM WORLD \n", "\n", "In this notebook, we will be discussing **the structure of agents** through an example of the **vacuum agent**. The job of AI is to design an **agent program** that implements the agent function: the mapping from percepts to actions. We assume this program will run on some sort of computing device with physical sensors and actuators: we call this the **architecture**:\n", "\n", "
class TrivialVacuumEnvironment(Environment):\n",
"\n",
" """This environment has two locations, A and B. Each can be Dirty\n",
" or Clean. The agent perceives its location and the location's\n",
" status. This serves as an example of how to implement a simple\n",
" Environment."""\n",
"\n",
" def __init__(self):\n",
" super().__init__()\n",
" self.status = {loc_A: random.choice(['Clean', 'Dirty']),\n",
" loc_B: random.choice(['Clean', 'Dirty'])}\n",
"\n",
" def thing_classes(self):\n",
" return [Wall, Dirt, ReflexVacuumAgent, RandomVacuumAgent,\n",
" TableDrivenVacuumAgent, ModelBasedVacuumAgent]\n",
"\n",
" def percept(self, agent):\n",
" """Returns the agent's location, and the location status (Dirty/Clean)."""\n",
" return (agent.location, self.status[agent.location])\n",
"\n",
" def execute_action(self, agent, action):\n",
" """Change agent's location and/or location's status; track performance.\n",
" Score 10 for each dirt cleaned; -1 for each move."""\n",
" if action == 'Right':\n",
" agent.location = loc_B\n",
" agent.performance -= 1\n",
" elif action == 'Left':\n",
" agent.location = loc_A\n",
" agent.performance -= 1\n",
" elif action == 'Suck':\n",
" if self.status[agent.location] == 'Dirty':\n",
" agent.performance += 10\n",
" self.status[agent.location] = 'Clean'\n",
"\n",
" def default_location(self, thing):\n",
" """Agents start in either location at random."""\n",
" return random.choice([loc_A, loc_B])\n",
"