-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab_1.py
More file actions
77 lines (66 loc) · 2.45 KB
/
Copy pathlab_1.py
File metadata and controls
77 lines (66 loc) · 2.45 KB
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
import random
class VacuumEnvironment:
def __init__(self):
self.status = {
'loc_a':random.choice(['Clean','Dirty']),
'loc_b':random.choice(['Clean','Dirty'])
}
class Agent:
def __init__(self):
self.agent_status = 'active'
self.location = random.choice(['loc_a','loc_b'])
self.env = VacuumEnvironment()
self.cost = 0
def action_suck(self):
self.percept('suck')
self.env.status[self.location] = 'Clean'
self.cost = self.cost + 1
def action_move(self,direction):
self.percept(direction)
if(direction == 'left'):
self.location = 'loc_a'
else:
self.location = 'loc_b'
self.cost = self.cost + 1
def percept(self,action):
print("Percept: ",tuple([self.location,action]))
def take_action(self):
if(self.location == 'loc_a'):
if self.env.status['loc_a'] == 'Dirty':
print("Environement A is dirty.")
self.action_suck()
print("Environment A is clean")
print("After suck:",self.cost)
self.action_move('right')
print("After moving\\ right",self.cost)
print("-------------------------")
else:
print("Environment A is clean")
self.action_move('right')
print("After movig right",self.cost)
print("--------------------------")
elif(self.location == 'loc_b'):
if self.env.status['loc_b'] == 'Dirty':
print("Environment B is dirty.")
self.action_suck()
print("Environment B is clean")
print("After suck:",self.cost)
self.action_move('left')
print("After moving left",self.cost)
print("---------------------------")
else:
print("Environment B is clean")
self.action_move('left')
print("After moving left",self.cost)
print("--------------------------")
else:
print("Agent is lost")
agent = Agent()
iterations = 10
for i in range(iterations):
#agent.take_action()
if agent.env.status['loc_a'] == 'Clean' and agent.env.status['loc_b'] == 'Clean':
print("Since both rooms are clean, agent goes inactive")
agent.agent_status = 'inactive'
break
agent.take_action()