Project by: Abhishek Raghuraman
A project showcasing modern game development techniques, multi-agent AI implementation, and professional UI design in Python.
Multi-Agent Connect Four is a modern implementation of the classic Connect Four board game, developed as a comprehensive demonstration of game development skills and AI programming techniques.
Primary Objectives:
- Create a fully functional Connect Four game with intuitive mouse-based controls
- Implement intelligent AI opponents with multiple difficulty levels and distinct strategies
- Develop a modern, visually appealing user interface with smooth animations and dark theme
- Provide comprehensive game statistics and performance tracking
This project encompasses a complete desktop gaming application featuring:
Core Game Features:
- Human vs Human - Classic two-player local multiplayer mode
- Human vs AI - Single-player mode with selectable AI difficulty levels
- AI vs AI Demo - Automated demonstration showing AI strategies in action
- Real-time winner detection with visual highlighting of winning pieces
- Animated gameplay with smooth piece dropping and visual feedback
- Game statistics tracking with persistent data storage
AI Implementation:
- Easy AI - Random move selection with slight center column preference
- Medium AI - Strategic gameplay featuring win detection, opponent blocking, and center positioning
- Hard AI - Advanced strategic evaluation with multi-move planning and threat analysis
- Automatic AI moves with realistic thinking delays and visual indicators
User Interface:
- Modern dark theme with professional color scheme and typography
- Responsive button system with hover effects and visual feedback
- Statistics dashboard displaying game history, win rates, and performance metrics
- Game over screens with detailed match results and replay options
- Smooth navigation between all game screens and modes
Technical Features:
- Modular architecture with clean separation of concerns
- Robust error handling and input validation
- Data persistence using JSON for game statistics
- Python 3.8+ - Primary programming language for all game logic and AI implementation
- Pygame 2.1+ - Graphics rendering engine, event handling, and game loop management
- JSON - Built-in library for data serialization and statistics persistence
- Object-Oriented Programming - Clean class-based architecture with inheritance
- Modular Design Pattern - Separated concerns across multiple specialized modules
- Type Hints - Enhanced code documentation and IDE support using typing module
ConnectFour/
├── main.py # Application entry point
├── requirements.txt # Project dependencies specification
├── src/ # Source code directory
│ ├── __init__.py # Package initialization
│ ├── config.py # Game configuration and visual constants
│ ├── board.py # Game board logic and rendering
│ ├── player.py # Player classes (Human and AI)
│ ├── game_engine.py # Main game engine and state management
│ └── ui_manager.py # User interface management and rendering
└── data/ # Runtime data storage
├── scores.json # Game results and match history
Ensure your system has the following installed:
- Python 3.8 or higher
- pip
Ensure you have the complete project directory with all source files:
main.py- Application entry pointsrc/- Directory with all Python modulesdata/- Directory for game statisticsrequirements.txt- File which specifies the project's dependencies
# Install pygame directly
pip install requirements.txt
# Run the game
python main.py- Mouse Movement - Hover over board columns to preview piece placement
- Left Mouse Click - Drop piece into selected column
- ESC Key - Return to main menu from any screen or game state
- Menu Navigation - Click buttons to navigate between different screens
- Local Multiplayer - Two players alternate turns on the same computer
- Turn Indicators - Clear visual indication of whose turn it is
- Win Detection - Automatic detection of horizontal, vertical, and diagonal wins
- Statistics Tracking - All games recorded for performance analysis
- Difficulty Selection - Choose from Easy, Medium, or Hard AI opponents
- AI Thinking Indicators - Visual feedback showing when AI is calculating moves
- Strategic Gameplay - Each difficulty level employs different strategies:
- Easy: Random moves with slight center preference
- Medium: Win/block detection with strategic positioning
- Hard: Advanced move evaluation and multi-turn planning
- Automated Gameplay - Watch AI opponents battle each other
- Strategy Comparison - Observe different AI difficulty levels competing
- Educational Value - Learn Connect Four strategy by watching AI play
- Comprehensive Tracking - All games automatically recorded with detailed statistics
- Performance Metrics - Win rates, average game duration, and move analysis
- Persistent Storage - Game data saved automatically between sessions
- Game History - Review recent matches with complete game details
The project follows a clean, modular architecture with well-separated concerns:
main.py- Application entry point with error handling and pygame initializationconfig.py- Centralized configuration management for all game constantsboard.py- Core game logic including move validation and winner detectionplayer.py- Player abstraction with Human and AI implementationsgame_engine.py- Main game state management and flow controlui_manager.py- Complete user interface rendering and event handling
The AI system features three distinct difficulty levels:
Easy AI:
- Random move selection from valid positions
- Basic center column preference for improved positioning
- Minimal strategic thinking for beginner-friendly gameplay
Medium AI:
- Immediate win detection and execution
- Opponent threat blocking to prevent losses
- Strategic center column positioning
- Balanced challenge for intermediate players
Hard AI:
- Advanced move evaluation with scoring system
- Multi-move strategic planning
- Threat analysis and tactical positioning
- Challenging gameplay for experienced players
- Responsive AI - Move calculations complete within 0.5-1.5 seconds
- Efficient Rendering - Optimized graphics for smooth visual experience
- Minimal Memory Usage - Lightweight design suitable for all systems
Modify src/config.py to customize game parameters:
# Board Configuration
ROWS = 6 # Number of board rows
COLS = 7 # Number of board columns
CONNECT_LENGTH = 4 # Pieces needed to win
# Display Settings
WINDOW_WIDTH = 900 # Game window width
WINDOW_HEIGHT = 700 # Game window height
CELL_SIZE = 80 # Size of each board cell
PIECE_RADIUS = 35 # Radius of game piecesModify AI thinking times and behaviors in src/player.py:
# Thinking delays
self.think_time = {
'EASY': 0.5, # Fast random moves
'MEDIUM': 1.0, # Moderate strategic thinking
'HARD': 1.5 # Longer strategic analysis
}.get(difficulty, 1.0)- Horizontal - Four pieces in a row horizontally
- Vertical - Four pieces in a column vertically
- Diagonal - Four pieces diagonally (both directions)
- Draw - Board completely filled with no winner
- Piece Preview - Hover over columns to see where pieces will drop
- Turn Indicators - Clear display of current player and colored indicators
- Winning Highlights - Animated effect on winning piece combinations
- AI Status - Visual indication when AI is calculating moves
- Game History - Complete record of all matches played
- Win Statistics - Breakdown of wins by player type (Human/AI/Draw)
- Performance Metrics - Average game duration and move counts
- Recent Games - Quick view of last 5 games with detailed results
- Clean Architecture - Well-organized modules with single responsibilities
- Type Safety - Comprehensive type hints throughout the codebase
- Error Handling - Robust exception handling for stability
- Documentation - Clear docstrings and comments explaining functionality
The modular design allows for easy extension:
- Additional AI Types - Extend
AIPlayerclass for new strategies - UI Themes - Modify color schemes in
config.py - New Game Modes - Add functionality to
game_engine.py - Enhanced Statistics - Extend data tracking in
ui_manager.py
Technical Specifications:
- Minimum Requirements: Python 3.8, Pygame 2.1, 2GB RAM
- Recommended: Python 3.10+, 4GB RAM for optimal performance
- Platform Support: Any platform supporting Python and Pygame