Example #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())));
 }
Example #2
0
  @Test(timeout = 1000)
  public void testAvailableMovesAfterMove() {
    BoardWrapper b = new BoardWrapperImpl();

    Coordinates newPos = new CoordinatesImpl(0, BOARD_SIZE - 3);
    assertTrue(b.getPieceAt(newPos) instanceof EmptyCell);
    Piece knight = Piece.createPiece(PieceColor.White, PieceType.Knight);
    b.setPieceAt(newPos, knight);

    Coordinates initPos = new CoordinatesImpl(1, BOARD_SIZE - 1);
    Assert.assertEquals(knight, b.getPieceAt(initPos));
    b.setPieceAt(initPos, EmptyCell.INSTANCE);
    GameUtil.getAvailableMoves(PieceColor.White, b.getInner());
    GameUtil.getAvailableMoves(PieceColor.Black, b.getInner());
  }
Example #3
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));
  }
Example #4
0
 @Test(timeout = 1000)
 public void testGetAvailableMovesInitialPositionBlack() {
   BoardWrapper b = new BoardWrapperImpl();
   List<Move> actual = GameUtil.getAvailableMoves(PieceColor.Black, b.getInner());
   List<Move> expected = new ArrayList<>();
   int row = 1;
   for (int i = 0; i < BOARD_SIZE; i++) {
     CoordinatesImpl initPos = new CoordinatesImpl(i, row);
     expected.add(new RegularMove(initPos, new CoordinatesImpl(i, row + BLACK_DIRECTION)));
     expected.add(new RegularMove(initPos, new CoordinatesImpl(i, row + BLACK_DIRECTION * 2)));
   }
   CoordinatesImpl bishopPos = new CoordinatesImpl(1, 0);
   expected.add(new RegularMove(bishopPos, new CoordinatesImpl(0, 2)));
   expected.add(new RegularMove(bishopPos, new CoordinatesImpl(2, 2)));
   bishopPos = new CoordinatesImpl(BOARD_SIZE - 2, 0);
   expected.add(new RegularMove(bishopPos, new CoordinatesImpl(BOARD_SIZE - 3, 2)));
   expected.add(new RegularMove(bishopPos, new CoordinatesImpl(BOARD_SIZE - 1, 2)));
   Collections.sort(expected);
   Collections.sort(actual);
   assertThat(expected, is(actual));
 }