Skip to content

Commit 32f76f0

Browse files
committed
Miscellaneous consistency tidying
1 parent e607ca8 commit 32f76f0

File tree

2 files changed

+32
-38
lines changed

2 files changed

+32
-38
lines changed

src/games/behavmixed.cc

Lines changed: 29 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,9 @@ MixedBehaviorProfile<T>::MixedBehaviorProfile(const Game &p_game)
3838
m_gameversion(p_game->GetVersion())
3939
{
4040
int index = 1;
41-
for (const auto &player : p_game->GetPlayers()) {
42-
for (const auto &infoset : player->GetInfosets()) {
43-
for (const auto &action : infoset->GetActions()) {
44-
m_profileIndex[action] = index++;
45-
}
41+
for (const auto &infoset : p_game->GetInfosets()) {
42+
for (const auto &action : infoset->GetActions()) {
43+
m_profileIndex[action] = index++;
4644
}
4745
}
4846
SetCentroid();
@@ -54,29 +52,27 @@ MixedBehaviorProfile<T>::MixedBehaviorProfile(const BehaviorSupportProfile &p_su
5452
m_gameversion(p_support.GetGame()->GetVersion())
5553
{
5654
int index = 1;
57-
for (const auto &player : p_support.GetGame()->GetPlayers()) {
58-
for (const auto &infoset : player->GetInfosets()) {
59-
for (const auto &action : infoset->GetActions()) {
60-
if (p_support.Contains(action)) {
61-
m_profileIndex[action] = index++;
62-
}
63-
else {
64-
m_profileIndex[action] = -1;
65-
}
55+
for (const auto &infoset : p_support.GetGame()->GetInfosets()) {
56+
for (const auto &action : infoset->GetActions()) {
57+
if (p_support.Contains(action)) {
58+
m_profileIndex[action] = index++;
59+
}
60+
else {
61+
m_profileIndex[action] = -1;
6662
}
6763
}
6864
}
6965
SetCentroid();
7066
}
7167

7268
template <class T>
73-
void MixedBehaviorProfile<T>::BehaviorStrat(GamePlayer &player, GameNode &p_node,
69+
void MixedBehaviorProfile<T>::BehaviorStrat(const GamePlayer &player, const GameNode &p_node,
7470
std::map<GameNode, T> &map_nvals,
7571
std::map<GameNode, T> &map_bvals)
7672
{
77-
for (auto child : p_node->GetChildren()) {
73+
for (const auto &child : p_node->GetChildren()) {
7874
if (p_node->GetPlayer() == player) {
79-
if (map_nvals[p_node] > T(0) && map_nvals[child] > T(0)) {
75+
if (map_nvals[p_node] > static_cast<T>(0) && map_nvals[child] > static_cast<T>(0)) {
8076
(*this)[child->GetPriorAction()] = map_nvals[child] / map_nvals[p_node];
8177
}
8278
}
@@ -86,7 +82,7 @@ void MixedBehaviorProfile<T>::BehaviorStrat(GamePlayer &player, GameNode &p_node
8682

8783
template <class T>
8884
void MixedBehaviorProfile<T>::RealizationProbs(const MixedStrategyProfile<T> &mp,
89-
GamePlayer &player,
85+
const GamePlayer &player,
9086
const std::map<GameInfosetRep *, int> &actions,
9187
GameNodeRep *node, std::map<GameNode, T> &map_nvals,
9288
std::map<GameNode, T> &map_bvals)
@@ -98,22 +94,22 @@ void MixedBehaviorProfile<T>::RealizationProbs(const MixedStrategyProfile<T> &mp
9894
if (node->GetPlayer() == player) {
9995
if (contains(actions, node->m_infoset) &&
10096
actions.at(node->GetInfoset().get()) == static_cast<int>(i)) {
101-
prob = T(1);
97+
prob = static_cast<T>(1);
10298
}
10399
else {
104-
prob = T(0);
100+
prob = static_cast<T>(0);
105101
}
106102
}
107103
else if (GetSupport().Contains(node->GetInfoset()->GetAction(i))) {
108104
const int num_actions = GetSupport().GetActions(node->GetInfoset()).size();
109-
prob = T(1) / T(num_actions);
105+
prob = static_cast<T>(1) / static_cast<T>(num_actions);
110106
}
111107
else {
112-
prob = T(0);
108+
prob = static_cast<T>(0);
113109
}
114110
}
115-
else { // n.GetPlayer() == 0
116-
prob = T(node->m_infoset->GetActionProb(node->m_infoset->GetAction(i)));
111+
else {
112+
prob = static_cast<T>(node->m_infoset->GetActionProb(node->m_infoset->GetAction(i)));
117113
}
118114

119115
auto child = node->m_children[i - 1];
@@ -131,12 +127,10 @@ MixedBehaviorProfile<T>::MixedBehaviorProfile(const MixedStrategyProfile<T> &p_p
131127
m_gameversion(p_profile.GetGame()->GetVersion())
132128
{
133129
int index = 1;
134-
for (const auto &player : p_profile.GetGame()->GetPlayers()) {
135-
for (const auto &infoset : player->GetInfosets()) {
136-
for (const auto &action : infoset->GetActions()) {
137-
m_profileIndex[action] = index;
138-
m_probs[index++] = static_cast<T>(0);
139-
}
130+
for (const auto &infoset : p_profile.GetGame()->GetInfosets()) {
131+
for (const auto &action : infoset->GetActions()) {
132+
m_profileIndex[action] = index;
133+
m_probs[index++] = static_cast<T>(0);
140134
}
141135
}
142136

@@ -145,18 +139,17 @@ MixedBehaviorProfile<T>::MixedBehaviorProfile(const MixedStrategyProfile<T> &p_p
145139
const StrategySupportProfile &support = p_profile.GetSupport();
146140
GameRep *game = m_support.GetGame().get();
147141

148-
for (auto player : game->GetPlayers()) {
142+
for (const auto &player : game->GetPlayers()) {
149143
std::map<GameNode, T> map_nvals, map_bvals;
150-
for (auto strategy : support.GetStrategies(player)) {
151-
if (p_profile[strategy] > T(0)) {
144+
for (const auto &strategy : support.GetStrategies(player)) {
145+
if (p_profile[strategy] > static_cast<T>(0)) {
152146
const auto &actions = strategy->m_behav;
153147
map_bvals[root->shared_from_this()] = p_profile[strategy];
154148
RealizationProbs(p_profile, player, actions, root, map_nvals, map_bvals);
155149
}
156150
}
157-
map_nvals[root->shared_from_this()] = T(1); // set the root nval
158-
auto root = m_support.GetGame()->GetRoot();
159-
BehaviorStrat(player, root, map_nvals, map_bvals);
151+
map_nvals[root->shared_from_this()] = static_cast<T>(1);
152+
BehaviorStrat(player, m_support.GetGame()->GetRoot(), map_nvals, map_bvals);
160153
}
161154
}
162155

src/games/behavmixed.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,9 @@ template <class T> class MixedBehaviorProfile {
134134

135135
/// @name Converting mixed strategies to behavior
136136
//@{
137-
void BehaviorStrat(GamePlayer &, GameNode &, std::map<GameNode, T> &, std::map<GameNode, T> &);
138-
void RealizationProbs(const MixedStrategyProfile<T> &, GamePlayer &,
137+
void BehaviorStrat(const GamePlayer &, const GameNode &, std::map<GameNode, T> &,
138+
std::map<GameNode, T> &);
139+
void RealizationProbs(const MixedStrategyProfile<T> &, const GamePlayer &,
139140
const std::map<GameInfosetRep *, int> &, GameNodeRep *,
140141
std::map<GameNode, T> &, std::map<GameNode, T> &);
141142
//@}

0 commit comments

Comments
 (0)