Update connect_four_game.py
Browse files- connect_four_game.py +14 -14
connect_four_game.py
CHANGED
|
@@ -111,27 +111,27 @@ class ConnectFour:
|
|
| 111 |
return score
|
| 112 |
|
| 113 |
def board_to_string(self) -> str:
|
| 114 |
-
'''
|
| 115 |
mapping = {0: '⚪', 1: '🔴', 2: '🟡'}
|
| 116 |
|
| 117 |
-
#
|
| 118 |
-
|
| 119 |
|
| 120 |
-
# Column
|
| 121 |
-
|
| 122 |
-
|
|
|
|
|
|
|
| 123 |
|
| 124 |
-
# Rows
|
| 125 |
-
rows_str = ""
|
| 126 |
for row in range(self.rows):
|
| 127 |
-
|
| 128 |
for col in range(self.cols):
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
rows_str += f"{mapping[self.board[row][col]]:^{cell_w}}"
|
| 132 |
-
rows_str += "\n"
|
| 133 |
|
| 134 |
-
|
|
|
|
| 135 |
|
| 136 |
|
| 137 |
def reset(self):
|
|
|
|
| 111 |
return score
|
| 112 |
|
| 113 |
def board_to_string(self) -> str:
|
| 114 |
+
'''HTML-rendered board with perfectly aligned columns'''
|
| 115 |
mapping = {0: '⚪', 1: '🔴', 2: '🟡'}
|
| 116 |
|
| 117 |
+
# Start HTML table
|
| 118 |
+
html = "<table style='border-collapse: collapse; margin: auto; text-align: center;'>"
|
| 119 |
|
| 120 |
+
# Column headers
|
| 121 |
+
html += "<tr><td></td>" # Empty corner cell for row labels
|
| 122 |
+
for i in range(self.cols):
|
| 123 |
+
html += f"<th style='padding:6px; color:#FFD700; font-weight:bold;'>{i}</th>"
|
| 124 |
+
html += "</tr>"
|
| 125 |
|
| 126 |
+
# Rows
|
|
|
|
| 127 |
for row in range(self.rows):
|
| 128 |
+
html += f"<tr><th style='padding:6px; color:#FFD700; font-weight:bold;'>{row}</th>"
|
| 129 |
for col in range(self.cols):
|
| 130 |
+
html += f"<td style='padding:6px; font-size:26px;'>{mapping[self.board[row][col]]}</td>"
|
| 131 |
+
html += "</tr>"
|
|
|
|
|
|
|
| 132 |
|
| 133 |
+
html += "</table>"
|
| 134 |
+
return html
|
| 135 |
|
| 136 |
|
| 137 |
def reset(self):
|