This is a Python-based grid game implemented using Pygame, where two players take turns selecting dots to form squares. The first player to complete a square wins. The game includes an AI agent using the Minimax algorithm for single-player mode.
- Players take turns selecting unmarked dots on a grid.
- A square is formed when four selected dots align to create a perfect square (any size or orientation).
- The first player to complete a square wins.
- If all dots are selected without forming a square, the game ends in a draw.
gameboard.py– Handles the graphical user interface (UI) for the game.gameai.py– Implements the Minimax algorithm for the AI opponent.sq.py– Contains core game functions like updating weights, checking for winners, and evaluating board states.
The AI prioritizes moves using:
- Initial Point Ordering – Points are pre-ranked based on the number of squares they contribute to.
- Weight Updates – Points adjacent to previous moves (both opponent and AI) get increased weight.
- Critical Move Identification – The highest priority is given to moves that form a square (placing the fourth point when three of the same color exist).
- Python 3.x
- Pygame library
- Clone the repository:
git clone <repo_url> cd square-game
- Install dependencies:
pip install pygame
- Run the game:
python gameboard.py
