Example #1
0
  // 評価関数
  Value evaluate(const Position& pos)
  {
    // 差分計算
    auto score = calc_diff_kpp(pos) + pos.state()->materialValue;

    // 非差分計算
//    auto score = compute_eval(pos) + pos.state()->materialValue;

    ASSERT_LV5(pos.state()->materialValue == Eval::material(pos));

    // 差分計算と非差分計算との計算結果が合致するかのテスト。(さすがに重いのでコメントアウトしておく)
    //    ASSERT_LV5(score == compute_eval(pos) + pos.state()->materialValue);

    return pos.side_to_move() == BLACK ? score : -score;
  }
Example #2
0
// 評価関数
Value evaluate(const Position& pos) {
  const auto& accumulator = pos.state()->accumulator;
  if (accumulator.computed_score) {
    return accumulator.score;
  }

#if defined(USE_GLOBAL_OPTIONS)
  // GlobalOptionsでeval hashを用いない設定になっているなら
  // eval hashへの照会をskipする。
  if (!GlobalOptions.use_eval_hash) {
    ASSERT_LV5(pos.state()->materialValue == Eval::material(pos));
    return NNUE::ComputeScore(pos);
  }
#endif

#if defined(USE_EVAL_HASH)
  // evaluate hash tableにはあるかも。
  const Key key = pos.state()->key();
  ScoreKeyValue entry = *g_evalTable[key];
  entry.decode();
  if (entry.key == key) {
    // あった!
    return Value(entry.score);
  }
#endif

  Value score = NNUE::ComputeScore(pos);
#if defined(USE_EVAL_HASH)
  // せっかく計算したのでevaluate hash tableに保存しておく。
  entry.key = key;
  entry.score = score;
  entry.encode();
  *g_evalTable[key] = entry;
#endif

  return score;
}