@@ -102,7 +102,7 @@ bool GameActionRep::Precedes(const GameNode &n) const
102102 GameNode node = n;
103103
104104 while (node != node->GetGame ()->GetRoot ()) {
105- if (node->GetPriorAction () == GameAction ( const_cast <GameActionRep *>( this ) )) {
105+ if (node->GetPriorAction () == shared_from_this ( )) {
106106 return true ;
107107 }
108108 else {
@@ -114,7 +114,7 @@ bool GameActionRep::Precedes(const GameNode &n) const
114114
115115void GameTreeRep::DeleteAction (GameAction p_action)
116116{
117- GameActionRep * action = p_action;
117+ const std::shared_ptr< GameActionRep> action = p_action;
118118 auto *infoset = action->m_infoset ;
119119 if (infoset->m_game != this ) {
120120 throw MismatchException ();
@@ -156,8 +156,9 @@ GameInfosetRep::GameInfosetRep(GameRep *p_efg, int p_number, GamePlayerRep *p_pl
156156 int p_actions)
157157 : m_game(p_efg), m_number(p_number), m_player(p_player), m_actions(p_actions)
158158{
159- std::generate (m_actions.begin (), m_actions.end (),
160- [this , i = 1 ]() mutable { return new GameActionRep (i++, " " , this ); });
159+ std::generate (m_actions.begin (), m_actions.end (), [this , i = 1 ]() mutable {
160+ return std::make_shared<GameActionRep>(i++, " " , this );
161+ });
161162 if (p_player->IsChance ()) {
162163 m_probs = Array<Number>(m_actions.size ());
163164 std::fill (m_probs.begin (), m_probs.end (), Rational (1 , m_actions.size ()));
@@ -167,7 +168,8 @@ GameInfosetRep::GameInfosetRep(GameRep *p_efg, int p_number, GamePlayerRep *p_pl
167168
168169GameInfosetRep::~GameInfosetRep ()
169170{
170- std::for_each (m_actions.begin (), m_actions.end (), [](GameActionRep *a) { a->Invalidate (); });
171+ std::for_each (m_actions.begin (), m_actions.end (),
172+ [](std::shared_ptr<GameActionRep> a) { a->Invalidate (); });
171173}
172174
173175Game GameInfosetRep::GetGame () const { return m_game; }
@@ -226,11 +228,11 @@ GameAction GameTreeRep::InsertAction(GameInfoset p_infoset, GameAction p_action
226228 IncrementVersion ();
227229 int where = p_infoset->m_actions .size () + 1 ;
228230 if (p_action) {
229- for (where = 1 ; p_infoset->m_actions [where] != p_action ; where++)
231+ for (where = 1 ; p_action != p_infoset->m_actions [where]; where++)
230232 ;
231233 }
232234
233- auto * action = new GameActionRep (where, " " , p_infoset);
235+ auto action = std::make_shared< GameActionRep> (where, " " , p_infoset);
234236 p_infoset->m_actions .insert (std::next (p_infoset->m_actions .cbegin (), where - 1 ), action);
235237 if (p_infoset->m_player ->IsChance ()) {
236238 p_infoset->m_probs .insert (std::next (p_infoset->m_probs .cbegin (), where - 1 ), Number ());
@@ -633,7 +635,7 @@ GameInfoset GameTreeRep::AppendMove(GameNode p_node, GameInfoset p_infoset)
633635 node->m_infoset = p_infoset;
634636 node->m_infoset ->m_members .push_back (node);
635637 std::for_each (node->m_infoset ->m_actions .begin (), node->m_infoset ->m_actions .end (),
636- [this , node](const GameActionRep * ) {
638+ [this , node](std::shared_ptr< GameActionRep> ) {
637639 node->m_children .push_back (new GameNodeRep (this , node));
638640 m_numNodes++;
639641 });
@@ -680,7 +682,8 @@ GameInfoset GameTreeRep::InsertMove(GameNode p_node, GameInfoset p_infoset)
680682 node->m_parent = newNode;
681683 newNode->m_children .push_back (node);
682684 std::for_each (std::next (newNode->m_infoset ->m_actions .begin ()),
683- newNode->m_infoset ->m_actions .end (), [this , newNode](const GameActionRep *) {
685+ newNode->m_infoset ->m_actions .end (),
686+ [this , newNode](std::shared_ptr<GameActionRep>) {
684687 newNode->m_children .push_back (new GameNodeRep (this , newNode));
685688 });
686689
0 commit comments