From 17645c77e5294e4be82516d9fc54d177661bcb0c Mon Sep 17 00:00:00 2001 From: Kaivalya Rawal Date: Wed, 22 Mar 2017 15:47:35 +0530 Subject: [PATCH 1/4] replace assert with if test in add_thing --- agents.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/agents.py b/agents.py index 047eb3fd6..e1b987b14 100644 --- a/agents.py +++ b/agents.py @@ -297,12 +297,14 @@ def add_thing(self, thing, location=None): for it. (Shouldn't need to override this.""" if not isinstance(thing, Thing): thing = Agent(thing) - assert thing not in self.things, "Don't add the same thing twice" - thing.location = location if location is not None else self.default_location(thing) - self.things.append(thing) - if isinstance(thing, Agent): - thing.performance = 0 - self.agents.append(thing) + if thing in self.things: + print("Can't add the same thing twice") + else: + thing.location = location if location is not None else self.default_location(thing) + self.things.append(thing) + if isinstance(thing, Agent): + thing.performance = 0 + self.agents.append(thing) def delete_thing(self, thing): """Remove a thing from the environment.""" From 98e0a40cfc80f031efec0241a56b0f31e3fd82e7 Mon Sep 17 00:00:00 2001 From: Kaivalya Rawal Date: Wed, 22 Mar 2017 15:49:05 +0530 Subject: [PATCH 2/4] removed inline assert --- agents.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/agents.py b/agents.py index e1b987b14..da10f2760 100644 --- a/agents.py +++ b/agents.py @@ -85,10 +85,9 @@ def __init__(self, program=None): self.bump = False self.holding = [] self.performance = 0 - if program is None: + if program is None or not isinstance(program, collections.Callable): def program(percept): return eval(input('Percept={}; action? '.format(percept))) - assert isinstance(program, collections.Callable) self.program = program def can_grab(self, thing): From 732f48bb622e57445042c436e1922d52b48be467 Mon Sep 17 00:00:00 2001 From: Kaivalya Rawal Date: Wed, 22 Mar 2017 15:56:33 +0530 Subject: [PATCH 3/4] added unit test to check edit --- tests/test_agents.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/test_agents.py b/tests/test_agents.py index 0162a78b8..699e317f7 100644 --- a/tests/test_agents.py +++ b/tests/test_agents.py @@ -1,4 +1,5 @@ from agents import Direction +from agents import Agent from agents import ReflexVacuumAgent, ModelBasedVacuumAgent, TrivialVacuumEnvironment @@ -65,3 +66,9 @@ def test_ModelBasedVacuumAgent() : # check final status of the environment assert environment.status == {(1,0):'Clean' , (0,0) : 'Clean'} +def test_Agent(): + def constant_prog(percept): + return percept + agent = Agent(constant_prog) + result = agent.program(5) + assert result == 5 From 84144b3b515cb1177a60e50d9a89771a6a60d5b8 Mon Sep 17 00:00:00 2001 From: Kaivalya Rawal Date: Wed, 22 Mar 2017 22:21:54 +0530 Subject: [PATCH 4/4] improve user interface --- agents.py | 1 + 1 file changed, 1 insertion(+) diff --git a/agents.py b/agents.py index da10f2760..ff049aa4a 100644 --- a/agents.py +++ b/agents.py @@ -86,6 +86,7 @@ def __init__(self, program=None): self.holding = [] self.performance = 0 if program is None or not isinstance(program, collections.Callable): + print("Can't find a valid program for {}, falling back to default.".format(self.__class__.__name__)) def program(percept): return eval(input('Percept={}; action? '.format(percept))) self.program = program pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy