A downloadable game for Windows

Connect4

Connect4 is a standalone implementation of the classic Connect Four game, written in Python using Pygame.

The rules are reassuringly simple: drop discs into a 7-column board and be the first to connect four horizontally, vertically or diagonally. The opposition, unfortunately, does not necessarily share that simplicity.

Play against another human, challenge a traditional lookahead AI, face a reinforcement-learning agent, or simply let the machines fight among themselves while you observe the consequences.


How to Play

Two players take turns dropping discs into the six-by-seven board. A disc falls to the lowest available position in the selected column.

The first player to form an uninterrupted line of four discs wins. Connections may be horizontal, vertical or diagonal.

  • Human vs Human
  • Human vs AI
  • AI vs AI

The Opposition

Connect4 includes two quite different approaches to artificial intelligence.

Lookahead AI

The traditional AI searches possible future moves using the game's compact bitboard representation. Several search depths are available, reaching as far as 13 moves ahead.

Increasing the depth makes the opponent progressively more capable and, as is customary with computers, progressively less concerned with your self-esteem.

PPO Agent

The game also includes PPO_2004, a neural-network agent produced during a much longer experiment with reinforcement learning.

The project originally started with a Python lookahead player created for a Kaggle Connect Four competition. That agent later became a tutor and benchmark for experiments with DQN, AlphaZero-style training and eventually PPO.

The PPO project used supervised pre-training based on approximately 15 million game states before continuing with reinforcement learning.


Analysis

Connect4 is not only intended as a game. It also retains some of the tools developed while experimenting with the different agents.

An analysis panel can be displayed while humans or computer players are playing, making it possible to observe what is happening behind the otherwise rather innocent-looking board.

AI-versus-AI games are also supported, allowing the different approaches to be tested directly against each other.


Under the Hood

  • Written in Python.
  • Custom single-window interface built with Pygame.
  • Standard 6 × 7 Connect Four board.
  • Compact bitboard representation of the game state.
  • Lookahead agents with multiple search depths, up to depth 13.
  • PPO neural-network opponent.
  • Human vs Human, Human vs AI and AI vs AI play.
  • Optional game and AI analysis tools.

The game engine and user interface are deliberately separated from the board logic, allowing the same game implementation to be used for interactive play, AI testing and automated matches.


Download

Connect4 is a standalone Windows game.

Download the ZIP archive, unpack it and run the included executable. No Python installation is required.

Download size: approximately 380 MB.

Source code is also available on GitHub.


Connect Four: proof that seven columns, forty-two spaces and two colours are quite sufficient to make a computer smug.

Download

Download
Connect4_LS-v0.6.0-win64.zip 380 MB

Install instructions

Download and unzip.

Or play the slightly worse web version: Connect-4

Leave a comment

Log in with itch.io to leave a comment.