Connect 4 Robot

Introduction

The Connect Four game (a.k.a Four in a Line) (1974) is a traditional board game, in which two players take turn to fill in a 6 x 7 board with Red and Yellow pieces. The winner is the first to create a line of four pieces with the same colour.

Connect 4 Game

In the summer of 2010, I designed and built my computer-based version of the Connect 4 robot, which used a USB Webcam to recognise the Human's move. I implemented the Alpha-Beta pruning algorithm. It took an average of 7 seconds to process the next move.


An Android-based Lego NXT - Connect 4 Robot

Having to carry a laptop around to demonstrate my robot, I decided to make it more portable.

In the winter of 2012, I simplified the Robot hand, and implemented a new threat-finding algorithm based on odd/even rows strategy. A 8-ply database was used to reduce the initial processing time, which helps the Robot play the first 10 opening moves perfectly.

  • Robot hand
  • Game process
Robot hand

Both the external Webcam and the laptop were substituted by a much portable Android mobile phone. With the built-in camera, a photo is taken every 2 seconds to determine the location of the piece. The Robot's next optimal move is calculated locally on the mobile phone, then sent to the Lego Mindstorms brick via Bluetooth. A listener waiting passively on the Lego brick will command the Robot hand to drop a piece when requested.

Game process

The biggest challenge, however, was the lighting condition. The traditional version of the game uses Red and Yellow pieces, which are both very bright colours. However, since the Robot knows its pieces' position, it only looks for any new bright colour on the board, and matches its position to the previous state of the board to find the human move.

Demo

Here is a performance of the new robot.