Requirement 7 – win condition (III)

This is the second win condition, which is pretty similar to the previous one.

If a player inserts a disc and connects more than three discs of his color in a straight horizontal line, then that player wins.

This time, we are trying to win the game by inserting discs into adjacent columns:

@Test
public void when4HorizontalDiscsAreConnectedThenPlayerWins() {
  int column;
  for (column = 0; column < 3; column++) {
    tested.putDiscInColumn(column); // R
    tested.putDiscInColumn(column); // G
  }
  assertThat(tested.getWinner(), isEmptyString());
  tested.putDiscInColumn(column); // R
  assertThat(tested.getWinner(), is("R"));
}

The code to pass this test is put into the checkWinners method:

 if (winner.isEmpty()) { String ...

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.