Skip to content

Commit fa6ffd4

Browse files
committed
change m_outcomes from Array to std::vector and move them to GameRep
1 parent 8d1989d commit fa6ffd4

6 files changed

Lines changed: 16 additions & 34 deletions

File tree

src/games/game.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,16 @@ Array<GameStrategy> GameRep::GetStrategies() const
221221
return ret;
222222
}
223223

224+
GameRep::~GameRep()
225+
{
226+
for (auto player : m_players) {
227+
player->Invalidate();
228+
}
229+
for (auto outcome : m_outcomes) {
230+
outcome->Invalidate();
231+
}
232+
}
233+
224234
//------------------------------------------------------------------------
225235
// GameRep: Writing data files
226236
//------------------------------------------------------------------------

src/games/game.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ class GameRep : public BaseGameRep {
420420

421421
protected:
422422
std::vector<GamePlayerRep *> m_players;
423+
std::vector<GameOutcomeRep *> m_outcomes;
423424
std::string m_title, m_comment;
424425
unsigned int m_version{0};
425426

@@ -435,7 +436,8 @@ class GameRep : public BaseGameRep {
435436
/// @name Lifecycle
436437
//@{
437438
/// Clean up the game
438-
~GameRep() override = default;
439+
virtual ~GameRep();
440+
439441
/// Create a copy of the game, as a new game
440442
virtual Game Copy() const = 0;
441443
//@}

src/games/gameagg.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,6 @@ class GameAGGRep : public GameRep {
3939
//@{
4040
/// Constructor
4141
explicit GameAGGRep(std::shared_ptr<agg::AGG>);
42-
/// Destructor
43-
~GameAGGRep() override
44-
{
45-
for (auto player : m_players) {
46-
player->Invalidate();
47-
}
48-
}
4942
/// Create a copy of the game, as a new game
5043
Game Copy() const override;
5144
//@}

src/games/gameexpl.cc

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,6 @@ namespace Gambit {
3232
// class GameExplicitRep
3333
//========================================================================
3434

35-
//------------------------------------------------------------------------
36-
// GameExplicitRep: Lifecycle
37-
//------------------------------------------------------------------------
38-
39-
GameExplicitRep::~GameExplicitRep()
40-
{
41-
for (auto player : m_players) {
42-
player->Invalidate();
43-
}
44-
for (auto outcome : m_outcomes) {
45-
outcome->Invalidate();
46-
}
47-
}
48-
4935
//------------------------------------------------------------------------
5036
// GameExplicitRep: General data access
5137
//------------------------------------------------------------------------

src/games/gameexpl.h

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,7 @@ namespace Gambit {
3030
class GameExplicitRep : public GameRep {
3131
template <class T> friend class MixedStrategyProfile;
3232

33-
protected:
34-
Array<GameOutcomeRep *> m_outcomes;
35-
3633
public:
37-
/// @name Lifecycle
38-
//@{
39-
/// Destructor
40-
~GameExplicitRep() override;
41-
//@}
42-
4334
/// @name General data access
4435
//@{
4536
/// Returns the smallest payoff to any player in any outcome of the game
@@ -69,7 +60,7 @@ class GameExplicitRep : public GameRep {
6960
/// Returns the number of outcomes defined in the game
7061
size_t NumOutcomes() const override { return m_outcomes.size(); }
7162
/// Returns the index'th outcome defined in the game
72-
GameOutcome GetOutcome(int index) const override { return m_outcomes[index]; }
63+
GameOutcome GetOutcome(int index) const override { return m_outcomes.at(index - 1); }
7364
/// Creates a new outcome in the game
7465
GameOutcome NewOutcome() override;
7566

src/games/gametable.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -295,10 +295,10 @@ GameTableRep::GameTableRep(const Array<int> &dim, bool p_sparseOutcomes /* = fal
295295
std::fill(m_results.begin(), m_results.end(), nullptr);
296296
}
297297
else {
298-
m_outcomes = Array<GameOutcomeRep *>(m_results.size());
298+
m_outcomes = std::vector<GameOutcomeRep *>(m_results.size());
299299
std::generate(m_outcomes.begin(), m_outcomes.end(),
300300
[this, outc = 1]() mutable { return new GameOutcomeRep(this, outc++); });
301-
m_results = m_outcomes;
301+
std::copy(m_outcomes.begin(), m_outcomes.end(), m_results.begin());
302302
}
303303
}
304304

0 commit comments

Comments
 (0)