Repository: sotetsuk/pgx

Issue:
Backgammonの黒と白の色反転
黒と白の実装ロジックが逆になってしまっているので, visualizerで黒と白を逆にしていただく必要があります.


Discussion:

Resolving patch:
diff --git a/pgx/dwg/backgammon.py b/pgx/dwg/backgammon.py
--- a/pgx/dwg/backgammon.py
+++ b/pgx/dwg/backgammon.py
@@ -1,7 +1,9 @@
 from pgx.backgammon import State as BackgammonState
+from pgx.backgammon import get_abs_board
 
 
 def _make_backgammon_dwg(dwg, state: BackgammonState, config):
+    board = get_abs_board(state)
     BOARD_WIDTH = config["BOARD_WIDTH"]
     BOARD_HEIGHT = config["BOARD_HEIGHT"]
     GRID_SIZE = config["GRID_SIZE"]
@@ -74,7 +76,7 @@ def _make_backgammon_dwg(dwg, state: BackgammonState, config):
         )
 
     # pieces
-    for i, piece in enumerate(state.board[:24]):
+    for i, piece in enumerate(board[:24]):
         fill_color = color_set.p2_color
         if piece < 0:  # 白
             piece = -piece
@@ -101,36 +103,36 @@ def _make_backgammon_dwg(dwg, state: BackgammonState, config):
                     r=0.5 * GRID_SIZE,
                     stroke=color_set.grid_color,
                     fill=fill_color,
-                    # stroke_width=GRID_SIZE,
                 )
             )
 
     # bar
-    for i, piece in enumerate(state.board[24:26]):  # 24:白,25:黒
+    for i, piece in enumerate(board[24:26]):  # 24:黒, 25:白
         fill_color = color_set.p2_color
-        diff = 1
-        if i == 0:
+        delta = 1
+        offset = 0.5
+        if i == 1:
             piece = -piece
             fill_color = color_set.p1_color
-            diff = -1
+            delta = -1
+            offset = -0.5
         for n in range(piece):
             board_g.add(
                 dwg.circle(
                     center=(
                         6.5 * GRID_SIZE,
-                        (6 + i * 2 + n * diff) * GRID_SIZE,
+                        (7 + offset + n * delta) * GRID_SIZE,
                     ),
                     r=0.5 * GRID_SIZE,
                     stroke=color_set.grid_color,
                     fill=fill_color,
-                    # stroke_width=GRID_SIZE,
                 )
             )
 
     # off
     board_g.add(
         dwg.rect(
-            (13 * GRID_SIZE, 12 * GRID_SIZE),
+            (13 * GRID_SIZE, 0),
             (
                 4 * GRID_SIZE,
                 2 * GRID_SIZE,
@@ -141,18 +143,18 @@ def _make_backgammon_dwg(dwg, state: BackgammonState, config):
     )
     board_g.add(
         dwg.circle(
-            center=(14 * GRID_SIZE, 13 * GRID_SIZE),
+            center=(14 * GRID_SIZE, 1 * GRID_SIZE),
             r=0.5 * GRID_SIZE,
             stroke=color_set.grid_color,
-            fill=color_set.p1_color,
+            fill=color_set.p2_color,
         )
     )
     board_g.add(
         dwg.text(
-            text=f"× {-state.board[26]}",  # 26:白
+            text=f"× {board[26]}",  # 26:黒
             insert=(
                 14.8 * GRID_SIZE,
-                13.4 * GRID_SIZE,
+                1.4 * GRID_SIZE,
             ),
             fill=color_set.grid_color,
             font_size="34px",
@@ -162,7 +164,7 @@ def _make_backgammon_dwg(dwg, state: BackgammonState, config):
 
     board_g.add(
         dwg.rect(
-            (13 * GRID_SIZE, 0),
+            (13 * GRID_SIZE, 12 * GRID_SIZE),
             (
                 4 * GRID_SIZE,
                 2 * GRID_SIZE,
@@ -173,18 +175,18 @@ def _make_backgammon_dwg(dwg, state: BackgammonState, config):
     )
     board_g.add(
         dwg.circle(
-            center=(14 * GRID_SIZE, 1 * GRID_SIZE),
+            center=(14 * GRID_SIZE, 13 * GRID_SIZE),
             r=0.5 * GRID_SIZE,
             stroke=color_set.grid_color,
-            fill=color_set.p2_color,
+            fill=color_set.p1_color,
         )
     )
     board_g.add(
         dwg.text(
-            text=f"× {state.board[27]}",  # 27:黒
+            text=f"× {-board[27]}",  # 27:白
             insert=(
                 14.8 * GRID_SIZE,
-                1.4 * GRID_SIZE,
+                13.4 * GRID_SIZE,
             ),
             fill=color_set.grid_color,
             font_size="34px",


Test patch: