Beispiel #1
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());
  }
Beispiel #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));
  }