Exemplo n.º 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. */ ;
    }
  }