diff --git a/src/games/game.h b/src/games/game.h index d9d567585..5b0fc8fbb 100644 --- a/src/games/game.h +++ b/src/games/game.h @@ -184,10 +184,10 @@ class GameInfosetRep : public GameObject { int m_number; std::string m_label; GamePlayerRep *m_player; - Array m_actions; + std::vector m_actions; std::vector m_members; int flag{0}, whichbranch{0}; - Array m_probs; + std::vector m_probs; GameInfosetRep(GameRep *p_efg, int p_number, GamePlayerRep *p_player, int p_actions); ~GameInfosetRep() override; @@ -214,7 +214,7 @@ class GameInfosetRep : public GameObject { /// Returns the number of actions available at the information set size_t NumActions() const { return m_actions.size(); } /// Returns the p_index'th action at the information set - GameAction GetAction(int p_index) const { return m_actions[p_index]; } + GameAction GetAction(int p_index) const { return m_actions.at(p_index - 1); } /// Returns the actions available at the information set Array GetActions() const; //@} @@ -230,7 +230,7 @@ class GameInfosetRep : public GameObject { if (p_action->GetInfoset() != GameInfoset(const_cast(this))) { throw MismatchException(); } - return m_probs[p_action->GetNumber()]; + return m_probs.at(p_action->GetNumber() - 1); } }; diff --git a/src/games/gametree.cc b/src/games/gametree.cc index 4cc8f2764..711195609 100644 --- a/src/games/gametree.cc +++ b/src/games/gametree.cc @@ -124,23 +124,22 @@ void GameTreeRep::DeleteAction(GameAction p_action) } IncrementVersion(); - size_t where; - for (where = 1; where <= infoset->m_actions.size() && infoset->m_actions[where] != action; - where++) - ; - infoset->m_actions[where]->Invalidate(); - erase_atindex(infoset->m_actions, where); + auto where = std::find(infoset->m_actions.begin(), infoset->m_actions.end(), action); + auto offset = where - infoset->m_actions.begin(); + (*where)->Invalidate(); + infoset->m_actions.erase(where); if (infoset->m_player->IsChance()) { - erase_atindex(infoset->m_probs, where); + infoset->m_probs.erase(std::next(infoset->m_probs.begin(), offset)); NormalizeChanceProbs(infoset); } infoset->RenumberActions(); for (auto member : infoset->m_members) { - DeleteTree(member->m_children[where - 1]); + auto it = std::next(member->m_children.begin(), offset); + DeleteTree(*it); m_numNodes--; - member->m_children[where - 1]->Invalidate(); - member->m_children.erase(std::next(member->m_children.begin(), where - 1)); + (*it)->Invalidate(); + member->m_children.erase(it); } ClearComputedValues(); Canonicalize(); @@ -159,7 +158,7 @@ GameInfosetRep::GameInfosetRep(GameRep *p_efg, int p_number, GamePlayerRep *p_pl std::generate(m_actions.begin(), m_actions.end(), [this, i = 1]() mutable { return new GameActionRep(i++, "", this); }); if (p_player->IsChance()) { - m_probs = Array(m_actions.size()); + m_probs = std::vector(m_actions.size()); std::fill(m_probs.begin(), m_probs.end(), Rational(1, m_actions.size())); } m_player->m_infosets.push_back(this); @@ -224,20 +223,17 @@ GameAction GameTreeRep::InsertAction(GameInfoset p_infoset, GameAction p_action } IncrementVersion(); - int where = p_infoset->m_actions.size() + 1; - if (p_action) { - for (where = 1; p_infoset->m_actions[where] != p_action; where++) - ; - } + auto where = std::find(p_infoset->m_actions.begin(), p_infoset->m_actions.end(), p_action); + auto offset = where - p_infoset->m_actions.begin(); - auto *action = new GameActionRep(where, "", p_infoset); - p_infoset->m_actions.insert(std::next(p_infoset->m_actions.cbegin(), where - 1), action); + auto *action = new GameActionRep(offset + 1, "", p_infoset); + p_infoset->m_actions.insert(where, action); if (p_infoset->m_player->IsChance()) { - p_infoset->m_probs.insert(std::next(p_infoset->m_probs.cbegin(), where - 1), Number()); + p_infoset->m_probs.insert(std::next(p_infoset->m_probs.cbegin(), offset), Number()); } p_infoset->RenumberActions(); for (const auto &member : p_infoset->m_members) { - member->m_children.insert(std::next(member->m_children.cbegin(), where - 1), + member->m_children.insert(std::next(member->m_children.cbegin(), offset), new GameNodeRep(this, member)); }