0% found this document useful (0 votes)
29 views7 pages

Programming Assignment Unit 2 - 1

The document outlines a programming assignment focused on designing a rational agent for cleaning a static 4x4 grid environment using the PEAS framework. It includes a detailed description of the agent's performance measures, environment, actuators, and sensors, along with Python-style pseudocode for the agent's functionality. The reflection section emphasizes the importance of structured decision-making, energy management, and the potential complexities of real-world applications compared to the simplified grid model.

Uploaded by

Anabi Asah
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)
29 views7 pages

Programming Assignment Unit 2 - 1

The document outlines a programming assignment focused on designing a rational agent for cleaning a static 4x4 grid environment using the PEAS framework. It includes a detailed description of the agent's performance measures, environment, actuators, and sensors, along with Python-style pseudocode for the agent's functionality. The reflection section emphasizes the importance of structured decision-making, energy management, and the potential complexities of real-world applications compared to the simplified grid model.

Uploaded by

Anabi Asah
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

Artificial Intelligence

Programming Assignment Unit 2


Part A: PEAS Description
Performance Measure (P): The agent’s goal is to clean all dirty locations using the minimum
number of actions, return to the home location (A), manage energy efficiently, and empty the bag
when it becomes full.
Environment (E): The environment is a static 4×4 grid with 16 locations labeled A to P. Some
locations contain dirt and some are clean. There are no obstacles in the basic version.
Actuators (A): The agent can move North, South, East, or West. It can also suck dirt and empty
its bag at the home location (A).
Sensors (S): The agent can sense its current location, whether the location is dirty or clean, the
level of dirt in its bag, and how much energy remains.

Part B: Python-style Pseudocode


# -----------------------------

# Environment and Agent Setup

# -----------------------------

