This project implements an intelligent agent that operates in a 5x5 game grid. The grid contains randomly placed balls and holes, and the agent's goal is to place the balls into the holes while adhering to specific constraints.
The solution is divided into two parts:
- Core Logic (C++): Implements the intelligent agent's functionality, including exploration and decision-making.
- Visualization (Python): Provides a visual representation of the agent's actions and the grid's state using the
tkinter
library.
- Dynamic Environment: Randomly generated balls and holes at the start of each game.
- Agent Capabilities:
- Move in one of four cardinal directions.
- Pick up a ball.
- Place a ball in a hole.
- Constraints:
- Limited to 30 moves.
- Can carry only one ball at a time.
- Each hole can accommodate exactly one ball.
- Visualization:
- Displays the grid state dynamically.
- Highlights the agent's current location, balls, and holes.
-
Project.cpp:
- Contains the core logic for the intelligent agent.
- Implements algorithms for grid traversal, ball detection, and hole placement.
- Outputs the game state to an external file for visualization.
-
Show.py:
- Reads the game state from the output file generated by
Project.cpp
. - Visualizes the game grid using the
tkinter
library. - Provides a step-by-step view of the agent's actions.
- Reads the game state from the output file generated by
- C++ Compiler: Ensure you have
g++
installed. - Python 3.x: With
tkinter
library installed.
- Compile and run the C++ code:
g++ Project.cpp -o main && ./main
- Execute the Python visualization script:
python Show.py
The visualization will open in a graphical window, showing the current state of the grid, the positions of balls, holes, and the agent.
- To run the program again with a new configuration:
- Modify the input parameters in
Project.cpp
(e.g., grid size, number of balls, etc.). - Recompile the C++ program and execute it to generate a new game state:
g++ Project.cpp -o main && ./main
- Run the Python script again:
python Show.py
- Observe the agent's behavior dynamically as it explores the grid, picks up balls, and places them into holes.
The Python script automatically cleans up temporary files (output.txt
and the compiled executable) after execution. No manual cleanup is necessary.
You can customize the behavior and settings of the program to suit your requirements:
- Grid Size and Object Count:
- Modify the constants in
Project.cpp
to change the grid dimensions or the number of balls and holes:Increase or decrease these values to adjust the game's complexity.const ll ROW_SIZE = 5, COLUMN_SIZE = 5, NUM_BALL = 5;
- Visualization:
- Adjust the cell size or colors in
Show.py
by modifying the relevant sections in thedraw_colored_table
function.
- Execution Behavior:
- Change the agent's constraints (e.g., number of moves allowed) by editing the corresponding logic in
Project.cpp
.
Here’s an example of what the program looks like during execution:
- C++ Output:
- The program generates a text-based representation of the grid and agent's actions in
output.txt
.
- Python Visualization:
- The visualization shows the grid state dynamically:
- Balls are represented as red circles.
- Holes are black circles.
- The agent is shown as a purple square.
The project can be extended in several ways:
-
Scalability:
-
Support for larger grids and more complex configurations.
-
Introduce multi-agent systems for cooperative problem-solving.
-
Enhanced AI:
-
Implement more advanced algorithms (e.g., A*, reinforcement learning) for efficient decision-making.
-
Optimize agent movement to reduce unnecessary exploration.
-
Improved Visualization:
-
Add real-time interaction (e.g., pause, reset, or speed controls).
-
Include labels or tooltips for easier interpretation of the grid.