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

Exp-2 Simple Reflex Agent

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Exp-2 Simple Reflex Agent

Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Experiment 2

Implement Random Movement Reflex Agent


Simple Reflex Agent – Vacuum Cleaner
Example
1. Initialize Environment:
 Create a grid of squares, each marked as either "Dirty" or
"Clean".
 Place the vacuum cleaner at the starting position (top-left
corner).
Algorithm
2. Define Percepts:
 The agent senses the status (clean or dirty) of the square it
occupies.
3. Define Actions:
 Suck: Clean the current square if it is dirty.
 Move Left: Move one square to the left (if not at the
leftmost edge).
 Move Right: Move one square to the right (if not at the
rightmost edge).
 Move Up: Move one square up (if not at the top edge).
Algorithm  Move Down: Move one square down (if not at the bottom
edge).

4. Movement Strategy:
 Use a systematic strategy to cover the entire grid, such as a
"snake-like" pattern where the agent moves right until it
hits the right edge, then moves down one row and moves
left, and so on.
5. Repeat Until All Squares are Clean:
 Sense the current square.
 If the current square is dirty, perform the ‘Suck’ action.
 Otherwise, move to the next square according to the
Algorithm movement strategy.

6. Terminate:
 The process ends when all squares have been visited and
cleaned.
Classes and Functions used in the
Program

1. SimpleReflexAgent Class:
class SimpleReflexAgent:

get_action(self, percept): Determines the action based on the current percept. If the percept is
"Dirty", the action is "Suck". If the percept is "Clean", the action is "Move".
Classes and Functions used in the
Program
2. Environment Class:
class Environment:

__init__(self, grid): Initializes the environment with a grid and sets the agent's starting location.

get_location_status(self): Returns the status ("Dirty" or "Clean") of the current location.

update(self, action): Updates the environment based on the agent's action. If the action is "Suck", it cleans
the current location. If the action is "Move", it moves the agent in the specified direction.

move_agent(self, direction): Moves the agent based on the specified direction, ensuring the agent stays
within the grid boundaries.

print_grid(self): Prints the current state of the grid.


Main Function definition in the
Program

def main():
 Initializes a grid with "Dirty" and "Clean" cells.
 Creates an environment and an agent.
 Defines the possible movements of the agent.
 Runs the agent for several steps equal to the number of cells in the grid.
 Prints the agent's location, action, and the current state of the grid after each step.

You might also like