Skip to content

Commit a29fd0a

Browse files
committed
Remove GetAction(int) from Game as part of deprecating access-by-index methods
1 parent 5295d31 commit a29fd0a

11 files changed

Lines changed: 24 additions & 33 deletions

File tree

src/games/game.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,8 +550,6 @@ class GameRep : public BaseGameRep {
550550
virtual Array<GameInfoset> GetInfosets() const = 0;
551551
/// Returns an array with the number of information sets per personal player
552552
virtual Array<int> NumInfosets() const = 0;
553-
/// Returns the act'th action in the game (numbered globally)
554-
virtual GameAction GetAction(int act) const = 0;
555553
//@}
556554

557555
/// @name Outcomes

src/games/gameagg.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ class GameAGGRep : public GameRep {
9393
Array<GameInfoset> GetInfosets() const override { throw UndefinedException(); }
9494
/// Returns an array with the number of information sets per personal player
9595
Array<int> NumInfosets() const override { throw UndefinedException(); }
96-
/// Returns the act'th action in the game (numbered globally)
97-
GameAction GetAction(int act) const override { throw UndefinedException(); }
9896
//@}
9997

10098
/// @name Outcomes

src/games/gamebagg.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@ class GameBAGGRep : public GameRep {
9494
Array<GameInfoset> GetInfosets() const override { throw UndefinedException(); }
9595
/// Returns an array with the number of information sets per personal player
9696
Array<int> NumInfosets() const override { throw UndefinedException(); }
97-
/// Returns the act'th action in the game (numbered globally)
98-
GameAction GetAction(int act) const override { throw UndefinedException(); }
9997
//@}
10098

10199
/// @name Outcomes

src/games/gametable.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ class GameTableRep : public GameExplicitRep {
8282
Array<GameInfoset> GetInfosets() const override { throw UndefinedException(); }
8383
/// Returns an array with the number of information sets per personal player
8484
Array<int> NumInfosets() const override { throw UndefinedException(); }
85-
/// Returns the act'th action in the game (numbered globally)
86-
GameAction GetAction(int act) const override { throw UndefinedException(); }
8785
//@}
8886

8987
/// @name Nodes

src/games/gametree.cc

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,21 +1031,6 @@ Array<int> GameTreeRep::NumInfosets() const
10311031
return foo;
10321032
}
10331033

1034-
GameAction GameTreeRep::GetAction(int p_index) const
1035-
{
1036-
int index = 1;
1037-
for (auto player : m_players) {
1038-
for (auto infoset : player->m_infosets) {
1039-
for (auto action : infoset->m_actions) {
1040-
if (index++ == p_index) {
1041-
return action;
1042-
}
1043-
}
1044-
}
1045-
}
1046-
throw IndexException();
1047-
}
1048-
10491034
//------------------------------------------------------------------------
10501035
// GameTreeRep: Outcomes
10511036
//------------------------------------------------------------------------

src/games/gametree.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,6 @@ class GameTreeRep : public GameExplicitRep {
284284
Array<GameInfoset> GetInfosets() const override;
285285
/// Returns an array with the number of information sets per personal player
286286
Array<int> NumInfosets() const override;
287-
/// Returns the act'th action in the game (numbered globally)
288-
GameAction GetAction(int act) const override;
289287
//@}
290288

291289
/// @name Modification

src/gui/analysis.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ std::string gbtAnalysisProfileList<T>::GetActionProb(int p_action, int p_index)
363363
try {
364364
const MixedBehaviorProfile<T> &profile = *m_behavProfiles[index];
365365

366-
if (!profile.IsDefinedAt(profile.GetGame()->GetAction(p_action)->GetInfoset())) {
366+
if (!profile.IsDefinedAt(m_doc->GetAction(p_action)->GetInfoset())) {
367367
return "*";
368368
}
369369

src/gui/dlefglogit.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ wxString gbtLogitBehavList::GetCellValue(const wxSheetCoords &p_coords)
8484
return wxT("Lambda");
8585
}
8686
else {
87-
Gambit::GameAction action = m_doc->GetGame()->GetAction(p_coords.GetCol());
87+
Gambit::GameAction action = m_doc->GetAction(p_coords.GetCol());
8888
return (wxString::Format(wxT("%d: "), action->GetInfoset()->GetNumber()) +
8989
wxString(action->GetLabel().c_str(), *wxConvCurrent));
9090
}
@@ -114,7 +114,7 @@ static wxColour GetPlayerColor(gbtGameDocument *p_doc, int p_index)
114114
return *wxBLACK;
115115
}
116116

117-
Gambit::GameAction action = p_doc->GetGame()->GetAction(p_index);
117+
Gambit::GameAction action = p_doc->GetAction(p_index);
118118
return p_doc->GetStyle().GetPlayerColor(action->GetInfoset()->GetPlayer()->GetNumber());
119119
}
120120

@@ -146,7 +146,7 @@ wxSheetCellAttr gbtLogitBehavList::GetAttr(const wxSheetCoords &p_coords, wxShee
146146
attr.SetAlignment(wxALIGN_RIGHT, wxALIGN_CENTER);
147147
attr.SetOrientation(wxHORIZONTAL);
148148
if (p_coords.GetCol() > 0) {
149-
Gambit::GameAction action = m_doc->GetGame()->GetAction(p_coords.GetCol());
149+
Gambit::GameAction action = m_doc->GetAction(p_coords.GetCol());
150150
attr.SetForegroundColour(
151151
m_doc->GetStyle().GetPlayerColor(action->GetInfoset()->GetPlayer()->GetNumber()));
152152
if (action->GetInfoset()->GetNumber() % 2 == 0) {

src/gui/efgprofile.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void gbtBehavProfileList::OnLabelClick(wxSheetEvent &p_event)
5858
else {
5959
// Clicking on an action column sets the selected node to the first
6060
// member of that information set.
61-
Gambit::GameAction action = m_doc->GetGame()->GetAction(p_event.GetCol() + 1);
61+
Gambit::GameAction action = m_doc->GetAction(p_event.GetCol() + 1);
6262
m_doc->SetSelectNode(action->GetInfoset()->GetMember(1));
6363
}
6464
}
@@ -74,7 +74,7 @@ wxString gbtBehavProfileList::GetCellValue(const wxSheetCoords &p_coords)
7474
return wxString::Format(wxT("%d"), p_coords.GetRow() + 1);
7575
}
7676
else if (IsColLabelCell(p_coords)) {
77-
Gambit::GameAction action = m_doc->GetGame()->GetAction(p_coords.GetCol() + 1);
77+
Gambit::GameAction action = m_doc->GetAction(p_coords.GetCol() + 1);
7878
return (wxString::Format(wxT("%d: "), action->GetInfoset()->GetNumber()) +
7979
wxString(action->GetLabel().c_str(), *wxConvCurrent));
8080
}
@@ -88,7 +88,7 @@ wxString gbtBehavProfileList::GetCellValue(const wxSheetCoords &p_coords)
8888

8989
static wxColour GetPlayerColor(gbtGameDocument *p_doc, int p_index)
9090
{
91-
Gambit::GameAction action = p_doc->GetGame()->GetAction(p_index + 1);
91+
Gambit::GameAction action = p_doc->GetAction(p_index + 1);
9292
return p_doc->GetStyle().GetPlayerColor(action->GetInfoset()->GetPlayer()->GetNumber());
9393
}
9494

@@ -136,7 +136,7 @@ wxSheetCellAttr gbtBehavProfileList::GetAttr(const wxSheetCoords &p_coords, wxSh
136136
attr.SetRenderer(wxSheetCellRenderer(new gbtRationalRendererRefData()));
137137

138138
try {
139-
Gambit::GameAction action = m_doc->GetGame()->GetAction(p_coords.GetCol() + 1);
139+
Gambit::GameAction action = m_doc->GetAction(p_coords.GetCol() + 1);
140140
attr.SetForegroundColour(
141141
m_doc->GetStyle().GetPlayerColor(action->GetInfoset()->GetPlayer()->GetNumber()));
142142
if (action->GetInfoset()->GetNumber() % 2 == 0) {

src/gui/gamedoc.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,21 @@ void gbtGameDocument::BuildNfg()
389389
}
390390
}
391391

392+
GameAction gbtGameDocument::GetAction(int p_index) const
393+
{
394+
int index = 1;
395+
for (auto player : m_game->GetPlayers()) {
396+
for (auto infoset : player->GetInfosets()) {
397+
for (auto action : infoset->GetActions()) {
398+
if (index++ == p_index) {
399+
return action;
400+
}
401+
}
402+
}
403+
}
404+
throw IndexException();
405+
}
406+
392407
void gbtGameDocument::SetStyle(const gbtStyle &p_style)
393408
{
394409
m_style = p_style;

0 commit comments

Comments
 (0)