Skip to content

๐Ÿ”ด๐ŸŸก Modern web-based Connect 4 game with intelligent AI opponent powered by Minimax algorithm with Alpha-Beta Pruning. Challenge yourself against strategic AI that thinks 5 moves ahead! Fast, responsive, and session-based for multi-user support.

Notifications You must be signed in to change notification settings

viliusjan/connect4-ai

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

7 Commits
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Connect 4 AI Game ๐Ÿ”ด๐ŸŸก

A modern, web-based Connect 4 game featuring an intelligent AI opponent powered by the Minimax algorithm with Alpha-Beta Pruning. Challenge yourself against a strategic AI that thinks 5 moves ahead!

โœจ Features

  • ๐Ÿง  Intelligent AI Opponent โ€” Minimax with Alpha-Beta Pruning for strategic gameplay
  • ๐Ÿ‘ฅ Multi-User Support โ€” Each browser gets its own game session
  • ๐Ÿ“ฑ Responsive Design โ€” Seamless experience on desktop, tablet, and mobile devices
  • โšก Fast Performance โ€” AI makes decisions in under 1 second
  • ๐ŸŽจ Modern UI โ€” Clean interface with smooth animations and visual feedback
  • ๐ŸŽฏ Strategic Depth โ€” AI analyzes up to 5 moves ahead for challenging gameplay

๐Ÿง  AI Performance Metrics

Metric Value
Search Depth 5 levels
Average Response < 1 second
Nodes Evaluated 10,000 - 50,000 per move
Algorithm Minimax + Alpha-Beta Prune
Difficulty Level Challenging

๐Ÿš€ Quick Start

Prerequisites

  • Python 3.7 or higher
  • Git

Installation & Setup

  1. Clone the repository

    git clone https://github.com/viliusjan/connect4-ai.git
    cd connect4-ai
  2. Install the project's requirements

    pip install flask
  3. Generate a Flask secret key
    Run this in Python:

    import secrets
    print(secrets.token_hex(32))

    Copy the generated string.

  4. Set your secret key in connect4.py

    app = Flask(__name__)
    app.secret_key = 'paste_your_generated_secret_key_here'
  5. Run the game locally

    python3 connect4.py
  6. Open your browser

    Navigate to: http://localhost:8000
    

๐Ÿ“ Project Structure

connect4-ai/
โ”œโ”€โ”€ connect4.py          # Main Flask application (session-based, multi-user)
โ”œโ”€โ”€ templates/           # HTML templates
โ””โ”€โ”€ README.md            # Project documentation

๐ŸŽฏ Game Rules

Connect 4 is a classic strategy game where players take turns dropping colored pieces into a grid:

  • Objective: Be the first to get 4 pieces in a row
  • Winning Conditions: Horizontal, vertical, or diagonal connections
  • Grid Size: 7 columns ร— 6 rows
  • Turn-based: Players alternate dropping pieces
  • Gravity Effect: Pieces fall to the lowest available position

๐Ÿงฎ Algorithm Details

The AI uses a sophisticated decision-making process:

  • Minimax Algorithm: Evaluates all possible future game states
  • Alpha-Beta Pruning: Optimizes search by eliminating inferior branches
  • Evaluation Function: Scores board positions based on strategic value
  • Depth Limitation: Searches 5 moves ahead for optimal performance balance

๐Ÿค Contributing

Contributions are welcome! Here's how you can help:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ› Issues & Support

Found a bug or have a suggestion? Please:

  1. Check existing issues
  2. Create a new issue with detailed description
  3. Include steps to reproduce (if applicable)

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • Classic Connect 4 game concept by Milton Bradley
  • Minimax algorithm implementation inspired by AI game theory
  • Thanks to the Python and Flask communities

Enjoy playing Connect 4 AI! ๐ŸŽ‰

Challenge yourself against an intelligent opponent and improve your strategic skills.

About

๐Ÿ”ด๐ŸŸก Modern web-based Connect 4 game with intelligent AI opponent powered by Minimax algorithm with Alpha-Beta Pruning. Challenge yourself against strategic AI that thinks 5 moves ahead! Fast, responsive, and session-based for multi-user support.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published