Example #1
0
  public void set(int flags) {
    if (!ignoreFlags) {
      if (isReversed) flags = EngUtil.reverseFlags(flags);

      //  castling privileges
      if (!EngUtil.canCastle(flags, WHITE_KINGS_CASTLING)) theValue ^= castle_random_w[0];
      if (!EngUtil.canCastle(flags, WHITE_QUEENS_CASTLING)) theValue ^= castle_random_w[1];
      if (!EngUtil.canCastle(flags, BLACK_KINGS_CASTLING)) theValue ^= castle_random_b[0];
      if (!EngUtil.canCastle(flags, BLACK_QUEENS_CASTLING)) theValue ^= castle_random_b[1];

      boolean whiteToMove = (flags & WHITE) != 0;

      //  en-passant target square
      int epFile = EngUtil.enPassantFile(flags);
      if (epFile != 0) {
        int epSquare;
        if (whiteToMove) epSquare = EngUtil.square(epFile, ROW_6);
        else epSquare = EngUtil.square(epFile, ROW_3);
        theValue ^= enpassant_random[square64(epSquare)];
      }

      //  color to move
      if (EngUtil.allOf(flags, WHITE)) theValue ^= wtm_random[0];
      else if (EngUtil.allOf(flags, BLACK)) theValue ^= wtm_random[1];
      else /* this branch is used when computing hash keys for look up in the crafty book.
				    there is no turn color. */ ;
    }
  }
Example #2
0
  public void set(int square, int piece) {
    /*  translate jose square encoding (0..80)
        to crafty square encoding (A1=0, B1=1, .. H8=63)
    */
    if (isReversed) {
      square = EngUtil.mirrorSquare(square);
      piece = EngUtil.oppositeColor(piece);
    }

    square = square64(square);

    switch (piece) {
      case WHITE_PAWN:
        theValue ^= w_pawn_random[square];
        break;
      case BLACK_PAWN:
        theValue ^= b_pawn_random[square];
        break;
      case WHITE_KNIGHT:
        theValue ^= w_knight_random[square];
        break;
      case BLACK_KNIGHT:
        theValue ^= b_knight_random[square];
        break;
      case WHITE_BISHOP:
        theValue ^= w_bishop_random[square];
        break;
      case BLACK_BISHOP:
        theValue ^= b_bishop_random[square];
        break;
      case WHITE_ROOK:
        theValue ^= w_rook_random[square];
        break;
      case BLACK_ROOK:
        theValue ^= b_rook_random[square];
        break;
      case WHITE_QUEEN:
        theValue ^= w_queen_random[square];
        break;
      case BLACK_QUEEN:
        theValue ^= b_queen_random[square];
        break;
      case WHITE_KING:
        theValue ^= w_king_random[square];
        break;
      case BLACK_KING:
        theValue ^= b_king_random[square];
        break;

      default:
        throw new IllegalArgumentException();
    }
  }
Example #3
0
 /*  translate jose square encoding (0..80)
     to crafty square encoding (A1=0, B1=1, .. H8=63)
 */
 private static int square64(int jose_square) {
   int file0 = EngUtil.fileOf(jose_square) - FILE_A;
   int row0 = EngUtil.rowOf(jose_square) - ROW_1;
   return 8 * row0 + file0;
 }