Skip to content

Commit 360bc9d

Browse files
committed
Use list insertion to minimise copying
1 parent 0114c9d commit 360bc9d

2 files changed

Lines changed: 15 additions & 12 deletions

File tree

src/games/gametree.cc

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -852,22 +852,26 @@ void GameTreeRep::MakeReducedStrategies() const
852852
}
853853

854854
auto [action, node] = *current_iter;
855-
if (current_iter == node->GetParent()->GetActions().begin()) {
855+
if (!node->GetParent()->GetPlayer()->IsChance() &&
856+
current_iter == node->GetParent()->GetActions().begin()) {
856857
// Update behaviors conditional on parent information set being reachable
857-
std::list<StrategyMap> new_behaviors;
858-
for (const auto &behav : behaviors[node->GetParent()->GetPlayer()]) {
859-
if (MatchesPartialHistory(behav, history, node->GetParent()->GetInfoset())) {
860-
for (const auto &action : node->GetParent()->GetInfoset()->GetActions()) {
861-
StrategyMap behav_copy = behav;
862-
behav_copy[node->GetParent()->GetInfoset().get()] = action;
863-
new_behaviors.push_back(behav_copy);
858+
auto behav = behaviors[node->GetParent()->GetPlayer()].begin();
859+
while (behav != behaviors[node->GetParent()->GetPlayer()].end()) {
860+
if (MatchesPartialHistory(*behav, history, node->GetParent()->GetInfoset())) {
861+
auto act = node->GetParent()->GetInfoset()->GetActions().begin();
862+
(*behav)[node->GetParent()->GetInfoset().get()] = *act;
863+
++behav;
864+
++act;
865+
while (act != node->GetParent()->GetInfoset()->GetActions().end()) {
866+
behaviors[node->GetParent()->GetPlayer()].insert(behav, *std::prev(behav));
867+
(*std::prev(behav))[node->GetParent()->GetInfoset().get()] = *act;
868+
++act;
864869
}
865870
}
866871
else {
867-
new_behaviors.push_back(behav);
872+
++behav;
868873
}
869874
}
870-
behaviors[node->GetParent()->GetPlayer()] = new_behaviors;
871875
}
872876
history[position.top().GetOwner()->GetInfoset().get()] = action;
873877

@@ -897,7 +901,6 @@ void GameTreeRep::MakeReducedStrategies() const
897901
std::make_shared<GameStrategyRep>(player.get(), player->m_strategies.size() + 1, label);
898902
for (const auto &[infoset, action] : behav) {
899903
strategy->m_behav[infoset] = action->GetNumber();
900-
std::cout << action->GetNumber() << std::endl;
901904
}
902905
player->m_strategies.push_back(strategy);
903906
}

tests/test_extensive.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ def test_outcome_index_exception_label():
349349
(games.BinEfgTwoPlayer.get_test_data(level=3)),
350350
(games.BinEfgTwoPlayer.get_test_data(level=4)),
351351
(games.BinEfgTwoPlayer.get_test_data(level=5)),
352-
(games.BinEfgTwoPlayer.get_test_data(level=6)),
352+
(games.BinEfgTwoPlayer.get_test_data(level=7)),
353353
# Three player binary tree
354354
(games.BinEfgThreePlayer.get_test_data(level=1)),
355355
(games.BinEfgThreePlayer.get_test_data(level=2)),

0 commit comments

Comments
 (0)