Requirement 8 – win condition (IV)

The last requirement is the last win condition.

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

We need to perform valid game movements to achieve the condition. In this case, we need to test both diagonals across the board: from top-right to bottom-left and from bottom-right to top-left. The following tests use a list of columns to recreate a full game to reproduce the scenario under test:

@Test public void when4Diagonal1DiscsAreConnectedThenThatPlayerWins() { int[] gameplay = new int[] {1, 2, 2, 3, 4, 3, 3, 4, 4, 5, 4}; for (int column : gameplay) { tested.putDiscInColumn(column); } assertThat(tested.getWinner(), is("R")); } ...

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.