File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change
1
+ import agents
1
2
from agents import *
2
3
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
+
3
31
def OurVacuum ():
4
32
Env = TrivialVacuumEnvironment ()
5
33
Env .add_thing (TraceAgent (RandomVacuumAgent ()))
You can’t perform that action at this time.
0 commit comments