Requirement 1 – the game's board

Let us start with the first requirement.

The board is composed of seven horizontal and six vertical empty positions.

The implementation of this requirement is pretty straightforward. We just need the representation of an empty position and the data structure to hold the game. Note that the colors used by the players are also defined:

public class Connect4 {
  public enum Color {
    RED('R'), GREEN('G'), EMPTY(' ');
     private final char value;
     Color(char value) { this.value = value; }
 @Override public String toString() { return String.valueOf(value); } } public static final int COLUMNS = 7; public static final int ROWS = 6; private Color[][] board = new Color[COLUMNS][ROWS]; public Connect4() { for (Color[] column ...

Get Test-Driven Java Development - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.