Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [17.0.0] - unreleased

### Changed
- Labels for reduced strategies are now rendered lazily on first access rather than
eagerly during strategy generation. Strategy labels are unchanged.

## [16.7.0] - 2026-07-11

### Added
Expand Down
15 changes: 5 additions & 10 deletions src/games/game.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,8 @@ void GamePlayerRep::MakeStrategy(const std::map<GameInfosetRep *, int> &behav)
{
auto strategy = std::make_shared<GameStrategyRep>(this, m_strategies.size() + 1, "");
strategy->m_behav = behav;
for (const auto &infoset : m_infosets) {
strategy->m_label += (contains(strategy->m_behav, infoset.get()))
? std::to_string(strategy->m_behav[infoset.get()])
: "*";
}
if (strategy->m_label.empty()) {
strategy->m_label = "*";
}
// A derived-label strategy: the text label is rendered from m_behav on the first GetLabel()
strategy->m_label.reset();
m_strategies.push_back(strategy);
}

Expand Down Expand Up @@ -305,8 +299,9 @@ MixedStrategyProfile<T>::MixedStrategyProfile(const MixedBehaviorProfile<T> &p_p
for (const auto &strategy : player->m_strategies) {
auto prob = static_cast<T>(1);
for (const auto &infoset : player->m_infosets) {
if (strategy->m_behav[infoset.get()] > 0) {
prob *= p_profile[infoset->GetAction(strategy->m_behav[infoset.get()])];
if (contains(strategy->m_behav, infoset.get()) &&
strategy->m_behav.at(infoset.get()) > 0) {
prob *= p_profile[infoset->GetAction(strategy->m_behav.at(infoset.get()))];
}
}
(*m_rep)[strategy] = prob;
Expand Down
22 changes: 19 additions & 3 deletions src/games/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <stack>
#include <queue>
#include <memory>
#include <optional>

#include "number.h"
#include "gameobject.h"
Expand Down Expand Up @@ -343,7 +344,9 @@ class GameStrategyRep : public std::enable_shared_from_this<GameStrategyRep> {
bool m_valid{true};
GamePlayerRep *m_player;
int m_number;
std::string m_label;
/// Stored label or std::nullopt for a strategy whose label is derived: strategies created by
/// GamePlayerRep::MakeStrategy() render a label from m_behav on the first call to GetLabel()
mutable std::optional<std::string> m_label;
std::map<GameInfosetRep *, int> m_behav;

public:
Expand All @@ -363,7 +366,7 @@ class GameStrategyRep : public std::enable_shared_from_this<GameStrategyRep> {
/// @name Data access
//@{
/// Returns the text label associated with the strategy
const std::string &GetLabel() const { return m_label; }
const std::string &GetLabel() const;
/// Sets the text label associated with the strategy
void SetLabel(const std::string &p_label);

Expand Down Expand Up @@ -1318,7 +1321,7 @@ inline GamePlayer GameStrategyRep::GetPlayer() const { return m_player->shared_f
inline Game GameStrategyRep::GetGame() const { return m_player->GetGame(); }
inline void GameStrategyRep::SetLabel(const std::string &p_label)
{
if (p_label == m_label) {
if (p_label == GetLabel()) {
return;
}
GetPlayer()->CheckStrategyLabel(p_label);
Expand Down Expand Up @@ -1474,6 +1477,19 @@ inline GamePlayerRep::Infosets GamePlayerRep::GetInfosets() const

inline Game GameSubgameRep::GetGame() const { return m_game->shared_from_this(); }

inline const std::string &GameStrategyRep::GetLabel() const
{
if (!m_label) {
std::string label;
for (const auto &infoset : m_player->GetInfosets()) {
const auto action = m_behav.find(infoset.get());
label += (action != m_behav.end()) ? std::to_string(action->second) : "*";
}
m_label = label.empty() ? "*" : std::move(label);
}
return *m_label;
}

//=======================================================================

/// Factory function to create new game tree
Expand Down
2 changes: 1 addition & 1 deletion src/games/gametree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1741,7 +1741,7 @@ Rational TreePureStrategyProfileRep::GetPayoff(const GamePlayer &p_player) const
for (const auto &player : m_game->GetPlayers()) {
for (const auto &infoset : player->GetInfosets()) {
try {
behav.SetAction(infoset->GetAction(GetStrategy(player)->m_behav[infoset.get()]));
behav.SetAction(infoset->GetAction(GetStrategy(player)->m_behav.at(infoset.get())));
}
catch (std::out_of_range &) {
}
Expand Down
Loading