void State::buildTree()

in simple_game/search.cc [133:178]


void State::buildTree(std::shared_ptr<State> own,
                      Manager& manager,
                      const rela::Env& g,
                      bool keepEnvInState) {
  if (manager.getOptions().verbose == VERBOSE) {
    std::cout << "State: " << g.info() << std::endl;
  }

  options_ = manager.getOptions();

  auto spec = g.spec();
  int numPlayer = spec.players.size();

  info_ = manager.getInfoSet(g);
  info_->setDepth(depth_);
  info_->addState(own);
  manager.addState(own);

  if (keepEnvInState) {
    env_ = g.clone();
  }

  u_.resize(numPlayer, 0);
  if (g.terminated()) {
    for (int i = 0; i < numPlayer; ++i) {
      u_[i] = g.playerReward(i);
    }
    return;
  }

  legalActions_ = g.legalActions();
  int numAction = (int)legalActions_.size();

  for (int i = 0; i < numAction; ++i) {
    std::unique_ptr<rela::Env> g_next = g.clone();
    assert(g_next != nullptr);
    g_next->step(legalActions_[i].first);

    children_.emplace_back(
        std::make_shared<State>(depth_ + 1, g_next->completeCompactDesc()));
    children_[i]->buildTree(children_[i], manager, *g_next, keepEnvInState);
    children_[i]->parent_ = own;
    children_[i]->parentActionIdx_ = i;
    info_->addDownStream(i, children_[i]->info_);
  }
}