This project simulates a robotic agent navigating a 5ร5 grid to collect randomly placed leaf debris. The system is implemented in Python using Jupyter Notebook and ipywidgets
for interactive visualization. The robot operates under two distinct modes:
- Without Memory: The agent cleans the environment without storing visited positions.
- With Memory: The agent keeps track of cleaned cells using a memory matrix and adapts its behavior to ensure full coverage.
The robot starts with a defined amount of energy and a central starting position. As it navigates the grid, it attempts to remove leaf debris (๐
) scattered randomly on the board. It consumes one unit of energy per action (scan or move). The simulation ends when energy is exhausted or all debris is removed.
- Python 3.9+
- Jupyter Notebook
- ipywidgets โ for dynamic visual rendering of the grid
- NumPy โ for efficient matrix management and logic
- The board is displayed as a grid using HTML tables.
- The robot (๐ค) moves in cardinal directions.
- It consumes energy while scanning or moving.
- Each cell may or may not contain a piece of debris (
๐
). - The robot removes a leaf if it occupies the same cell.
- The robot operates reactively.
- It only checks and cleans the current cell.
- Movement is random, without reference to past states.
- No internal representation of visited or cleaned cells is maintained.
- The robot maintains a
n ร n
memory matrix:0
: Unvisited or uncertain1
: Visited and clean
- In addition to scanning the current cell, the robot:
- Scans its 4 neighboring cells (
escaneoVecino
) - Updates its memory based on findings
- Attempts to follow a logical cleaning path
- Executes a deep cleaning column-based strategy if no debris is found after several steps
- Scans its 4 neighboring cells (
Function | Description |
---|---|
llenadoAleatorio() |
Randomly places leaf debris (๐ ) on the grid |
escaneo() |
Scans and cleans the current cell |
escaneoVecino() |
Scans adjacent cells and updates memory matrix |
avanzar() |
Moves the robot one step in the direction of its angulo |
girar(angulo) |
Changes the robotโs orientation |
revisionMemoria() |
Checks whether all cells have been visited or verified |
limpieza(agente, escenario) |
Main cleaning loop (while energy and uncleaned cells remain) |
The grid is rendered as a dynamic HTML table:
๐ค
: Cleaning robot๐
: Leaf debris- Empty cells: Clean and unoccupied
Parameter | Value |
---|---|
Grid Size | 5 ร 5 |
Initial Position | (2, 2) |
Initial Energy | 200 |
Debris Probability | 50% per cell |
Emoticons | ๐ค (robot), ๐ (leaf) |
At the end of the simulation, the following are printed:
- โ Total leaves collected
- ๐ Energy consumed
- ๐งผ Whether the robot completed a full cleaning (with memory only)
Josh Sebastiรกn Lรณpez Murcia