Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/games/game.cc
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,16 @@ Array<GameStrategy> GameRep::GetStrategies() const
return ret;
}

GameRep::~GameRep()
{
for (auto player : m_players) {
player->Invalidate();
}
for (auto outcome : m_outcomes) {
outcome->Invalidate();
}
}

//------------------------------------------------------------------------
// GameRep: Writing data files
//------------------------------------------------------------------------
Expand Down
4 changes: 3 additions & 1 deletion src/games/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,7 @@ class GameRep : public BaseGameRep {

protected:
std::vector<GamePlayerRep *> m_players;
std::vector<GameOutcomeRep *> m_outcomes;
std::string m_title, m_comment;
unsigned int m_version{0};

Expand All @@ -435,7 +436,8 @@ class GameRep : public BaseGameRep {
/// @name Lifecycle
//@{
/// Clean up the game
~GameRep() override = default;
~GameRep() override;

/// Create a copy of the game, as a new game
virtual Game Copy() const = 0;
//@}
Expand Down
7 changes: 0 additions & 7 deletions src/games/gameagg.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,6 @@ class GameAGGRep : public GameRep {
//@{
/// Constructor
explicit GameAGGRep(std::shared_ptr<agg::AGG>);
/// Destructor
~GameAGGRep() override
{
for (auto player : m_players) {
player->Invalidate();
}
}
/// Create a copy of the game, as a new game
Game Copy() const override;
//@}
Expand Down
14 changes: 0 additions & 14 deletions src/games/gameexpl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,6 @@ namespace Gambit {
// class GameExplicitRep
//========================================================================

//------------------------------------------------------------------------
// GameExplicitRep: Lifecycle
//------------------------------------------------------------------------

GameExplicitRep::~GameExplicitRep()
{
for (auto player : m_players) {
player->Invalidate();
}
for (auto outcome : m_outcomes) {
outcome->Invalidate();
}
}

//------------------------------------------------------------------------
// GameExplicitRep: General data access
//------------------------------------------------------------------------
Expand Down
11 changes: 1 addition & 10 deletions src/games/gameexpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,7 @@ namespace Gambit {
class GameExplicitRep : public GameRep {
template <class T> friend class MixedStrategyProfile;

protected:
Array<GameOutcomeRep *> m_outcomes;

public:
/// @name Lifecycle
//@{
/// Destructor
~GameExplicitRep() override;
//@}

/// @name General data access
//@{
/// Returns the smallest payoff to any player in any outcome of the game
Expand Down Expand Up @@ -69,7 +60,7 @@ class GameExplicitRep : public GameRep {
/// Returns the number of outcomes defined in the game
size_t NumOutcomes() const override { return m_outcomes.size(); }
/// Returns the index'th outcome defined in the game
GameOutcome GetOutcome(int index) const override { return m_outcomes[index]; }
GameOutcome GetOutcome(int index) const override { return m_outcomes.at(index - 1); }
/// Creates a new outcome in the game
GameOutcome NewOutcome() override;

Expand Down
4 changes: 2 additions & 2 deletions src/games/gametable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,10 @@ GameTableRep::GameTableRep(const Array<int> &dim, bool p_sparseOutcomes /* = fal
std::fill(m_results.begin(), m_results.end(), nullptr);
}
else {
m_outcomes = Array<GameOutcomeRep *>(m_results.size());
m_outcomes = std::vector<GameOutcomeRep *>(m_results.size());
std::generate(m_outcomes.begin(), m_outcomes.end(),
[this, outc = 1]() mutable { return new GameOutcomeRep(this, outc++); });
m_results = m_outcomes;
std::copy(m_outcomes.begin(), m_outcomes.end(), m_results.begin());
}
}

Expand Down