-
Notifications
You must be signed in to change notification settings - Fork 1
/
vacuum.py
100 lines (92 loc) · 3.65 KB
/
vacuum.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
95
96
97
98
99
100
"""
CVR COLLEGE OF ENGINEERING AND TECHNOLOGY
DEPARTMENT OF ARTIFICIAL INTELLIGENCE
PROGRAM: A SIMPLE REFLEX BASED VACUUM CLEANING AGENT
BY: MIR HABEEBULLAH SHAH QUADRI
ROLL NO: 18B81DA914
CLASS: MTECH - I YEAR (AI)
UNDER THE GUIDANCE AND SUPERVISION OF: DR.PONUSAMY
"""
import random
# Create the environment with two locations A and B
# Assign values 1 or 0 randomly to the locations
# 0 means clean and 1 means dirty
class Environment(object):
def __init__(self):
self.locationCondition = {'A':'0', 'B':'0'}
self.locationCondition['A'] = random.randint(0,1)
self.locationCondition['B'] = random.randint(0,1)
print('Location Conditions are:', self.locationCondition)
# Create the simple reflex agent as an extention to the evironment class
# Set the score to 0
# Place the agent randomly at one location 0 or 1
# 0 means location A and 1 means location B
class SimpleReflexVacuumAgent(Environment):
def __init__(self, Environment):
self.score = 0
self.vacuumLocation = random.randint(0,1)
self.locationCondition = Environment.locationCondition
# Check the position the agent currently is in
# If dirty, clean and increment the score by 1
# If clean, decrement the score by 1 and move to next location
# Repeat the same process for the next location
def runVacuum(self):
if self.vacuumLocation == 0:
print('Currently at location A')
if self.locationCondition['A'] == 1:
self.cleanLocation(0)
print('Moving to location B')
if self.locationCondition['B'] == 1:
self.cleanLocation(1)
else:
print('Location B is already clean!')
self.score -= 1
else:
print('Location A is already clean!')
self.score -= 1
print('Moving to location B')
if self.locationCondition['B'] == 1:
self.cleanLocation(1)
else:
print('Location B is already clean!')
self.score -= 1
else:
print('Currently at Location B')
if self.locationCondition['B'] == 1:
self.cleanLocation(1)
print('Moving to location A')
if self.locationCondition['A'] == 1:
self.cleanLocation(0)
else:
print('Location A is already clean')
self.score -= 1
else:
print('Location B is already clean')
self.score -= 1
print('Moving to location A')
if self.locationCondition['A'] == 1:
self.cleanLocation(0)
else:
print('Location A is already clean')
self.score -= 1
# Used for executing the suck operation of the vacuum cleaner
# If location is 0 then clean location A and set location condition to 0
# If location is 1 then clean location B and set location condition to 0
# Increment the score by 1 in both cases
def cleanLocation(self, location):
if location == 0:
print('Location A is dirty. Use Vacuum Cleaner')
self.locationCondition['A'] = 0
self.score += 1
print('Location A is now clean!')
else:
print('Location B is dirty. User Vacuum Cleaner')
self.locationCondition['B'] = 0
self.score += 1
print('Location B is now clean!')
def printScore(self):
print('The score is: ', self.score)
e = Environment()
srva = SimpleReflexVacuumAgent(e)
srva.runVacuum()
srva.printScore()