0% found this document useful (0 votes)
5 views

Michael T Ai assignment

The document contains an individual assignment for a computer science course by Michael Tibebu, focusing on a Python implementation of a Vacuum Cleaner Agent. The code defines the agent's behavior, including sensing its environment, performing actions based on its state, and moving between two locations. The agent is designed to clean dirty areas and can operate for a specified number of steps, updating its environment accordingly.

Uploaded by

9w68mqqvn9
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Michael T Ai assignment

The document contains an individual assignment for a computer science course by Michael Tibebu, focusing on a Python implementation of a Vacuum Cleaner Agent. The code defines the agent's behavior, including sensing its environment, performing actions based on its state, and moving between two locations. The agent is designed to clean dirty areas and can operate for a specified number of steps, updating its environment accordingly.

Uploaded by

9w68mqqvn9
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Artificial intelligence assignment

Department of Computer Science


Individual assignment

NAME: Michael Tibebu


ID NO: RCD/0729/2014

SECTION: B
Python code for class Vacuum CleanerAgent
def __init__(self):
# Initial location is A, but you could set it to B depending on your initial conditions
self.location = "A"
self.environment = {"A": "Dirty", "B": "Dirty"} # initial state

def sense(self):
# Sense the state of the current location
return self.environment[self.location]

def perform_action(self, percept):


# Decide action based on the percept
if percept == "Dirty":
print(f"{self.location} is Dirty. Sucking...")
self.environment[self.location] = "Clean"
else:
if self.location == "A":
print("Moving to B...")
self.location = "B"
else:
print("Moving to A...")
self.location = "A"

def run(self, steps):


# Run the vacuum cleaner for a set number of steps
for _ in range(steps):
percept = self.sense()
self.perform_action(percept)
print(f"Environment: {self.environment}")
print(f"Location: {self.location}\n")

# Create and run the vacuum cleaner agent


vacuum_agent = VacuumCleanerAgent()
vacuum_agent.run(10)

You might also like