예제 #1
0
  static GenericBoard toGenericBoard(Position position) {
    GenericBoard genericBoard = new GenericBoard();

    // Set board
    for (int square : Square.values) {
      if (position.board[square] != NOPIECE) {
        genericBoard.setPiece(fromPiece(position.board[square]), fromSquare(square));
      }
    }

    // Set castling
    if ((position.castlingRights & WHITE_KINGSIDE) != NOCASTLING) {
      genericBoard.setCastling(fromColor(WHITE), fromCastlingType(KINGSIDE), fromFile(h));
    }
    if ((position.castlingRights & WHITE_QUEENSIDE) != NOCASTLING) {
      genericBoard.setCastling(fromColor(WHITE), fromCastlingType(QUEENSIDE), fromFile(a));
    }
    if ((position.castlingRights & BLACK_KINGSIDE) != NOCASTLING) {
      genericBoard.setCastling(fromColor(BLACK), fromCastlingType(KINGSIDE), fromFile(h));
    }
    if ((position.castlingRights & BLACK_QUEENSIDE) != NOCASTLING) {
      genericBoard.setCastling(fromColor(BLACK), fromCastlingType(QUEENSIDE), fromFile(a));
    }

    // Set en passant
    if (position.enPassantSquare != NOSQUARE) {
      genericBoard.setEnPassant(fromSquare(position.enPassantSquare));
    }

    // Set active color
    genericBoard.setActiveColor(fromColor(position.activeColor));

    // Set half move clock
    genericBoard.setHalfMoveClock(position.halfmoveClock);

    // Set full move number
    genericBoard.setFullMoveNumber(position.getFullmoveNumber());

    return genericBoard;
  }
예제 #2
0
  static Position toPosition(@NotNull GenericBoard genericBoard) {
    Position newPosition = new Position();

    // Initialize board
    for (int square : Square.values) {
      GenericPiece genericPiece = genericBoard.getPiece(fromSquare(square));
      if (genericPiece != null) {
        int piece = toPiece(genericPiece);
        newPosition.put(piece, square);
      }
    }

    // Initialize active color
    newPosition.setActiveColor(toColor(genericBoard.getActiveColor()));

    // Initialize castling
    for (int color : Color.values) {
      for (int castlingtype : CastlingType.values) {
        GenericFile genericFile =
            genericBoard.getCastling(fromColor(color), fromCastlingType(castlingtype));
        if (genericFile != null) {
          newPosition.setCastlingRight(Castling.valueOf(color, castlingtype));
        }
      }
    }

    // Initialize en passant
    if (genericBoard.getEnPassant() != null) {
      newPosition.setEnPassantSquare(toSquare(genericBoard.getEnPassant()));
    }

    // Initialize half move clock
    newPosition.setHalfmoveClock(genericBoard.getHalfMoveClock());

    // Initialize the full move number
    newPosition.setFullmoveNumber(genericBoard.getFullMoveNumber());

    return newPosition;
  }