Skip to content

Commit 9115592

Browse files
committed
Fixed improper shared pointer handling writing a .nfg file for an extensive game
1 parent ed951ad commit 9115592

File tree

4 files changed

+38
-4
lines changed

4 files changed

+38
-4
lines changed

ChangeLog

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
### Fixed
66
- Fixed a regression in which null outcomes in strategic game tables were not handled correctly
77
when changing the number of strategies in the game (#571)
8+
- Fixed improper shared pointer handling when writing a .nfg file based on a game in
9+
extensive form.
810

911

1012
## [16.3.2] - unreleased

src/games/behavmixed.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,8 @@ template <class T> class MixedBehaviorProfile {
226226
template <class Generator>
227227
MixedBehaviorProfile<double> GameRep::NewRandomBehaviorProfile(Generator &generator) const
228228
{
229-
auto profile = MixedBehaviorProfile<double>(Game(const_cast<GameRep *>(this)));
229+
auto profile =
230+
MixedBehaviorProfile<double>(std::const_pointer_cast<GameRep>(shared_from_this()));
230231
std::exponential_distribution<> dist(1); // NOLINT(misc-const-correctness)
231232
for (auto player : GetPlayers()) {
232233
for (auto infoset : player->GetInfosets()) {
@@ -242,7 +243,8 @@ template <class Generator>
242243
MixedBehaviorProfile<Rational> GameRep::NewRandomBehaviorProfile(int p_denom,
243244
Generator &generator) const
244245
{
245-
auto profile = MixedBehaviorProfile<Rational>(Game(const_cast<GameRep *>(this)));
246+
auto profile =
247+
MixedBehaviorProfile<Rational>(std::const_pointer_cast<GameRep>(shared_from_this()));
246248
for (auto player : GetPlayers()) {
247249
for (auto infoset : player->GetInfosets()) {
248250
std::list<Rational> dist =

src/games/game.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ void GameRep::WriteNfgFile(std::ostream &p_file) const
213213
p_file << "}" << std::endl;
214214
p_file << std::quoted(GetComment()) << std::endl << std::endl;
215215

216-
for (auto iter :
217-
StrategyContingencies(StrategySupportProfile(Game(const_cast<GameRep *>(this))))) {
216+
for (auto iter : StrategyContingencies(
217+
StrategySupportProfile(std::const_pointer_cast<GameRep>(shared_from_this())))) {
218218
p_file << FormatList(
219219
players,
220220
[&iter](const GamePlayer &p) {

tests/test_io.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,36 @@ def test_write_nfg():
6363
assert serialized_game[:3] == "NFG"
6464

6565

66+
def test_write_efg_as_nfg():
67+
result = """
68+
NFG 1 R "Centipede game. Three inning with probability of altruism. " { "Player 1" "Player 2" }
69+
70+
{ { "1**111" "21*111" "221111" "222111" }
71+
{ "1**111" "21*111" "221111" "222111" }
72+
}
73+
""
74+
75+
20027/25000 2689/12500
76+
541/1250 3983/2500
77+
3299/6250 5053/3125
78+
227/250 214/125
79+
5081/6250 3283/12500
80+
19931/6250 2677/3125
81+
5362/3125 19903/3125
82+
262/125 808/125
83+
2689/3125 5659/12500
84+
10114/3125 3271/3125
85+
39814/3125 10696/3125
86+
856/125 3184/125
87+
163/125 163/500
88+
92/25 23/25
89+
1648/125 412/125
90+
256/5 64/5
91+
"""
92+
game = gbt.read_efg("tests/test_games/cent3.efg")
93+
assert game.to_nfg().strip() == result.strip()
94+
95+
6696
def test_write_html():
6797
game = gbt.Game.new_table([2, 2])
6898
serialized_game = game.to_html()

0 commit comments

Comments
 (0)