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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.