Exemplo n.º 1
0
 @Test
 public void testPawnNonEmptyCell() {
   BoardWrapper b = new BoardWrapperImpl();
   CoordinatesImpl blackLoc = new CoordinatesImpl(3, 3);
   CoordinatesImpl whiteLoc = new CoordinatesImpl(3, 4);
   b.setPieceAt(blackLoc, Piece.createPiece(PieceColor.Black, PieceType.Pawn));
   b.setPieceAt(whiteLoc, Piece.createPiece(PieceColor.White, PieceType.Pawn));
   assertThat(new HashSet<>(), is(GameUtil.getAvailableMovesForPiece(whiteLoc, b.getInner())));
   assertThat(new HashSet<>(), is(GameUtil.getAvailableMovesForPiece(blackLoc, b.getInner())));
 }
Exemplo n.º 2
0
  @Test
  public void testCastling() {
    BoardWrapper b = new BoardWrapperImpl();
    List<Coordinates> blackKings =
        GameUtil.findPiecesByTypeAndColor(PieceType.King, PieceColor.Black, b.getInner());
    assertTrue(blackKings.size() == 1);
    Coordinates kingPos = blackKings.get(0);

    assertThat(GameUtil.getAvailableMovesForPiece(kingPos, b.getInner()), is(new HashSet<>()));
    b.setPieceAt(new CoordinatesImpl(BOARD_SIZE - 2, 0), EmptyCell.INSTANCE);
    b.setPieceAt(new CoordinatesImpl(BOARD_SIZE - 3, 0), EmptyCell.INSTANCE);
    LinkedList<Move> expected = new LinkedList<>();
    CoordinatesImpl rookInitPos = new CoordinatesImpl(BOARD_SIZE - 1, 0);
    assertTrue(b.getPieceAt(rookInitPos).getType() == PieceType.Rook);
    CoordinatesImpl rookNewPos = new CoordinatesImpl(BOARD_SIZE - 3, 0);
    expected.add(
        new Castling(kingPos, new CoordinatesImpl(BOARD_SIZE - 2, 0), rookInitPos, rookNewPos));
    expected.add(new RegularMove(kingPos, new CoordinatesImpl(BOARD_SIZE - 3, 0)));
    LinkedList<Move> actual =
        new LinkedList<>(GameUtil.getAvailableMovesForPiece(kingPos, b.getInner()));
    Collections.sort(actual);
    Collections.sort(expected);
    assertThat(actual, is(expected));
  }