Board { public List<Position> legalMovesFor(char color) { final ImmutableList.Builder<Position> result = ImmutableList.builder(); for (int iLine = 0; iLine < cells.length; ++iLine) { for (int iColumn = 0; iColumn < cells[iLine].length; ++iColumn) { final Position currentPosition = position(iLine, iColumn); if (isValidPosition(color, currentPosition)) { result.add(currentPosition); } } } return result.build(); } Board(char[]... cells); List<Position> legalMovesFor(char color); static final char _; static final char B; static final char W; }
@Test public void it_selects_the_only_free_position() { assertThat(new Board( l(B, W, W, B), l(W, B, W, W), l(W, W, B, W), l(_, W, W, B)).legalMovesFor(B)) .containsExactly(position(3, 0)); }
@Test public void it_selects_a_different_only_free_position() { assertThat(new Board( l(B, W, W, B), l(W, B, W, W), l(_, W, B, W), l(W, W, W, B)).legalMovesFor(B)) .containsExactly(position(2, 0)); }
@Test public void it_selects_two_different_positions() { assertThat(new Board( l(B, W, W, B), l(W, B, W, W), l(_, W, B, W), l(_, W, W, B)).legalMovesFor(B)) .containsExactly(position(2, 0), position(3, 0)); }
@Test public void it_has_just_one_illegal_position() { assertThat(new Board( l(B, B, B, B), l(B, B, B, B), l(B, _, B, B), l(B, B, B, B)).legalMovesFor(B)) .isEmpty(); }
@Test public void it_has_just_one_illegal_position_2() { assertThat(new Board( l(B, B, B, B), l(B, B, B, B), l(B, _, B, B), l(B, B, B, B)).legalMovesFor(W)) .isEmpty(); }