environment = {

"A": "Dirty", "B": "Clean", "C": "Dirty", "D": "Clean",

"E": "Dirty", "F": "Clean", "G": "Clean", "H": "Dirty",

"I": "Clean", "J": "Dirty", "K": "Clean", "L": "Clean",

"M": "Dirty", "N": "Clean", "O": "Dirty", "P": "Clean"

grid = [

["A", "B", "C", "D"],

["E", "F", "G", "H"],

["I", "J", "K", "L"],

["M", "N", "O", "P"]

agent_location = "A"

home = "A"

energy = 100
bag_capacity = 10

bag_level = 0

# -----------------------------

# Helper Functions

# -----------------------------

def get_index(location):

"""Return the index of a location (A=0, B=1, ..., P=15)."""

return ord(location) - ord("A")

def get_location(index):

"""Return the location letter from an index."""

return chr(index + ord("A"))

def direction_to(current, next_loc):

"""Determine direction from current to next location."""

current_index = get_index(current)

next_index = get_index(next_loc)

current_row, current_col = divmod(current_index, 4)

next_row, next_col = divmod(next_index, 4)

if next_row == current_row and next_col == current_col + 1:

return "East"

elif next_row == current_row and next_col == current_col - 1:

return "West"

elif next_row == current_row + 1 and next_col == current_col:

return "South"

elif next_row == current_row - 1 and next_col == current_col:

return "North"

else:

return None

def move(location, direction):

"""Move agent in the given direction and return new location."""

index = get_index(location)

row, col = divmod(index, 4)

if direction == "North":

row -= 1
elif direction == "South":

row += 1

elif direction == "East":

col += 1

elif direction == "West":

col -= 1

# Stay in bounds

row = max(0, min(row, 3))

col = max(0, min(col, 3))

new_index = row * 4 + col

return get_location(new_index)

def get_direction_toward_home(location):

"""Return the best direction to move toward home (A)."""

home_index = get_index(home)

current_index = get_index(location)

home_row, home_col = divmod(home_index, 4)

current_row, current_col = divmod(current_index, 4)

if current_row > home_row:

return "North"

elif current_row < home_row:

return "South"

elif current_col > home_col:

return "West"

elif current_col < home_col:

return "East"

else:

return None

# -----------------------------

# Decision-Making Functions

# -----------------------------

def decide_action(location):

"""Decide whether to Suck, Move, or Go Home."""


global bag_level

if environment[location] == "Dirty":

return "Suck"

elif bag_level == bag_capacity:

return "Go_Home"

else:

return "Move"

def get_next_direction(location):

"""Return direction to the next unvisited location in order."""

index = get_index(location)

if index < 15:

next_location = get_location(index + 1)

return direction_to(location, next_location)

else:

return None

def navigate_home(location):

"""Return the path (list of directions) from current location to home."""

path = []

while location != home:

direction = get_direction_toward_home(location)

[Link](direction)

location = move(location, direction)

return path

def goal_achieved():

"""Check if all locations are clean and agent is at home."""

for location in environment:

if environment[location] == "Dirty":

return False

return agent_location == home

# -----------------------------

# Main Agent Loop

# -----------------------------

while energy > 0 and not goal_achieved():


action = decide_action(agent_location)

if action == "Suck":

environment[agent_location] = "Clean"

bag_level += 1

energy -= 1

print(f"Suck at {agent_location}. Bag: {bag_level}, Energy: {energy}")

elif action == "Go_Home":

path = navigate_home(agent_location)

for step in path:

agent_location = move(agent_location, step)

energy -= 1

print(f"Move {step} to {agent_location}. Energy: {energy}")

bag_level = 0

print("Bag emptied at home.")

elif action == "Move":

direction = get_next_direction(agent_location)

if direction is not None:

agent_location = move(agent_location, direction)

energy -= 1

print(f"Move {direction} to {agent_location}. Energy: {energy}")

print("Goal achieved or energy depleted.")


Part C: Summary and Reflection
This assignment helped me understand how a rational agent works and how artificial intelligence
systems make decisions based on rules and goals. Before doing this assignment, I thought a
vacuum cleaner robot simply moves randomly and cleans when it finds dirt. However, after
designing this agent, I realized that even a simple environment requires structured decision-
making, energy management, and logical planning. The PEAS framework helped me clearly
identify the agent’s goal, the environment it operates in, what actions it can perform, and what it
can sense. This made the design process more organized and easier to understand.
One important lesson I learned is how to break a complex task into smaller functions. Instead of
writing one long block of code, I created separate functions for deciding actions, choosing
movement direction, navigating back home, and checking if the goal is achieved. This modular
approach made the program easier to understand and manage. It also showed me how real-world
AI systems are built using smaller components that work together.
Regarding the energy limit of 100 points, I believe the agent should be able to reach the goal
within this limit in the 4×4 grid environment. There are only 16 locations, and each action costs
1 energy point. Even if the agent moves to every location and cleans all dirty spots, the total
number of actions will likely be far less than 100. The only additional energy usage comes from
returning home to empty the bag when it is full. Since the bag capacity is 10 and the environment
has only 16 locations, the agent would not need to return home too many times. Therefore, 100
energy points should be more than sufficient for this small static environment.
If the static environment becomes bigger, such as an 8×8 or 10×10 grid, changes would be
necessary. The current simple movement strategy (moving in sequence from A to P) would not
be efficient for larger environments. The agent needs a more advanced path-planning algorithm
such as Breadth-First Search (BFS) or A to find the shortest path to dirty locations and return
home efficiently. Additionally, energy management would become more important because the
agent could easily run out of energy in a larger space. The data structure representing the
environment would also need to be more flexible, possibly using a larger 2D array or graph
structure.
In the real world, the environment is much more complex than a static grid. A smart vacuum
cleaner must handle obstacles such as furniture, walls, humans, and pets. To handle these
obstacles, the agent would need additional sensors like cameras, infrared sensors, and bump
sensors. The algorithm would need to detect obstacles and adjust the path dynamically instead of
following a fixed route. This would change the environment from static to dynamic, meaning the
agent must constantly update its knowledge and react in real time. It may also need machine
learning techniques to improve efficiency over time by remembering obstacle locations and
frequently dirty areas.
Overall, this assignment helped me understand how rational agents function in controlled
environments and how artificial intelligence systems use perception, decision-making, and
planning to achieve goals. It also showed me that even simple problems can become complex
when we consider real-world conditions.

References
Poole, D. L., & Mackworth, A. K. (2025). Artificial Intelligence: Foundations of Computational
Agents, 3rd Edition. Cambridge: Cambridge University Press.
Russell, S. J., & Norvig, P. (2022). Artificial Intelligence A Modern Approach Fourth Edition.
Harlow: Pearson Education Limited.

You might also like