Skip to content

Commit 0498496

Browse files
Add player labels for normal form game visuals
1 parent 1daa6e3 commit 0498496

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

src/games/writer.cc

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,35 @@ std::string WriteHTMLFile(const Game &p_game, const GamePlayer &p_rowPlayer,
5252

5353
theHtml += "<table>";
5454
theHtml += "<tr>";
55-
theHtml += "<td></td>";
55+
theHtml += "<td colspan=\"2\" rowspan=\"2\"></td>";
56+
theHtml += "<td colspan=\"" + std::to_string(p_colPlayer->GetStrategies().size()) +
57+
"\" align=\"center\"><b>";
58+
theHtml += p_colPlayer->GetLabel();
59+
theHtml += "</b></td>";
60+
theHtml += "</tr>";
61+
theHtml += "<tr>";
5662
for (const auto &strategy : p_colPlayer->GetStrategies()) {
57-
theHtml += "<td align=center><b>";
63+
theHtml += "<td align=\"center\"><b>";
5864
theHtml += strategy->GetLabel();
5965
theHtml += "</b></td>";
6066
}
6167
theHtml += "</tr>";
68+
69+
bool first_row_strategy = true;
6270
for (const auto &row_strategy : p_rowPlayer->GetStrategies()) {
6371
const PureStrategyProfile profile = iter;
6472
profile->SetStrategy(row_strategy);
6573
theHtml += "<tr>";
66-
theHtml += "<td align=center><b>";
74+
75+
if (first_row_strategy) {
76+
theHtml += "<td rowspan=\"" + std::to_string(p_rowPlayer->GetStrategies().size()) +
77+
"\" align=\"center\" valign=\"middle\"><b>";
78+
theHtml += p_rowPlayer->GetLabel();
79+
theHtml += "</b></td>";
80+
first_row_strategy = false;
81+
}
82+
83+
theHtml += "<td align=\"center\"><b>";
6784
theHtml += row_strategy->GetLabel();
6885
theHtml += "</b></td>";
6986
for (const auto &col_strategy : p_colPlayer->GetStrategies()) {

tests/test_io.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,12 @@ def test_write_efg_as_nfg():
101101

102102
def test_write_html():
103103
game = gbt.Game.new_table([2, 2])
104+
game.players[0].label = "Alice"
105+
game.players[1].label = "Bob"
104106
serialized_game = game.to_html()
105107
assert isinstance(serialized_game, str)
108+
assert "Alice" in serialized_game
109+
assert "Bob" in serialized_game
106110

107111

108112
def test_write_latex():

0 commit comments

Comments
 (0)