Exemple #1
0
  public boolean isLegal(Position position, Move move) {
    final HashSet<MoveVector> possibleVectors = getPossibleVectors();
    final MoveVector moveVector = new MoveVector(move);
    final Square s1 = move.getStartSquare();
    final Square s2 = move.getEndSquare();
    final PieceType pieceType = position.getPieceAt(move.getStartSquare()).getType();

    if (pieceType.equals(PieceType.PAWN)) {
      return false;
    }
    if (!position.isMovablePieceAtSquare(s1)) {
      return false;
    }
    if (position.isCaptureOfOwnColor(move)) {
      return false;
    }
    if (!move.getPromotionPieceType().equals(PieceType.NONE)) {
      return false;
    }
    if (!possibleVectors.contains(moveVector)) {
      return false;
    }

    if (!possibleVectors.contains(moveVector)) {
      return false;
    }

    for (final Square square : Chess.getSquaresBetween(s1, s2, false)) {
      if (!position.getPieceAt(square).equals(Piece.NONE)) {
        return false;
      }
    }
    return true;
  }
Exemple #2
0
  /** Determines whether a particular square is attacked by a piece of the given color. */
  public boolean isAttackedByColor(Square target, PieceColor color) {
    MoveLogic simpleChessLogic = new SimpleChessLogic();
    Position modPosition;

    if (this.getPieceAt(target).getColor().invert() != color) {
      return false;
    }

    if (this.getColorToMove() != color) {
      modPosition = new Position(this);
      modPosition.setColorToMove(color);
    } else {
      modPosition = this;
    }

    for (int i = 0; i < Chess.BOARD_SIZE; i++) {
      for (int j = 0; j < Chess.BOARD_SIZE; j++) {
        final Square source = new Square(i, j);
        final Move move = new Move(source, target);
        if (simpleChessLogic.isLegal(this, move)) {
          return true;
        }
      }
    }

    return false;
  }
Exemple #3
0
 public boolean apply(Position position, Move move) {
   position.movePiece(move);
   position.updateCastlingRights(move);
   position.updateBackgroundInfo(position.isCapture(move));
   return true;
 }
Exemple #4
0
  /**
   * Determines whether the king with the move is currently attacked by a piece of the opposite
   * color.
   */
  public boolean isKingToMoveInCheck() {
    Position opponentToMovePosition = new Position(this);
    opponentToMovePosition.setColorToMove(this.getColorToMove().invert());

    return opponentToMovePosition.isKingLeftInCheck();
  }