Skip to content

Commit 4d697f4

Browse files
committed
Fix regression in handling null outcomes when resizing strategic games.
Re-building the strategic game outcomes table was not correctly handling the case of null outcomes since the migration to using std::shared_ptr. Fixes #571. Also affected changes to strategies in `pygambit`; a test was extended to check this case.
1 parent 51855b0 commit 4d697f4

3 files changed

Lines changed: 14 additions & 3 deletions

File tree

ChangeLog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## [16.4.1] - unreleased
4+
5+
### Fixed
6+
- Fixed a regression in which null outcomes in strategic game tables were not handled correctly
7+
when changing the number of strategies in the game (#571)
8+
9+
310
## [16.4.0] - 2025-09-05
411

512
### General

src/games/gametable.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,8 +407,8 @@ GameStrategy GameTableRep::NewStrategy(const GamePlayer &p_player, const std::st
407407
throw MismatchException();
408408
}
409409
IncrementVersion();
410-
p_player->m_strategies.push_back(
411-
std::make_shared<GameStrategyRep>(p_player.get(), p_player->m_strategies.size(), p_label));
410+
p_player->m_strategies.push_back(std::make_shared<GameStrategyRep>(
411+
p_player.get(), p_player->m_strategies.size() + 1, p_label));
412412
RebuildTable();
413413
return p_player->m_strategies.back();
414414
}
@@ -495,7 +495,7 @@ void GameTableRep::RebuildTable()
495495
}
496496
}
497497

498-
if (newindex >= 0) {
498+
if (newindex >= 0 && iter->GetOutcome() != nullptr) {
499499
newResults[newindex] = iter->GetOutcome().get();
500500
}
501501
}

tests/test_players.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ def test_strategic_game_add_strategy():
8080
game = gbt.Game.new_table([2, 2])
8181
game.add_strategy(game.players[0], "new strategy")
8282
assert len(game.players[0].strategies) == 3
83+
# This second add also ensures that we are testing the case where there
84+
# are null outcomes in the table
85+
game.add_strategy(game.players[1], "new strategy")
86+
assert len(game.players[1].strategies) == 3
8387

8488

8589
def test_extensive_game_add_strategy():

0 commit comments

Comments
 (0)