Exp-2 Simple Reflex Agent
Exp-2 Simple Reflex Agent
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.
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.
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.