@@ -40,88 +40,32 @@ namespace Gambit {
4040// / in which they appear in the underlying game.
4141class StrategySupportProfile {
4242 Game m_game;
43- CartesianSubset m_strategies;
43+ std::map<GamePlayer, std::vector<GameStrategy>> m_support;
44+ CartesianSubset m_strategyDigits;
4445
4546public:
4647 class Support {
4748 const StrategySupportProfile *m_profile;
48- size_t m_playerIndex ;
49+ GamePlayer m_player ;
4950
5051 public:
51- class const_iterator {
52- const StrategySupportProfile *m_profile{nullptr };
53- size_t m_playerIndex{0 };
54- std::vector<int >::const_iterator m_it;
55-
56- public:
57- using value_type = GameStrategy;
58- using reference = GameStrategy;
59- using pointer = void ;
60- using difference_type = std::ptrdiff_t ;
61- using iterator_category = std::forward_iterator_tag;
62-
63- const_iterator () = default ;
64- const_iterator (const StrategySupportProfile *profile, const size_t playerIndex,
65- const std::vector<int >::const_iterator it)
66- : m_profile(profile), m_playerIndex(playerIndex), m_it(it)
67- {
68- }
69-
70- GameStrategy operator *() const
71- {
72- const auto &player = m_profile->m_game ->GetPlayer (m_playerIndex + 1 );
73- return player->GetStrategy (*m_it + 1 );
74- }
75-
76- const_iterator &operator ++()
77- {
78- ++m_it;
79- return *this ;
80- }
81-
82- bool operator ==(const const_iterator &other) const { return m_it == other.m_it ; }
83-
84- bool operator !=(const const_iterator &other) const { return !(*this == other); }
85- };
86-
87- Support () : m_profile(nullptr ), m_playerIndex(0 ) {}
88-
89- Support (const StrategySupportProfile *profile, GamePlayer player)
90- : m_profile(profile), m_playerIndex(player->GetNumber () - 1)
91- {
92- }
93-
94- size_t size () const { return m_profile->m_strategies .m_allowedDigits [m_playerIndex].size (); }
95-
96- GameStrategy operator [](const size_t index) const
97- {
98- const int digit = m_profile->m_strategies .m_allowedDigits [m_playerIndex][index];
99- return m_profile->m_game ->GetPlayer (m_playerIndex + 1 )->GetStrategy (digit + 1 );
100- }
52+ using const_iterator = std::vector<GameStrategy>::const_iterator;
10153
102- GameStrategy front () const
54+ Support () : m_profile(nullptr ), m_player(nullptr ) {}
55+ Support (const StrategySupportProfile *profile, const GamePlayer &player)
56+ : m_profile(profile), m_player(player)
10357 {
104- const int digit = m_profile->m_strategies .m_allowedDigits [m_playerIndex].front ();
105- return m_profile->m_game ->GetPlayer (m_playerIndex + 1 )->GetStrategy (digit + 1 );
10658 }
10759
108- GameStrategy back () const
109- {
110- const int digit = m_profile->m_strategies .m_allowedDigits [m_playerIndex].back ();
111- return m_profile->m_game ->GetPlayer (m_playerIndex + 1 )->GetStrategy (digit + 1 );
112- }
113-
114- const_iterator begin () const
115- {
116- const auto &digits = m_profile->m_strategies .m_allowedDigits [m_playerIndex];
117- return {m_profile, m_playerIndex, digits.begin ()};
118- }
119-
120- const_iterator end () const
60+ size_t size () const { return m_profile->m_support .at (m_player).size (); }
61+ GameStrategy operator [](const size_t index) const
12162 {
122- const auto &digits = m_profile->m_strategies .m_allowedDigits [m_playerIndex];
123- return {m_profile, m_playerIndex, digits.end ()};
63+ return m_profile->m_support .at (m_player)[index];
12464 }
65+ GameStrategy front () const { return m_profile->m_support .at (m_player).front (); }
66+ GameStrategy back () const { return m_profile->m_support .at (m_player).back (); }
67+ const_iterator begin () const { return m_profile->m_support .at (m_player).begin (); }
68+ const_iterator end () const { return m_profile->m_support .at (m_player).end (); }
12569 };
12670
12771 // / @name Lifecycle
@@ -136,13 +80,13 @@ class StrategySupportProfile {
13680 bool operator ==(const StrategySupportProfile &p_support) const
13781 {
13882 return m_game == p_support.m_game &&
139- m_strategies .m_allowedDigits == p_support.m_strategies .m_allowedDigits ;
83+ m_strategyDigits .m_allowedDigits == p_support.m_strategyDigits .m_allowedDigits ;
14084 }
14185 // / Test for the inequality of two supports
14286 bool operator !=(const StrategySupportProfile &p_support) const
14387 {
14488 return m_game != p_support.m_game ||
145- m_strategies .m_allowedDigits != p_support.m_strategies .m_allowedDigits ;
89+ m_strategyDigits .m_allowedDigits != p_support.m_strategyDigits .m_allowedDigits ;
14690 }
14791 // @}
14892
@@ -166,7 +110,7 @@ class StrategySupportProfile {
166110 // / Returns true exactly when the strategy is in the support.
167111 bool Contains (const GameStrategy &s) const
168112 {
169- const auto &digits = m_strategies .m_allowedDigits [s->GetPlayer ()->GetNumber () - 1 ];
113+ const auto &digits = m_strategyDigits .m_allowedDigits [s->GetPlayer ()->GetNumber () - 1 ];
170114 const int digit = s->GetNumber () - 1 ;
171115 return std::binary_search (digits.begin (), digits.end (), digit);
172116 }
@@ -203,7 +147,7 @@ class StrategySupportProfile {
203147 const size_t player_index = player->GetNumber () - 1 ;
204148 const int digit = p_strategy->GetNumber () - 1 ;
205149 StrategySupportProfile restricted (*this );
206- restricted.m_strategies .m_allowedDigits [player_index].assign (1 , digit);
150+ restricted.m_strategyDigits .m_allowedDigits [player_index].assign (1 , digit);
207151 return restricted;
208152 }
209153 // @}
0 commit comments