diff --git a/src/games/game.cc b/src/games/game.cc index 3a9c7d941..601130d14 100644 --- a/src/games/game.cc +++ b/src/games/game.cc @@ -21,6 +21,7 @@ // #include +#include #include "gambit.h" #include "gametree.h" @@ -568,21 +569,19 @@ GameStrategy GameExplicitRep::GetStrategy(int p_index) const int GameExplicitRep::NumStrategyContingencies() const { const_cast(this)->BuildComputedValues(); - int ncont = 1; - for (auto player : m_players) { - ncont *= player->m_strategies.size(); - } - return ncont; + return std::accumulate( + m_players.begin(), m_players.end(), 1, + [](int ncont, GamePlayerRep *p) { return ncont * p->m_strategies.size(); } + ); } int GameExplicitRep::MixedProfileLength() const { const_cast(this)->BuildComputedValues(); - int strats = 0; - for (auto player : m_players) { - strats += player->m_strategies.size(); - } - return strats; + return std::accumulate( + m_players.begin(), m_players.end(), 0, + [](int size, GamePlayerRep *p) { return size + p->m_strategies.size(); } + ); } diff --git a/src/games/gametree.h b/src/games/gametree.h index 3eba4642c..af0075396 100644 --- a/src/games/gametree.h +++ b/src/games/gametree.h @@ -101,7 +101,7 @@ class GameTreeInfosetRep : public GameInfosetRep { /// @name Actions //@{ /// Returns the number of actions available at the information set - int NumActions() const override { return m_actions.Length(); } + int NumActions() const override { return m_actions.size(); } /// Returns the p_index'th action at the information set GameAction GetAction(int p_index) const override { return m_actions[p_index]; } /// Returns a forward iterator over the available actions @@ -109,7 +109,7 @@ class GameTreeInfosetRep : public GameInfosetRep { // { return GameActionIterator(m_actions); } //@} - int NumMembers() const override { return m_members.Length(); } + int NumMembers() const override { return m_members.size(); } GameNode GetMember(int p_index) const override; bool Precedes(GameNode) const override; @@ -160,13 +160,13 @@ class GameTreeNodeRep : public GameNodeRep { int NumberInInfoset() const override { return infoset->m_members.Find(const_cast(this)); } - int NumChildren() const override { return children.Length(); } + int NumChildren() const override { return children.size(); } GameInfoset GetInfoset() const override { return infoset; } void SetInfoset(GameInfoset) override; GameInfoset LeaveInfoset() override; - bool IsTerminal() const override { return (children.Length() == 0); } + bool IsTerminal() const override { return children.empty(); } GamePlayer GetPlayer() const override { return (infoset) ? infoset->GetPlayer() : nullptr; } GameAction GetPriorAction() const override; // returns null if root node diff --git a/src/games/mixed.h b/src/games/mixed.h index 433e2871d..520db1ae2 100644 --- a/src/games/mixed.h +++ b/src/games/mixed.h @@ -220,7 +220,7 @@ template class MixedStrategyProfile { void Randomize(int p_denom) { m_rep->Randomize(p_denom); } /// Returns the total number of strategies in the profile - int MixedProfileLength() const { return m_rep->m_probs.Length(); } + int MixedProfileLength() const { return m_rep->m_probs.size(); } /// Converts the profile to one on the full support of the game MixedStrategyProfile ToFullSupport() const;