Skip to content

Commit

Permalink
Some STLisation of game representation.
Browse files Browse the repository at this point in the history
  • Loading branch information
tturocy committed Apr 5, 2023
1 parent 0980a9d commit aa2ac0b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
19 changes: 9 additions & 10 deletions src/games/game.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
//

#include <iostream>
#include <numeric>

#include "gambit.h"
#include "gametree.h"
Expand Down Expand Up @@ -568,21 +569,19 @@ GameStrategy GameExplicitRep::GetStrategy(int p_index) const
int GameExplicitRep::NumStrategyContingencies() const
{
const_cast<GameExplicitRep *>(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<GameExplicitRep *>(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(); }
);
}


Expand Down
8 changes: 4 additions & 4 deletions src/games/gametree.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ 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
//virtual GameActionIterator Actions(void) const
// { 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;
Expand Down Expand Up @@ -160,13 +160,13 @@ class GameTreeNodeRep : public GameNodeRep {
int NumberInInfoset() const override
{ return infoset->m_members.Find(const_cast<GameTreeNodeRep *>(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
Expand Down
2 changes: 1 addition & 1 deletion src/games/mixed.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ template <class T> 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<T> ToFullSupport() const;
Expand Down

0 comments on commit aa2ac0b

Please sign in to comment.