Skip to content

SayinAla81/Computational-Intelligence

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

Intelligent Agent for Ball and Hole Puzzle

Overview

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:

  1. Core Logic (C++): Implements the intelligent agent's functionality, including exploration and decision-making.
  2. Visualization (Python): Provides a visual representation of the agent's actions and the grid's state using the tkinter library.

Features

  • 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.

Files

  1. 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.
  2. 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.

How to Run

Prerequisites

  • C++ Compiler: Ensure you have g++ installed.
  • Python 3.x: With tkinter library installed.

Steps

  1. Compile and run the C++ code:
    g++ Project.cpp -o main && ./main
  2. 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.

  1. 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
    
  1. Observe the agent's behavior dynamically as it explores the grid, picks up balls, and places them into holes.

Cleanup

The Python script automatically cleans up temporary files (output.txt and the compiled executable) after execution. No manual cleanup is necessary.

Customization

You can customize the behavior and settings of the program to suit your requirements:

  1. Grid Size and Object Count:
  • Modify the constants in Project.cpp to change the grid dimensions or the number of balls and holes:
    const ll ROW_SIZE = 5, COLUMN_SIZE = 5, NUM_BALL = 5;
    Increase or decrease these values to adjust the game's complexity.
  1. Visualization:
  • Adjust the cell size or colors in Show.py by modifying the relevant sections in the draw_colored_table function.
  1. Execution Behavior:
  • Change the agent's constraints (e.g., number of moves allowed) by editing the corresponding logic in Project.cpp.

Example Output

Here’s an example of what the program looks like during execution:

  1. C++ Output:
  • The program generates a text-based representation of the grid and agent's actions in output.txt.
  1. 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.

Future Enhancements

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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published