Skip to content

Commit 8d1989d

Browse files
committed
Make GameRep::BuildComputedValues logically const
1 parent 3e5cc45 commit 8d1989d

File tree

4 files changed

+9
-10
lines changed

4 files changed

+9
-10
lines changed

src/games/game.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ class GameRep : public BaseGameRep {
641641
//@}
642642

643643
/// Build any computed values anew
644-
virtual void BuildComputedValues() {}
644+
virtual void BuildComputedValues() const {}
645645
};
646646

647647
//=======================================================================

src/games/gameexpl.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ Rational GameExplicitRep::GetMaxPayoff(const GamePlayer &p_player) const
9494

9595
Array<int> GameExplicitRep::NumStrategies() const
9696
{
97-
const_cast<GameExplicitRep *>(this)->BuildComputedValues();
97+
BuildComputedValues();
9898
Array<int> dim;
9999
for (const auto &player : m_players) {
100100
dim.push_back(player->m_strategies.size());
@@ -104,7 +104,7 @@ Array<int> GameExplicitRep::NumStrategies() const
104104

105105
GameStrategy GameExplicitRep::GetStrategy(int p_index) const
106106
{
107-
const_cast<GameExplicitRep *>(this)->BuildComputedValues();
107+
BuildComputedValues();
108108
int i = 1;
109109
for (const auto &player : m_players) {
110110
for (const auto &strategy : player->m_strategies) {
@@ -118,15 +118,15 @@ GameStrategy GameExplicitRep::GetStrategy(int p_index) const
118118

119119
int GameExplicitRep::NumStrategyContingencies() const
120120
{
121-
const_cast<GameExplicitRep *>(this)->BuildComputedValues();
121+
BuildComputedValues();
122122
return std::accumulate(
123123
m_players.begin(), m_players.end(), 1,
124124
[](int ncont, const GamePlayerRep *p) { return ncont * p->m_strategies.size(); });
125125
}
126126

127127
int GameExplicitRep::MixedProfileLength() const
128128
{
129-
const_cast<GameExplicitRep *>(this)->BuildComputedValues();
129+
BuildComputedValues();
130130
return std::accumulate(
131131
m_players.begin(), m_players.end(), 0,
132132
[](int size, const GamePlayerRep *p) { return size + p->m_strategies.size(); });

src/games/gametree.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -884,12 +884,12 @@ void GameTreeRep::ClearComputedValues() const
884884
m_computedValues = false;
885885
}
886886

887-
void GameTreeRep::BuildComputedValues()
887+
void GameTreeRep::BuildComputedValues() const
888888
{
889889
if (m_computedValues) {
890890
return;
891891
}
892-
Canonicalize();
892+
const_cast<GameTreeRep *>(this)->Canonicalize();
893893
for (const auto &player : m_players) {
894894
player->MakeReducedStrats(m_root, nullptr);
895895
}
@@ -959,8 +959,7 @@ void GameTreeRep::WriteEfgFile(std::ostream &p_file, const GameNode &p_subtree /
959959

960960
void GameTreeRep::WriteNfgFile(std::ostream &p_file) const
961961
{
962-
// FIXME: Building computed values is logically const.
963-
const_cast<GameTreeRep *>(this)->BuildComputedValues();
962+
BuildComputedValues();
964963
GameRep::WriteNfgFile(p_file);
965964
}
966965

src/games/gametree.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class GameTreeRep : public GameExplicitRep {
4848
/// @name Managing the representation
4949
//@{
5050
void Canonicalize();
51-
void BuildComputedValues() override;
51+
void BuildComputedValues() const override;
5252
void ClearComputedValues() const;
5353

5454
/// Removes the node from the information set, invalidating if emptied

0 commit comments

Comments
 (0)