Skip to content

Commit 5b7788a

Browse files
committed
Convert GamePlayerRep::m_strategies from Array to std::vector
1 parent 53c5e5c commit 5b7788a

6 files changed

Lines changed: 15 additions & 40 deletions

File tree

src/games/game.h

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ class GameStrategyRep : public GameObject {
290290

291291
/// A player in a game
292292
class GamePlayerRep : public GameObject {
293+
friend class GameRep;
293294
friend class GameExplicitRep;
294295
friend class GameTreeRep;
295296
friend class GameTableRep;
@@ -311,7 +312,7 @@ class GamePlayerRep : public GameObject {
311312
int m_number;
312313
std::string m_label;
313314
std::vector<GameInfosetRep *> m_infosets;
314-
Array<GameStrategyRep *> m_strategies;
315+
std::vector<GameStrategyRep *> m_strategies;
315316

316317
GamePlayerRep(GameRep *p_game, int p_id) : m_game(p_game), m_number(p_id) {}
317318
GamePlayerRep(GameRep *p_game, int p_id, int m_strats);
@@ -553,11 +554,21 @@ class GameRep : public BaseGameRep {
553554
/// Remove the strategy from the game
554555
virtual void DeleteStrategy(const GameStrategy &p_strategy) { throw UndefinedException(); }
555556
/// Returns the number of strategy contingencies in the game
556-
virtual int NumStrategyContingencies() const = 0;
557+
int NumStrategyContingencies() const
558+
{
559+
BuildComputedValues();
560+
return std::transform_reduce(m_players.begin(), m_players.end(), 0, std::multiplies<>(),
561+
[](const GamePlayerRep *p) { return p->m_strategies.size(); });
562+
}
557563
/// Returns the total number of actions in the game
558564
virtual int BehavProfileLength() const = 0;
559565
/// Returns the total number of strategies in the game
560-
virtual int MixedProfileLength() const = 0;
566+
int MixedProfileLength() const
567+
{
568+
BuildComputedValues();
569+
return std::transform_reduce(m_players.begin(), m_players.end(), 0, std::plus<>(),
570+
[](const GamePlayerRep *p) { return p->m_strategies.size(); });
571+
}
561572
//@}
562573

563574
virtual PureStrategyProfile NewPureStrategyProfile() const = 0;
@@ -696,7 +707,7 @@ inline size_t GamePlayerRep::NumStrategies() const
696707
inline GameStrategy GamePlayerRep::GetStrategy(int st) const
697708
{
698709
m_game->BuildComputedValues();
699-
return m_strategies[st];
710+
return m_strategies.at(st - 1);
700711
}
701712

702713
//=======================================================================

src/games/gameagg.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ class GameAGGRep : public GameRep {
5252
GameStrategy GetStrategy(int p_index) const override;
5353
/// Returns the total number of actions in the game
5454
int BehavProfileLength() const override { throw UndefinedException(); }
55-
/// Returns the total number of strategies in the game
56-
int MixedProfileLength() const override { return aggPtr->getNumActions(); }
57-
int NumStrategyContingencies() const override { throw UndefinedException(); }
5855
//@}
5956

6057
PureStrategyProfile NewPureStrategyProfile() const override;

src/games/gamebagg.cc

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -242,15 +242,6 @@ Array<int> GameBAGGRep::NumStrategies() const
242242
return ns;
243243
}
244244

245-
int GameBAGGRep::MixedProfileLength() const
246-
{
247-
int res = 0;
248-
for (const auto &player : m_players) {
249-
res += player->m_strategies.size();
250-
}
251-
return res;
252-
}
253-
254245
PureStrategyProfile GameBAGGRep::NewPureStrategyProfile() const
255246
{
256247
return PureStrategyProfile(

src/games/gamebagg.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,8 @@ class GameBAGGRep : public GameRep {
5757
Array<int> NumStrategies() const override;
5858
/// Gets the i'th strategy in the game, numbered globally
5959
GameStrategy GetStrategy(int p_index) const override { throw UndefinedException(); }
60-
/// Returns the number of strategy contingencies in the game
61-
int NumStrategyContingencies() const override { throw UndefinedException(); }
6260
/// Returns the total number of actions in the game
6361
int BehavProfileLength() const override { throw UndefinedException(); }
64-
/// Returns the total number of strategies in the game
65-
int MixedProfileLength() const override;
6662
//@}
6763

6864
PureStrategyProfile NewPureStrategyProfile() const override;

src/games/gameexpl.cc

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -102,22 +102,6 @@ GameStrategy GameExplicitRep::GetStrategy(int p_index) const
102102
throw IndexException();
103103
}
104104

105-
int GameExplicitRep::NumStrategyContingencies() const
106-
{
107-
BuildComputedValues();
108-
return std::accumulate(
109-
m_players.begin(), m_players.end(), 1,
110-
[](int ncont, const GamePlayerRep *p) { return ncont * p->m_strategies.size(); });
111-
}
112-
113-
int GameExplicitRep::MixedProfileLength() const
114-
{
115-
BuildComputedValues();
116-
return std::accumulate(
117-
m_players.begin(), m_players.end(), 0,
118-
[](int size, const GamePlayerRep *p) { return size + p->m_strategies.size(); });
119-
}
120-
121105
//------------------------------------------------------------------------
122106
// GameExplicitRep: Outcomes
123107
//------------------------------------------------------------------------

src/games/gameexpl.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@ class GameExplicitRep : public GameRep {
4949
Array<int> NumStrategies() const override;
5050
/// Gets the i'th strategy in the game, numbered globally
5151
GameStrategy GetStrategy(int p_index) const override;
52-
/// Returns the number of strategy contingencies in the game
53-
int NumStrategyContingencies() const override;
54-
/// Returns the total number of strategies in the game
55-
int MixedProfileLength() const override;
5652
//@}
5753

5854
/// @name Outcomes

0 commit comments

Comments
 (0)