@@ -209,6 +209,7 @@ class GameInfosetRep : public std::enable_shared_from_this<GameInfosetRep> {
209209 }
210210
211211public:
212+ void DebugSanityCheck () const ;
212213 using Actions = ElementCollection<GameInfoset, GameActionRep>;
213214 using Members = ElementCollection<GameInfoset, GameNodeRep>;
214215
@@ -382,6 +383,15 @@ class GamePlayerRep : public std::enable_shared_from_this<GamePlayerRep> {
382383 std::vector<std::shared_ptr<GameStrategyRep>> m_strategies;
383384
384385public:
386+ void DebugSanityCheck () const
387+ {
388+ if (!m_game) {
389+ throw std::runtime_error (" PlayerRep: m_game is null" );
390+ }
391+ if (!m_valid) {
392+ throw std::runtime_error (" PlayerRep: IsValid() is false" );
393+ }
394+ }
385395 using Infosets = ElementCollection<GamePlayer, GameInfosetRep>;
386396 using Strategies = ElementCollection<GamePlayer, GameStrategyRep>;
387397
@@ -970,6 +980,24 @@ class GameRep : public std::enable_shared_from_this<GameRep> {
970980#undef NDEBUG
971981#include < cassert>
972982
983+ inline void GameInfosetRep::DebugSanityCheck () const
984+ {
985+ if (!m_game) {
986+ throw std::runtime_error (" InfosetRep: m_game is null" );
987+ }
988+ if (!m_player) {
989+ throw std::runtime_error (" InfosetRep: m_player is null" );
990+ }
991+ if (!m_valid) {
992+ throw std::runtime_error (" InfosetRep: IsValid() is false" );
993+ }
994+
995+ // Optional deeper checks:
996+ if (m_player->m_game != m_game) {
997+ throw std::runtime_error (" InfosetRep: player->m_game mismatch" );
998+ }
999+ }
1000+
9731001class GameRep ::Infosets {
9741002public:
9751003 class iterator {
@@ -996,25 +1024,17 @@ class GameRep::Infosets {
9961024
9971025 value_type operator *() const
9981026 {
999- assert (inner_ != inner_end_);
1000- assert (*inner_);
1001- assert ((*inner_)->IsValid ());
1002- assert ((*inner_)->m_game != nullptr );
1003- assert ((*inner_)->m_player != nullptr );
1004-
1027+ (*inner_)->DebugSanityCheck ();
1028+ (*inner_)->GetPlayer ()->DebugSanityCheck ();
10051029 auto g = (*inner_)->GetGame ();
10061030 assert (g); // i.e. g != nullptr
10071031 return GameInfoset (*inner_); // GameObjectPtr constructor
10081032 }
10091033
10101034 value_type operator ->() const
10111035 {
1012- assert (inner_ != inner_end_);
1013- assert (*inner_);
1014- assert ((*inner_)->IsValid ());
1015- assert ((*inner_)->m_game != nullptr );
1016- assert ((*inner_)->m_player != nullptr );
1017-
1036+ (*inner_)->DebugSanityCheck ();
1037+ (*inner_)->GetPlayer ()->DebugSanityCheck ();
10181038 auto g = (*inner_)->GetGame ();
10191039 assert (g); // i.e. g != nullptrreturn
10201040 return GameInfoset (*inner_);
0 commit comments