Skip to content
Merged
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
8 changes: 4 additions & 4 deletions src/games/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,10 @@ class GameInfosetRep : public GameObject {
int m_number;
std::string m_label;
GamePlayerRep *m_player;
Array<GameActionRep *> m_actions;
std::vector<GameActionRep *> m_actions;
std::vector<GameNodeRep *> m_members;
int flag{0}, whichbranch{0};
Array<Number> m_probs;
std::vector<Number> m_probs;

GameInfosetRep(GameRep *p_efg, int p_number, GamePlayerRep *p_player, int p_actions);
~GameInfosetRep() override;
Expand All @@ -214,7 +214,7 @@ class GameInfosetRep : public GameObject {
/// Returns the number of actions available at the information set
size_t NumActions() const { return m_actions.size(); }
/// Returns the p_index'th action at the information set
GameAction GetAction(int p_index) const { return m_actions[p_index]; }
GameAction GetAction(int p_index) const { return m_actions.at(p_index - 1); }
/// Returns the actions available at the information set
Array<GameAction> GetActions() const;
//@}
Expand All @@ -230,7 +230,7 @@ class GameInfosetRep : public GameObject {
if (p_action->GetInfoset() != GameInfoset(const_cast<GameInfosetRep *>(this))) {
throw MismatchException();
}
return m_probs[p_action->GetNumber()];
return m_probs.at(p_action->GetNumber() - 1);
}
};

Expand Down
36 changes: 16 additions & 20 deletions src/games/gametree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -124,23 +124,22 @@ void GameTreeRep::DeleteAction(GameAction p_action)
}

IncrementVersion();
size_t where;
for (where = 1; where <= infoset->m_actions.size() && infoset->m_actions[where] != action;
where++)
;
infoset->m_actions[where]->Invalidate();
erase_atindex(infoset->m_actions, where);
auto where = std::find(infoset->m_actions.begin(), infoset->m_actions.end(), action);
auto offset = where - infoset->m_actions.begin();
(*where)->Invalidate();
infoset->m_actions.erase(where);
if (infoset->m_player->IsChance()) {
erase_atindex(infoset->m_probs, where);
infoset->m_probs.erase(std::next(infoset->m_probs.begin(), offset));
NormalizeChanceProbs(infoset);
}
infoset->RenumberActions();

for (auto member : infoset->m_members) {
DeleteTree(member->m_children[where - 1]);
auto it = std::next(member->m_children.begin(), offset);
DeleteTree(*it);
m_numNodes--;
member->m_children[where - 1]->Invalidate();
member->m_children.erase(std::next(member->m_children.begin(), where - 1));
(*it)->Invalidate();
member->m_children.erase(it);
}
ClearComputedValues();
Canonicalize();
Expand All @@ -159,7 +158,7 @@ GameInfosetRep::GameInfosetRep(GameRep *p_efg, int p_number, GamePlayerRep *p_pl
std::generate(m_actions.begin(), m_actions.end(),
[this, i = 1]() mutable { return new GameActionRep(i++, "", this); });
if (p_player->IsChance()) {
m_probs = Array<Number>(m_actions.size());
m_probs = std::vector<Number>(m_actions.size());
std::fill(m_probs.begin(), m_probs.end(), Rational(1, m_actions.size()));
}
m_player->m_infosets.push_back(this);
Expand Down Expand Up @@ -224,20 +223,17 @@ GameAction GameTreeRep::InsertAction(GameInfoset p_infoset, GameAction p_action
}

IncrementVersion();
int where = p_infoset->m_actions.size() + 1;
if (p_action) {
for (where = 1; p_infoset->m_actions[where] != p_action; where++)
;
}
auto where = std::find(p_infoset->m_actions.begin(), p_infoset->m_actions.end(), p_action);
auto offset = where - p_infoset->m_actions.begin();

auto *action = new GameActionRep(where, "", p_infoset);
p_infoset->m_actions.insert(std::next(p_infoset->m_actions.cbegin(), where - 1), action);
auto *action = new GameActionRep(offset + 1, "", p_infoset);
p_infoset->m_actions.insert(where, action);
if (p_infoset->m_player->IsChance()) {
p_infoset->m_probs.insert(std::next(p_infoset->m_probs.cbegin(), where - 1), Number());
p_infoset->m_probs.insert(std::next(p_infoset->m_probs.cbegin(), offset), Number());
}
p_infoset->RenumberActions();
for (const auto &member : p_infoset->m_members) {
member->m_children.insert(std::next(member->m_children.cbegin(), where - 1),
member->m_children.insert(std::next(member->m_children.cbegin(), offset),
new GameNodeRep(this, member));
}

Expand Down