-
Notifications
You must be signed in to change notification settings - Fork 8
/
agentTwo.py
94 lines (82 loc) · 3.53 KB
/
agentTwo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import random
class Environment(object):
def __init__(self):
# instantiate locations and conditions
# 0 indicates Clean and 1 indicates Dirty
self.locationCondition = {'A': '0', 'B': '0'}
# randomize conditions in locations A and B
self.locationCondition['A'] = random.randint(0, 1)
self.locationCondition['B'] = random.randint(0, 1)
class SimpleReflexVacuumAgent(Environment):
def __init__(self, Environment):
print Environment.locationCondition
# Instantiate performance measurement
Score = 0
# place vacuum at random location
vacuumLocation = random.randint(0, 1)
# if vacuum at A
if vacuumLocation == 0:
print "Vacuum is randomly placed at Location A"
# and A is Dirty
if Environment.locationCondition['A'] == 1:
print "Location A is Dirty. "
# suck and mark clean
Environment.locationCondition['A'] = 0;
Score += 1
print "Location A has been Cleaned. :D"
# if B is Dirty
if Environment.locationCondition['B'] == 1:
print "Location B is Dirty."
# move to B
print "Moving to Location B..."
Score -= 1
# suck and mark clean
Environment.locationCondition['B'] = 0;
Score += 1
print "Location B has been Cleaned :D."
else:
# if B is Dirty
if Environment.locationCondition['B'] == 1:
print "Location B is Dirty."
# move to B
Score -= 1
print "Moving to Location B..."
# suck and mark clean
Environment.locationCondition['B'] = 0;
Score += 1
print "Location B has been Cleaned. :D"
elif vacuumLocation == 1:
print "Vacuum is randomly placed at Location B. "
# and B is Dirty
if Environment.locationCondition['B'] == 1:
print "Location B is Dirty"
# suck and mark clean
Environment.locationCondition['B'] = 0;
Score += 1
print "Location B has been Cleaned"
# if A is Dirty
if Environment.locationCondition['A'] == 1:
print "Location A is Dirty"
# move to A
Score -= 1
print "Moving to Location A"
# suck and mark clean
Environment.locationCondition['A'] = 0;
Score += 1
print "Location A has been Cleaned"
else:
# if A is Dirty
if Environment.locationCondition['A'] == 1:
print "Location A is Dirty"
# move to A
print "Moving to Location A"
Score -= 1
# suck and mark clean
Environment.locationCondition['A'] = 0;
Score += 1
print "Location A has been Cleaned"
# done cleaning
print Environment.locationCondition
print "Performance Measurement: " + str(Score)
theEnvironment = Environment()
theVacuum = SimpleReflexVacuumAgent(theEnvironment)