示例#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());
  }
示例#2
0
文件: King.java 项目: Janikaka/Chess
 /**
  * Method returns all the squares where this king can move.
  *
  * @param board is the current chess board.
  * @param from where it's now.
  * @return list of squares where this king can move.
  */
 @Override
 public SquareList whereToMove(Board board, Square from) {
   SquareList squares = this.whatThreats(board, from);
   from.setPiece(null);
   board.updateInfo();
   SquareList remove = new SquareList();
   SquareList danger;
   SquareList mySquares;
   if (this.getColor() == 'w') {
     danger = board.getBlackThreats();
     mySquares = board.getWhites();
   } else {
     danger = board.getWhiteThreats();
     mySquares = board.getBlacks();
   }
   removeSquares(squares, danger, mySquares, remove);
   addCastle(board, from, squares);
   from.setPiece(this);
   return squares;
 }