@@ -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 ();
@@ -155,8 +155,9 @@ GameInfosetRep::GameInfosetRep(GameRep *p_efg, int p_number, GamePlayerRep *p_pl
155155 int p_actions)
156156 : m_game(p_efg), m_number(p_number), m_player(p_player), m_actions(p_actions)
157157{
158- std::generate (m_actions.begin (), m_actions.end (),
159- [this , i = 1 ]() mutable { return new GameActionRep (i++, " " , this ); });
158+ std::generate (m_actions.begin (), m_actions.end (), [this , i = 1 ]() mutable {
159+ return std::make_shared<GameActionRep>(i++, " " , this );
160+ });
160161 if (p_player->IsChance ()) {
161162 m_probs = Array<Number>(m_actions.size ());
162163 std::fill (m_probs.begin (), m_probs.end (), Rational (1 , m_actions.size ()));
@@ -166,7 +167,8 @@ GameInfosetRep::GameInfosetRep(GameRep *p_efg, int p_number, GamePlayerRep *p_pl
166167
167168GameInfosetRep::~GameInfosetRep ()
168169{
169- std::for_each (m_actions.begin (), m_actions.end (), [](GameActionRep *a) { a->Invalidate (); });
170+ std::for_each (m_actions.begin (), m_actions.end (),
171+ [](std::shared_ptr<GameActionRep> a) { a->Invalidate (); });
170172}
171173
172174Game GameInfosetRep::GetGame () const { return m_game; }
@@ -225,11 +227,11 @@ GameAction GameTreeRep::InsertAction(GameInfoset p_infoset, GameAction p_action
225227 IncrementVersion ();
226228 int where = p_infoset->m_actions .size () + 1 ;
227229 if (p_action) {
228- for (where = 1 ; p_infoset->m_actions [where] != p_action ; where++)
230+ for (where = 1 ; p_action != p_infoset->m_actions [where]; where++)
229231 ;
230232 }
231233
232- auto * action = new GameActionRep (where, " " , p_infoset);
234+ auto action = std::make_shared< GameActionRep> (where, " " , p_infoset);
233235 p_infoset->m_actions .insert (std::next (p_infoset->m_actions .cbegin (), where - 1 ), action);
234236 if (p_infoset->m_player ->IsChance ()) {
235237 p_infoset->m_probs .insert (std::next (p_infoset->m_probs .cbegin (), where - 1 ), Number ());
@@ -627,7 +629,7 @@ GameInfoset GameTreeRep::AppendMove(GameNode p_node, GameInfoset p_infoset)
627629 node->m_infoset = p_infoset;
628630 node->m_infoset ->m_members .push_back (node);
629631 std::for_each (node->m_infoset ->m_actions .begin (), node->m_infoset ->m_actions .end (),
630- [this , node](const GameActionRep * ) {
632+ [this , node](std::shared_ptr< GameActionRep> ) {
631633 node->m_children .push_back (new GameNodeRep (this , node));
632634 m_numNodes++;
633635 });
@@ -673,7 +675,8 @@ GameInfoset GameTreeRep::InsertMove(GameNode p_node, GameInfoset p_infoset)
673675 node->m_parent = newNode;
674676 newNode->m_children .push_back (node);
675677 std::for_each (std::next (newNode->m_infoset ->m_actions .begin ()),
676- newNode->m_infoset ->m_actions .end (), [this , newNode](const GameActionRep *) {
678+ newNode->m_infoset ->m_actions .end (),
679+ [this , newNode](std::shared_ptr<GameActionRep>) {
677680 newNode->m_children .push_back (new GameNodeRep (this , newNode));
678681 });
679682
0 commit comments