From 0498496ffc5246a1bf0e9f1ef021e977c441c133 Mon Sep 17 00:00:00 2001 From: Ed Chalstrey Date: Tue, 31 Mar 2026 11:11:52 +0100 Subject: [PATCH 1/2] Add player labels for normal form game visuals --- src/games/writer.cc | 23 ++++++++++++++++++++--- tests/test_io.py | 4 ++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/games/writer.cc b/src/games/writer.cc index 744f3efad..5c2d679b9 100644 --- a/src/games/writer.cc +++ b/src/games/writer.cc @@ -52,18 +52,35 @@ std::string WriteHTMLFile(const Game &p_game, const GamePlayer &p_rowPlayer, theHtml += ""; theHtml += ""; - theHtml += ""; + theHtml += ""; + theHtml += ""; + theHtml += ""; + theHtml += ""; for (const auto &strategy : p_colPlayer->GetStrategies()) { - theHtml += ""; } theHtml += ""; + + bool first_row_strategy = true; for (const auto &row_strategy : p_rowPlayer->GetStrategies()) { const PureStrategyProfile profile = iter; profile->SetStrategy(row_strategy); theHtml += ""; - theHtml += ""; + first_row_strategy = false; + } + + theHtml += ""; for (const auto &col_strategy : p_colPlayer->GetStrategies()) { diff --git a/tests/test_io.py b/tests/test_io.py index 3016c224b..da3043502 100644 --- a/tests/test_io.py +++ b/tests/test_io.py @@ -101,8 +101,12 @@ def test_write_efg_as_nfg(): def test_write_html(): game = gbt.Game.new_table([2, 2]) + game.players[0].label = "Alice" + game.players[1].label = "Bob" serialized_game = game.to_html() assert isinstance(serialized_game, str) + assert "Alice" in serialized_game + assert "Bob" in serialized_game def test_write_latex(): From c33858d7cd89749882b5ac3d60c3545e0d5d3b38 Mon Sep 17 00:00:00 2001 From: Ed Chalstrey Date: Tue, 31 Mar 2026 11:36:49 +0100 Subject: [PATCH 2/2] refactor HTML generation block to use C++11 raw string literals --- src/games/writer.cc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/games/writer.cc b/src/games/writer.cc index 5c2d679b9..3cc882e9c 100644 --- a/src/games/writer.cc +++ b/src/games/writer.cc @@ -52,15 +52,15 @@ std::string WriteHTMLFile(const Game &p_game, const GamePlayer &p_rowPlayer, theHtml += "
GetStrategies().size()) + + "\" align=\"center\">"; + theHtml += p_colPlayer->GetLabel(); + theHtml += "
"; + theHtml += ""; theHtml += strategy->GetLabel(); theHtml += "
"; + + if (first_row_strategy) { + theHtml += "GetStrategies().size()) + + "\" align=\"center\" valign=\"middle\">"; + theHtml += p_rowPlayer->GetLabel(); + theHtml += ""; theHtml += row_strategy->GetLabel(); theHtml += "
"; theHtml += ""; - theHtml += ""; - theHtml += ")"; + theHtml += R"("; theHtml += ""; theHtml += ""; for (const auto &strategy : p_colPlayer->GetStrategies()) { - theHtml += ""; } @@ -73,14 +73,14 @@ std::string WriteHTMLFile(const Game &p_game, const GamePlayer &p_rowPlayer, theHtml += ""; if (first_row_strategy) { - theHtml += ""; first_row_strategy = false; } - theHtml += ""; for (const auto &col_strategy : p_colPlayer->GetStrategies()) {
GetStrategies().size()) + - "\" align=\"center\">"; + theHtml += R"(GetStrategies().size()) + + R"(" align="center">)"; theHtml += p_colPlayer->GetLabel(); theHtml += "
"; + theHtml += R"()"; theHtml += strategy->GetLabel(); theHtml += "
GetStrategies().size()) + - "\" align=\"center\" valign=\"middle\">"; + theHtml += R"(GetStrategies().size()) + + R"(" align="center" valign="middle">)"; theHtml += p_rowPlayer->GetLabel(); theHtml += ""; + theHtml += R"()"; theHtml += row_strategy->GetLabel(); theHtml += "