@@ -54,7 +54,7 @@ class GameNodeRep;
5454using GameNode = GameObjectPtr<GameNodeRep>;
5555
5656class GameRep ;
57- using Game = GameObjectPtr <GameRep>;
57+ using Game = std::shared_ptr <GameRep>;
5858
5959template <class P , class T > class ElementCollection {
6060 P m_owner{nullptr };
@@ -488,7 +488,7 @@ class GameNodeRep : public GameObject {
488488};
489489
490490// / This is the class for representing an arbitrary finite game.
491- class GameRep : public BaseGameRep {
491+ class GameRep : public std ::enable_shared_from_this<GameRep> {
492492 friend class GameOutcomeRep ;
493493 friend class GameNodeRep ;
494494 friend class PureStrategyProfileRep ;
@@ -536,7 +536,8 @@ class GameRep : public BaseGameRep {
536536
537537 iterator () = default ;
538538
539- iterator (const Game &game, const GameNode &start_node) : m_owner(game), m_current_node(start_node)
539+ iterator (const Game &game, const GameNode &start_node)
540+ : m_owner(game), m_current_node(start_node)
540541 {
541542 if (!start_node) {
542543 return ;
@@ -600,7 +601,7 @@ class GameRep : public BaseGameRep {
600601 // / @name Lifecycle
601602 // @{
602603 // / Clean up the game
603- ~GameRep () override ;
604+ virtual ~GameRep ();
604605
605606 // / Create a copy of the game, as a new game
606607 virtual Game Copy () const = 0;
@@ -778,7 +779,10 @@ class GameRep : public BaseGameRep {
778779 // / Returns the pl'th player in the game
779780 GamePlayer GetPlayer (int pl) const { return m_players.at (pl - 1 ); }
780781 // / Returns the set of players in the game
781- Players GetPlayers () const { return Players (this , &m_players); }
782+ Players GetPlayers () const
783+ {
784+ return Players (std::const_pointer_cast<GameRep>(shared_from_this ()), &m_players);
785+ }
782786 // / Returns the chance (nature) player
783787 virtual GamePlayer GetChance () const = 0;
784788 // / Creates a new player in the game, with no moves
@@ -798,7 +802,10 @@ class GameRep : public BaseGameRep {
798802 // / Returns the index'th outcome defined in the game
799803 GameOutcome GetOutcome (int index) const { return m_outcomes.at (index - 1 ); }
800804 // / Returns the set of outcomes in the game
801- Outcomes GetOutcomes () const { return Outcomes (this , &m_outcomes); }
805+ Outcomes GetOutcomes () const
806+ {
807+ return Outcomes (std::const_pointer_cast<GameRep>(shared_from_this ()), &m_outcomes);
808+ }
802809 // / Creates a new outcome in the game
803810 virtual GameOutcome NewOutcome () { throw UndefinedException (); }
804811 // / Deletes the specified outcome from the game
@@ -810,7 +817,7 @@ class GameRep : public BaseGameRep {
810817 // / Returns the root node of the game
811818 virtual GameNode GetRoot () const = 0;
812819 // / Returns a range that can be used to iterate over the nodes of the game
813- Nodes GetNodes () const { return Nodes (this ); }
820+ Nodes GetNodes () const { return Nodes (std::const_pointer_cast<GameRep>( shared_from_this ()) ); }
814821 // / Returns the number of nodes in the game
815822 virtual size_t NumNodes () const = 0;
816823 // / Returns the number of non-terminal nodes in the game
@@ -834,7 +841,7 @@ class GameRep : public BaseGameRep {
834841// These must be postponed to here in the file because they require
835842// all classes to be defined.
836843
837- inline Game GameOutcomeRep::GetGame () const { return m_game; }
844+ inline Game GameOutcomeRep::GetGame () const { return m_game-> shared_from_this () ; }
838845
839846template <class T > const T &GameOutcomeRep::GetPayoff (const GamePlayer &p_player) const
840847{
@@ -867,11 +874,11 @@ inline void GameOutcomeRep::SetPayoff(const GamePlayer &p_player, const Number &
867874
868875inline GamePlayer GameStrategyRep::GetPlayer () const { return m_player; }
869876
870- inline Game GameInfosetRep::GetGame () const { return m_game; }
877+ inline Game GameInfosetRep::GetGame () const { return m_game-> shared_from_this () ; }
871878inline GamePlayer GameInfosetRep::GetPlayer () const { return m_player; }
872879inline bool GameInfosetRep::IsChanceInfoset () const { return m_player->IsChance (); }
873880
874- inline Game GamePlayerRep::GetGame () const { return m_game; }
881+ inline Game GamePlayerRep::GetGame () const { return m_game-> shared_from_this () ; }
875882inline GameStrategy GamePlayerRep::GetStrategy (int st) const
876883{
877884 m_game->BuildComputedValues ();
@@ -883,7 +890,7 @@ inline GamePlayerRep::Strategies GamePlayerRep::GetStrategies() const
883890 return Strategies (this , &m_strategies);
884891}
885892
886- inline Game GameNodeRep::GetGame () const { return m_game; }
893+ inline Game GameNodeRep::GetGame () const { return m_game-> shared_from_this () ; }
887894
888895// =======================================================================
889896
0 commit comments