{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# AGENT #\n", "\n", "An agent, as defined in 2.1 is anything that can perceive its environment through sensors, and act upon that environment through actuators based on its agent program. This can be a dog, robot, or even you. As long as you can perceive the environment and act on it, you are an agent. This notebook will explain how to implement a simple agent, create an environment, and create a program that helps the agent act on the environment based on its percepts.\n", "\n", "Before moving on, review the Agent and Environment classes in [agents.py](https://github.com/aimacode/aima-python/blob/master/agents.py).\n", "\n", "Let's begin by importing all the functions from the agents.py module and creating our first agent - a blind dog." ] }, { "cell_type": "code", "execution_count": 29, "metadata": { "collapsed": false, "scrolled": true }, "outputs": [], "source": [ "from agents import *\n", "\n", "class BlindDog(Agent):\n", " def eat(self, thing):\n", " print(\"Dog: Ate food at {}.\".format(self.location))\n", " \n", " def drink(self, thing):\n", " print(\"Dog: Drank water at {}.\".format( self.location))\n", "\n", "dog = BlindDog()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "What we have just done is create a dog who can only feel what's in his location (since he's blind), and can eat or drink. Let's see if he's alive..." ] }, { "cell_type": "code", "execution_count": 30, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "True\n" ] } ], "source": [ "print(dog.alive)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "This is our dog. How cool is he? Well, he's hungry and needs to go search for food. For him to do this, we need to give him a program. But before that, let's create a park for our dog to play in." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# ENVIRONMENT #\n", "\n", "A park is an example of an environment because our dog can perceive and act upon it. The Environment class in agents.py is an abstract class, so we will have to create our own subclass from it before we can use it. The abstract class must contain the following methods:\n", "\n", "
Percept: | \n", "Feel Food | \n", "Feel Water | \n", "Feel Nothing | \n", "
Action: | \n", "eat | \n", "drink | \n", "move up | \n", "