Requirement 6 – win condition (II)

This is the first win condition requirement for players.

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

In fact, this requires one single check. If the current inserted disc connects other three discs in a vertical line, the current player wins the game:

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

There are a couple of changes to the putDiscInColumn method. Also, a new method called ...

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.