Skip to content

About

An interactive, search-driven Connect Four game engine and simulator powered by adversarial AI agents. CP468 Artificial Intelligence - Wilfrid Laurier University

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

ConnectFourAI

Cover

Live Sandbox Demo Video Report PDF Evaluation Markdown Evaluation JSON

Connect Four is played on a 7 × 6 board (7 columns, 6 rows). Two players alternately drop a disc into one of the seven columns; a disc falls to the lowest empty cell of that column. The first player to connect four consecutive discs horizontally, vertically, or diagonally wins. If the board fills with no winner, the game is a draw.

This repository contains a modular Python implementation of a Connect Four game engine and a suite of seedable AI agents, alongside a responsive full-stack Web GUI sandbox for live agent evaluations.


🚀 Quick Start

1. Run Automated Unit Tests

To verify core engine correctness, win/draw state transitions, and agent decision logic:

python3 -m unittest discover -s tests

2. Play Game (Interactive CLI)

Run the main script to play against the AI agents or local players:

  • Player vs Player (Local):
    python3 main.py --mode player-vs-player
  • Player vs Random AI:
    python3 main.py --mode player-vs-random
  • Player vs Rule-Based AI:
    python3 main.py --mode player-vs-rulebased
  • Player vs Minimax AI:
    python3 main.py --mode player-vs-minimax

3. Simulate Game (AI vs AI)

To simulate games between agents with a deterministic seed for evaluation:

python3 main.py --mode minimax-vs-random --seed 42 --delay 0.5

📂 Project Navigation & Deliverables

Deliverable / Asset Location / Link Description
Live Hosted Sandbox GitHub Pages Deployment Interactive full-stack web GUI for real-time play and evaluation
Demonstration Video Google Drive Walkthrough Walkthrough demonstrating CLI runs, unit tests, and agent gameplay
Project Report assets/report.pdf Algorithm designs, evaluations, and analysis
Evaluation Data evaluation_results.md · evaluation_results.json Compiled pairing metrics, win rates, and step logs
Test Suite tests/test_engine.py · tests/test_agents.py Unit tests verifying core game rules and agent behaviors

Core Source Code Map


🛠️ Technical Requirements

Requirement 1: Game Engine

  • Implementation File: ConnectFourAI/engine.py
  • Details:
    • Board Representation: 6 rows × 7 columns grid (0 = empty, 1 = Player 1, 2 = Player 2).
    • Gravity Simulation: Disc placement slides to the lowest empty index of the column.
    • API Features: Out-of-bounds validation, legal moves generator, deep cloning for forecasting, and win scanners in all 4 planes.

Requirement 2: AI Agents

Requirement 3: Experimental Evaluation

Case Study A - Random vs Rule-Based

Agent Wins Win Rate Draws Avg Decision Time
Random 1/30 3.33% 0 0.0012 ms
Rule-Based 29/30 96.67% 0 0.2555 ms

Case Study B - Rule-Based vs Minimax

Agent Wins Win Rate Draws Avg Decision Time
Rule-Based 3/30 10.00% 1 0.2719 ms
Minimax (depth 4) 26/30 86.67% 1 33.4204 ms

Case Study C - Minimax vs Random

Agent Wins Win Rate Draws Avg Decision Time
Minimax (depth 4) 30/30 100.00% 0 42.5260 ms
Random 0/30 0.00% 0 0.0021 ms

Requirement 4: Report

Requirement 5: Demonstration Video


🔬 Deterministic Seeding & Test Environment Control

Computers rely on Pseudo-Random Number Generators (PRNGs) which are mathematical algorithms (e.g., Python's Mersenne Twister or JavaScript's Linear Congruential Generator) that compute sequences of numbers starting from an initial integer called a seed. Because these algorithms are fully deterministic, using the same seed ensures the exact same sequence of choices is generated every time.

About

An interactive, search-driven Connect Four game engine and simulator powered by adversarial AI agents. CP468 Artificial Intelligence - Wilfrid Laurier University

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages