Connect Four Robot

Introduction

Connect Four, introduced in 1974 and also known as Four in a Line, is a classic game in which two players take turns dropping red and yellow pieces into a vertical grid with six rows and seven columns. The first player to form a horizontal, vertical or diagonal line of four pieces of the same colour wins.

Connect Four game

In the summer of 2010, I designed and built a computer-controlled Connect Four robot. It used a USB webcam to recognise the human player's moves and alpha-beta pruning to search for its response. Calculating the next move took an average of seven seconds.


An Android-Controlled LEGO NXT Connect Four Robot

Carrying a laptop to every demonstration prompted me to develop a more portable version.

In the winter of 2012, I simplified the robotic hand and implemented a new algorithm for identifying threats using an odd/even row strategy. An eight-ply database reduced the initial processing time, helping the robot play the first ten opening moves perfectly.

  • Connect Four robot hand
  • Connect Four robot gameplay process
Connect Four robot hand

An Android phone replaced both the laptop and the external webcam. Its built-in camera captured an image every two seconds to locate newly placed pieces. The phone calculated the robot's next move and sent it to the LEGO Mindstorms brick via Bluetooth. A program on the brick listened for incoming commands and instructed the robotic hand to drop a piece into the selected column.

Connect Four robot gameplay process

The main challenge was detecting pieces reliably under different lighting conditions. The standard game uses red and yellow pieces, both of which are brightly coloured. Because the robot already knew the positions of its own pieces, it could identify the human player's move by detecting a new brightly coloured piece and comparing its position with the previous board state.

Demonstration

Watch the redesigned robot in action below.