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: 7 additions & 1 deletion src/games/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ class GameInfosetRep : public std::enable_shared_from_this<GameInfosetRep> {
void Invalidate() { m_valid = false; }

Game GetGame() const;
int GetNumber() const { return m_number; }
int GetNumber() const;

GamePlayer GetPlayer() const;

Expand Down Expand Up @@ -1228,6 +1228,12 @@ inline GameNode GameInfosetRep::GetMember(int p_index) const
return m_members.at(p_index - 1);
}

inline int GameInfosetRep::GetNumber() const
{
m_game->EnsureInfosetOrdering();
return m_number;
}

inline GameInfosetRep::Members GameInfosetRep::GetMembers() const
{
m_game->EnsureInfosetOrdering();
Expand Down
23 changes: 11 additions & 12 deletions src/games/gametree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ void GameTreeRep::DeleteAction(GameAction p_action)
member->m_children.erase(it);
}
ClearComputedValues();
InvalidateNodeOrdering();
InvalidateTreeOrdering();
}

GameInfoset GameActionRep::GetInfoset() const { return m_infoset->shared_from_this(); }
Expand Down Expand Up @@ -195,7 +195,7 @@ void GameTreeRep::SetPlayer(GameInfoset p_infoset, GamePlayer p_player)
p_player->m_infosets.push_back(p_infoset);

ClearComputedValues();
InvalidateNodeOrdering();
InvalidateTreeOrdering();
}

bool GameInfosetRep::Precedes(GameNode p_node) const
Expand Down Expand Up @@ -239,7 +239,7 @@ GameAction GameTreeRep::InsertAction(GameInfoset p_infoset, GameAction p_action
m_numNodes += p_infoset->m_members.size();
// m_numNonterminalNodes stays unchanged when an action is appended to an information set
ClearComputedValues();
InvalidateNodeOrdering();
InvalidateTreeOrdering();
return action;
}

Expand All @@ -253,9 +253,8 @@ void GameTreeRep::RemoveMember(GameInfosetRep *p_infoset, GameNodeRep *p_node)
p_infoset->Invalidate();
p_infoset->m_player->m_infosets.erase(std::find(
player->m_infosets.begin(), player->m_infosets.end(), p_infoset->shared_from_this()));
RenumberInfosets(player);
}
InvalidateNodeOrdering();
InvalidateTreeOrdering();
}

void GameTreeRep::Reveal(GameInfoset p_atInfoset, GamePlayer p_player)
Expand All @@ -282,7 +281,7 @@ void GameTreeRep::Reveal(GameInfoset p_atInfoset, GamePlayer p_player)
}

ClearComputedValues();
InvalidateNodeOrdering();
InvalidateTreeOrdering();
}

//========================================================================
Expand Down Expand Up @@ -428,7 +427,7 @@ void GameTreeRep::DeleteParent(GameNode p_node)

oldParent->Invalidate();
ClearComputedValues();
InvalidateNodeOrdering();
InvalidateTreeOrdering();
}

void GameTreeRep::DeleteTree(GameNode p_node)
Expand All @@ -455,7 +454,7 @@ void GameTreeRep::DeleteTree(GameNode p_node)
node->m_label = "";

ClearComputedValues();
InvalidateNodeOrdering();
InvalidateTreeOrdering();
}

void GameTreeRep::CopySubtree(GameNodeRep *dest, GameNodeRep *src, GameNodeRep *stop)
Expand Down Expand Up @@ -497,7 +496,7 @@ void GameTreeRep::CopyTree(GameNode p_dest, GameNode p_src)
CopySubtree(dest_child->get(), src_child->get(), dest);
}
ClearComputedValues();
InvalidateNodeOrdering();
InvalidateTreeOrdering();
}
}

Expand All @@ -521,7 +520,7 @@ void GameTreeRep::MoveTree(GameNode p_dest, GameNode p_src)
dest->m_outcome = nullptr;

ClearComputedValues();
InvalidateNodeOrdering();
InvalidateTreeOrdering();
}

Game GameTreeRep::CopySubgame(GameNode p_root) const
Expand Down Expand Up @@ -630,7 +629,7 @@ GameInfoset GameTreeRep::AppendMove(GameNode p_node, GameInfoset p_infoset)
});
m_numNonterminalNodes++;
ClearComputedValues();
InvalidateNodeOrdering();
InvalidateTreeOrdering();
return node->m_infoset->shared_from_this();
}

Expand Down Expand Up @@ -687,7 +686,7 @@ GameInfoset GameTreeRep::InsertMove(GameNode p_node, GameInfoset p_infoset)
m_numNodes += newNode->m_infoset->m_actions.size();
m_numNonterminalNodes++;
ClearComputedValues();
InvalidateNodeOrdering();
InvalidateTreeOrdering();
return p_infoset;
}

Expand Down
3 changes: 2 additions & 1 deletion src/games/gametree.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ class GameTreeRep final : public GameExplicitRep {

/// @name Managing the representation
//@{
void InvalidateNodeOrdering() const
/// Jointly invalidates the ordering of the nodes and the ordering of the information sets.
void InvalidateTreeOrdering() const
{
m_nodesOrdered = false;
m_infosetsOrdered = false;
Expand Down