void SearchBot::filterBeliefsConsistentWithAction_()

in csrc/SearchBot.cc [272:332]


void SearchBot::filterBeliefsConsistentWithAction_(const Move &move, int from, const Server &server) {
  if (from == me_) {
    return;
  }

  {
    // just for logging
    auto cheat_hand = server.cheatGetHand(me_);
    auto cheat_bot = hand_distribution_[cheat_hand].getPartner(from);
    auto cheat_server = SimulServer(server);
    cheat_server.setHand(me_, cheat_hand);
    auto expected_move = cheat_server.simulatePlayerMove(from, cheat_bot->clone());
    std::cerr << "SearchBot expected " << expected_move.toString() << " , observed " << move.toString() << std::endl;
  }

  if (PARTNER_UNIFORM_UNC == 1) {
    return;
  }
  size_t old_size = hand_distribution_.size();
  std::cerr << now() << "filterAction_ with " << old_size << " beliefs." << std::endl;
  auto hand_dist_keys = copyKeys(hand_distribution_);
  applyDelayedObservations(hand_distribution_, hand_dist_keys);
  std::vector<boost::fibers::future<void>> futures;
  for (int t = 0; t < NUM_THREADS; t++) {
    futures.push_back(getThreadPool().enqueue([&, t]() {
      SimulServer simulserver(simulserver_);
      for (int i = t; i < hand_dist_keys.size(); i += NUM_THREADS) {
        auto &hand = hand_dist_keys[i];
        simulserver.setHand(me_, hand);
        auto bot = hand_distribution_[hand].getPartner(from);
        if (PARTNER_BOLTZMANN_UNC > 0) {
          auto action_probs = bot->getActionProbs();
          if (server.cheatGetHand(me_) == hand.get()) {
            for (auto kv : action_probs) std::cerr << "Action " << kv.first << " : " <<kv.second << std::endl;
            std::cerr << "Prob of " << move.toString() << " ( " << moveToIndex(move, server) << ") : " << action_probs[moveToIndex(move, server)] << std::endl;
          }
          hand_distribution_[hand].prob *= (action_probs[moveToIndex(move, server)] + PARTNER_UNIFORM_UNC);
        } else {
          Move cf_move = simulserver.simulatePlayerMove(from, bot.get());

          if (move != cf_move) {
            hand_distribution_[hand].prob *= PARTNER_UNIFORM_UNC;
          }
        }
      }
    }));
  }
  for (auto &f: futures) {
    f.get();
  }
  for (auto &hand: hand_dist_keys) {
    if (hand_distribution_[hand].prob == 0) {
      hand_distribution_.erase(hand);
    }
  }
  std::cerr << now() << "Player " << me_ << ": Filtered beliefs consistent with player " << from << " action '" << move.toString()
            << "' reduced from " << old_size << " to " <<
            hand_distribution_.size() << std::endl;

  checkBeliefs_(server);
}