Skip to content

Latest commit

 

History

56 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Connect 4 with Monte Carlo Tree Search

🎯 Project Overview

This project implements the classic Connect 4 game, with:

  • Graphical User Interface (GUI): An interactive and user-friendly design to play the game.
  • AI Opponent (MCTS): A Monte Carlo Tree Search algorithm that makes strategic decisions, providing a challenging gameplay experience.

The goal is to demonstrate the integration of game logic and artificial intelligence techniques to better understand Monte Carlo methods.


🧠 How the AI Works (MCTS)

Monte Carlo Tree Search (MCTS) is used as the decision-making algorithm:

  • Selection: Traverse the game tree using UCT (Upper Confidence Bound for Trees).
  • Expansion: Add new nodes for unexplored moves.
  • Simulation: Play random games until reaching a terminal state.
  • Backpropagation: Update win/visit counts for all visited nodes.

This process balances exploration (trying new moves) and exploitation (choosing moves that worked in the past).


📂Files content:

< Connect-4.py >
    Graphic version to play
    Can play PvP or PvAI (AI plays using MCTS algorithm limited to 5 seconds)

< Game4InLine.py >
    Game logic and A* implementation

< MCTS.py >
    Monte Carlo Tree Search implementation

< play.py >
    Terminal interface to play (and view the AI choices with values for each possible play): (5 options)
        1: Human vs Human | or | Human vs AI (you can choose which AI to face, among A* and MCTS)
        2: A* vs A*
        3: MCTS vs MCTS
        4: A* vs MCTS
        5: MCTS vs A*


🛠️ Installation & Setup

Clone the repository:
git clone https://github.com/joaobaptista30/AI-4_connected.git
cd AI-4_connected

# Install dependencies:
pip install -r requirements.txt

# Run the game with UI:
python Connect-4.py

# Run on terminal to view AI thoughts at each turn:
python play.py

📸 Screenshots

Start Menu
Player vs AI
Player vs Player

About

Made for an IA class regarding search problems applied to games

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Contributors

Languages