Skip to content

Commit 52d6a9e

Browse files
committed
In pure strategy profile compute strategy by mixed-radix arithmetic rather than map lookup.
1 parent b4c3f2b commit 52d6a9e

3 files changed

Lines changed: 17 additions & 10 deletions

File tree

src/games/game.cc

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,16 @@ GameRep::~GameRep()
184184

185185
void GameRep::IndexStrategies() const
186186
{
187-
long offset = 1L;
188-
for (auto player : m_players) {
189-
int st = 1;
190-
for (auto strategy : player->m_strategies) {
191-
strategy->m_number = st;
192-
strategy->m_offset = (st - 1) * offset;
193-
st++;
187+
long stride = 1L;
188+
for (const auto player : m_players) {
189+
player->m_stride = stride;
190+
int digit = 0;
191+
for (const auto strategy : player->m_strategies) {
192+
strategy->m_number = digit + 1;
193+
strategy->m_offset = digit * stride;
194+
++digit;
194195
}
195-
offset *= player->m_strategies.size();
196+
stride *= player->m_strategies.size();
196197
}
197198
}
198199

src/games/game.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ class GamePlayerRep : public std::enable_shared_from_this<GamePlayerRep> {
363363
friend class GameInfosetRep;
364364
friend class GameNodeRep;
365365
friend class StrategySupportProfile;
366+
friend class PureStrategyProfileRep;
366367
template <class T> friend class MixedBehaviorProfile;
367368
template <class T> friend class MixedStrategyProfile;
368369

@@ -378,6 +379,8 @@ class GamePlayerRep : public std::enable_shared_from_this<GamePlayerRep> {
378379
bool m_valid{true};
379380
GameRep *m_game;
380381
int m_number;
382+
// The stride of the player into the set of pure strategy profiles
383+
long m_stride{0};
381384
std::string m_label;
382385
std::vector<std::shared_ptr<GameInfosetRep>> m_infosets;
383386
std::vector<std::shared_ptr<GameStrategyRep>> m_strategies;

src/games/stratpure.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,12 @@ class PureStrategyProfileRep {
6161
const Game &GetGame() const { return m_nfg; }
6262

6363
/// Get the strategy played by the player
64-
const GameStrategy &GetStrategy(const GamePlayer &p_player) const
64+
GameStrategy GetStrategy(const GamePlayer &p_player) const
6565
{
66-
return m_profile.at(p_player);
66+
const long stride = p_player->m_stride;
67+
const long radix = p_player->m_strategies.size();
68+
const long digit = (m_index / stride) % radix;
69+
return p_player->m_strategies[digit];
6770
}
6871

6972
/// Set the strategy for a player

0 commit comments

Comments
 (0)