{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## CS 470 Artificial Intelligence hw1\n", "\n", "You are to edit the file hw1.py, as described in the instructions.\n", "We have provided a solution file, hw1a.pyc, which is compiled bytecode that you may run.\n", "\n", "Below we demonstrate the code, both with and without graphics." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from hw1a import *" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "gv = GraphicVacuumEnvironment(10,10,bias=0.5,color={'Agent': (200,0,0), 'Dirt': (230, 115, 40), 'Wall': (100,100,100)})" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[[[],\n", " [],\n", " [],\n", " [],\n", " [],\n", " [],\n", " [],\n", " [],\n", " [],\n", " []],\n", " [[], [], [], [], [], [], [], [], [], []],\n", " [[],\n", " [],\n", " [],\n", " [],\n", " [],\n", " [],\n", " [],\n", " [],\n", " [],\n", " []],\n", " [[],\n", " [],\n", " [],\n", " [],\n", " [],\n", " [],\n", " [],\n", " [],\n", " [],\n", " []],\n", " [[], [], [], [], [], [], [], [], [], []],\n", " [[], [], [], [], [], [], [], [], [], []],\n", " [[], [], [], [], [], [], [], [], [], []],\n", " [[],\n", " [],\n", " [],\n", " [],\n", " [],\n", " [],\n", " [],\n", " [],\n", " [],\n", " []],\n", " [[],\n", " [],\n", " [],\n", " [],\n", " [],\n", " [],\n", " [],\n", " [],\n", " [],\n", " []],\n", " [[],\n", " [],\n", " [],\n", " [],\n", " [],\n", " [],\n", " [],\n", " [],\n", " [],\n", " []]]" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rv = TraceAgent(BetterReflexVacuumAgent())\n", "gv.add_thing(rv)\n", "gv.get_world()" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rv.performance" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(1, 1)" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rv.location" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ " perceives ('Clean', 'None') and does Right at (1, 1)\n" ] }, { "data": { "text/html": [], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ " perceives ('Dirty', 'None') and does Suck at (2, 1)\n" ] }, { "data": { "text/html": [], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ " perceives ('Clean', 'None') and does Right at (2, 1)\n" ] }, { "data": { "text/html": [], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ " perceives ('Clean', 'None') and does Right at (3, 1)\n" ] }, { "data": { "text/html": [], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ " perceives ('Clean', 'None') and does Right at (4, 1)\n" ] }, { "data": { "text/html": [], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ " perceives ('Dirty', 'None') and does Suck at (5, 1)\n" ] }, { "data": { "text/html": [], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ " perceives ('Clean', 'None') and does Up at (5, 1)\n" ] }, { "data": { "text/html": [], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ " perceives ('Clean', 'None') and does Down at (5, 1)\n" ] }, { "data": { "text/html": [], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ " perceives ('Dirty', 'None') and does Suck at (5, 2)\n" ] }, { "data": { "text/html": [], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ " perceives ('Clean', 'None') and does Up at (5, 2)\n" ] }, { "data": { "text/html": [], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "gv.run(10)" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(5, 1)" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rv.location" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "23" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "rv.performance" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now we create a vacuum world without graphics." ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "nve = NewVacuumEnvironment(10,10,bias=0.5)" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[[[],\n", " [],\n", " [],\n", " [],\n", " [],\n", " [],\n", " [],\n", " [],\n", " [],\n", " []],\n", " [[],\n", " [, ],\n", " [],\n", " [],\n", " [],\n", " [],\n", " [],\n", " [],\n", " [],\n", " []],\n", " [[], [], [], [], [], [], [], [], [], []],\n", " [[], [], [], [], [], [], [], [], [], []],\n", " [[], [], [], [], [], [], [], [], [], []],\n", " [[],\n", " [],\n", " [],\n", " [],\n", " [],\n", " [],\n", " [],\n", " [],\n", " [],\n", " []],\n", " [[], [], [], [], [], [], [], [], [], []],\n", " [[], [], [], [], [], [], [], [], [], []],\n", " [[], [], [], [], [], [], [], [], [], []],\n", " [[],\n", " [],\n", " [],\n", " [],\n", " [],\n", " [],\n", " [],\n", " [],\n", " [],\n", " []]]" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "nrv = TraceAgent(BetterReflexVacuumAgent())\n", "nve.add_thing(nrv)\n", "nve.get_world()" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " perceives ('Dirty', 'None') and does Suck at (1, 1)\n", " perceives ('Clean', 'None') and does Up at (1, 1)\n", " perceives ('Clean', 'None') and does Down at (1, 1)\n", " perceives ('Dirty', 'None') and does Suck at (1, 2)\n", " perceives ('Clean', 'None') and does Up at (1, 2)\n", " perceives ('Clean', 'None') and does Left at (1, 1)\n", " perceives ('Clean', 'None') and does Right at (1, 1)\n", " perceives ('Dirty', 'None') and does Suck at (2, 1)\n", " perceives ('Clean', 'None') and does Down at (2, 1)\n", " perceives ('Clean', 'None') and does Up at (2, 2)\n" ] } ], "source": [ "nve.run(10)" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(2, 1)" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "nrv.location" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "23" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "nrv.performance" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "hours\n", "# is it greater than 0?\n", " OK got: 2 expected: . at 0x7fc32822fcb0>\n", "NewVacuumEnvironment - Walls\n", " OK got: '[[[], [], [], [], []], [[], [], [], [], []], [[], [], [], [], []], [[], [], [], [], []], [[], [], [], [], []]]' expected: '[[[], [], [], [], []], [[], [], [], [], []], [[], [], [], [], []], [[], [], [], [], []], [[], [], [], [], []]]'\n", "NewVacuumEnvironment - Dirt\n", " OK got: 159 expected: . at 0x7fc328232170>\n", "NewVacuumEnvironment - Very Clean\n", " OK got: 0 expected: 0\n", "NewVacuumEnvironment - Very Dirty\n", " OK got: 324 expected: 324\n", "TraceAgent and BetterReflexVacuumAgent\n", " perceives ('Dirty', 'None') and does Suck at (1, 1)\n", " OK got: (1, 1) expected: (1, 1)\n", " OK got: 10 expected: 10\n", " perceives ('Clean', 'None') and does Left at (1, 1)\n", " perceives ('Clean', 'None') and does Up at (1, 1)\n", " perceives ('Clean', 'None') and does Down at (1, 1)\n", " perceives ('Dirty', 'None') and does Suck at (1, 2)\n", " perceives ('Clean', 'None') and does Down at (1, 2)\n", " perceives ('Dirty', 'None') and does Suck at (1, 3)\n", " perceives ('Clean', 'None') and does Down at (1, 3)\n", " perceives ('Dirty', 'None') and does Suck at (1, 4)\n", " perceives ('Clean', 'None') and does Up at (1, 4)\n", " perceives ('Clean', 'None') and does Up at (1, 3)\n", " perceives ('Clean', 'None') and does Up at (1, 2)\n", " perceives ('Clean', 'None') and does Left at (1, 1)\n", " perceives ('Clean', 'None') and does Left at (1, 1)\n", " perceives ('Clean', 'None') and does Left at (1, 1)\n", " perceives ('Clean', 'None') and does Right at (1, 1)\n", " perceives ('Dirty', 'None') and does Suck at (2, 1)\n", " perceives ('Clean', 'None') and does Up at (2, 1)\n", " perceives ('Clean', 'None') and does Down at (2, 1)\n", " perceives ('Dirty', 'None') and does Suck at (2, 2)\n", " perceives ('Clean', 'None') and does Down at (2, 2)\n", " OK got: 45 expected: . at 0x7fc328242a70>\n" ] } ], "source": [ "main()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Below we demonstrate the testing code from the end of agents.py" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [], "source": [ "environment = TrivialVacuumEnvironment" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [], "source": [ "agents = [ModelBasedVacuumAgent, ReflexVacuumAgent]" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [], "source": [ "result = compare_agents(environment, agents)" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[(, 9),\n", " (, -989)]" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "result" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.6" } }, "nbformat": 4, "nbformat_minor": 2 }