Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit adb2c42

Browse files
committed
Environment for task 2.13, failing Suck and dirt sensor
1 parent 5c8e93a commit adb2c42

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

Our_vacuum.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,33 @@
1+
import agents
12
from agents import *
23

4+
from random import random
5+
class VacuumEnvironment213(agents.TrivialVacuumEnvironment):
6+
def percept(self, agent):
7+
if random() < 0.9:
8+
return super().percept(agent)
9+
else:
10+
print("Dirt sensor failed")
11+
if self.status[agent.location] == "Dirty":
12+
return (agent.location, "Clean")
13+
else:
14+
return (agent.location, "Dirty")
15+
16+
def execute_action(self, agent, action):
17+
if action is not "Suck" or random() < 0.75:
18+
# everything is normal
19+
super().execute_action(agent, action)
20+
else: # Suck failed
21+
print("Suck failed")
22+
if self.status[agent.location] == "Clean":
23+
print("Deposited dirt on a clean floor")
24+
self.add_thing(Dirt(), agent.location)
25+
26+
env = VacuumEnvironment213()
27+
env.add_thing(agents.TraceAgent(agents.RandomVacuumAgent()))
28+
env.run(100)
29+
30+
331
def OurVacuum():
432
Env = TrivialVacuumEnvironment()
533
Env.add_thing(TraceAgent(RandomVacuumAgent()))

0 commit comments

Comments
 (0)