Exemplo n.º 1
0
  @Test
  public void threatTest() {
    Square square = this.board.getSquare('e', 1);
    square.setPiece(wPawn);
    SquareList squares = square.getPiece().whatThreats(board, square);
    SquareList list = new SquareList();
    list.add(this.board.getSquare('d', 2));
    list.add(this.board.getSquare('f', 2));
    boolean ok = true;
    for (Square sqr : list.getList()) {
      if (!squares.contains(sqr)) {
        ok = false;
      }
    }
    assertEquals(true, squares.size() == list.size());

    square = this.board.getSquare('e', 8);
    square.setPiece(bPawn);
    squares = square.getPiece().whatThreats(board, square);
    list = new SquareList();
    list.add(this.board.getSquare('d', 7));
    list.add(this.board.getSquare('f', 7));
    for (Square sqr : list.getList()) {
      if (!squares.contains(sqr)) {
        ok = false;
      }
    }
    assertEquals(true, ok);
    assertEquals(true, squares.size() == list.size());
  }
Exemplo n.º 2
0
 /**
  * Method adds squares where to castle
  *
  * @param board current chess board
  * @param from current square
  * @param squares
  */
 private void addCastle(Board board, Square from, SquareList squares) {
   if (this.notMoved() && board.checkThreats(this.getColor())) {
     if (checkShort(board, from)) {
       squares.add(board.getSquare('g', from.getN()));
     }
     if (checkLong(board, from)) {
       squares.add(board.getSquare('c', from.getN()));
     }
   }
 }
Exemplo n.º 3
0
 /**
  * Method removes squares where this king can't move.
  *
  * @param squares squares what king threats
  * @param danger squares where king can't move
  * @param mySquares
  * @param remove squares that needs to remove
  */
 private void removeSquares(
     SquareList squares, SquareList danger, SquareList mySquares, SquareList remove) {
   for (Square square : squares.getList()) {
     if (danger.contains(square) || mySquares.contains(square)) {
       remove.add(square);
     }
   }
   for (Square square : remove.getList()) {
     squares.remove(square);
   }
 }