Professional Documents
Culture Documents
Ai Lb6 Hanzala Amir rc-398
Ai Lb6 Hanzala Amir rc-398
BSCS-36
RC-298
Hanzala amir
Artificial
Intelligence
(Lab6)
LAB 5: Intelligent Agents
5.1.3 TASK:
o Can you name few model-based reflex agents?
o Write a program for model-based reflex agent of your own choice.
o Consider the vacuum world shown in the figure below:
This particular world has just two locations: squares A and B. The vacuum agent perceives
which square it is in and whether there is dirt in the square. It can choose to move left, move
right, suck up the dirt, or do nothing. One very simple agent function is the following: if the
current square is dirty, then suck, otherwise move to the other square. Write a simple reflex agent
for the vacuum cleaner. (Hint: Agent has no initial states knowledge)
If the current square is dirty, then suck; otherwise, move to the other square.
Pseudocode to the task is as follows;
function Reflex-Vacuum-Agent( [location,status]) returns an
action if status = Dirty then return Suck else if location = A then
return Right else if location = B then return Left
class VacuumAgent:
def __init__(self):
self.location = 'A' # Starting location of the vacuum cleaner
self.percept_history = {'A': 'Clean', 'B': 'Clean'} # Percept
history to keep track of cleanliness
# Execute action
if action == 'Suck':
print("Sucking dirt at location", self.location)
elif action == 'Left':
self.location = 'A'
print("Moving to location A")
elif action == 'Right':
self.location = 'B'
print("Moving to location B")