From d61f321903dc1db65b7564bcaacb29ac14bc11f5 Mon Sep 17 00:00:00 2001 From: youyou-ku Date: Thu, 8 Jun 2023 19:42:32 +0900 Subject: [PATCH 1/6] add without_check_repetition --- tests/assets/shogi/repetition_001.svg | 2 ++ tests/assets/shogi/repetition_002.svg | 2 ++ tests/assets/shogi/repetition_003.svg | 2 ++ tests/assets/shogi/repetition_004.svg | 2 ++ tests/assets/shogi/repetition_005.svg | 2 ++ tests/test_shogi.py | 36 +++++++++++++++++++++++++++ 6 files changed, 46 insertions(+) create mode 100644 tests/assets/shogi/repetition_001.svg create mode 100644 tests/assets/shogi/repetition_002.svg create mode 100644 tests/assets/shogi/repetition_003.svg create mode 100644 tests/assets/shogi/repetition_004.svg create mode 100644 tests/assets/shogi/repetition_005.svg diff --git a/tests/assets/shogi/repetition_001.svg b/tests/assets/shogi/repetition_001.svg new file mode 100644 index 000000000..91e3ff48c --- /dev/null +++ b/tests/assets/shogi/repetition_001.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_002.svg b/tests/assets/shogi/repetition_002.svg new file mode 100644 index 000000000..7fb414271 --- /dev/null +++ b/tests/assets/shogi/repetition_002.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_003.svg b/tests/assets/shogi/repetition_003.svg new file mode 100644 index 000000000..34b0bfce2 --- /dev/null +++ b/tests/assets/shogi/repetition_003.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_004.svg b/tests/assets/shogi/repetition_004.svg new file mode 100644 index 000000000..6e09ef306 --- /dev/null +++ b/tests/assets/shogi/repetition_004.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_005.svg b/tests/assets/shogi/repetition_005.svg new file mode 100644 index 000000000..91e3ff48c --- /dev/null +++ b/tests/assets/shogi/repetition_005.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/test_shogi.py b/tests/test_shogi.py index 94920d198..505efaaee 100644 --- a/tests/test_shogi.py +++ b/tests/test_shogi.py @@ -405,6 +405,42 @@ def test_sfen(): assert s._to_sfen() == sfen +def test_repetition(): + # without check + sfen = "l2+B2knl/1r4g2/2n1gpsp1/p1pps1p1p/1p5P1/P1P1SPP1P/1PSPP4/2G2G3/LNK4RL b Pbn 1" + s = State._from_sfen(sfen) + visualize(s, "tests/assets/shogi/repetition_001.svg") + dlshogi_action1 = 243 + 54 + s = step(s, dlshogi_action1) + visualize(s, "tests/assets/shogi/repetition_002.svg") + dlshogi_action2 = 243 + 43 + s = step(s, dlshogi_action2) + visualize(s, "tests/assets/shogi/repetition_003.svg") + dlshogi_action3 = 324 + 45 + s = step(s, dlshogi_action3) + visualize(s, "tests/assets/shogi/repetition_004.svg") + dlshogi_action4 = 324 + 16 + s = step(s, dlshogi_action4) + # 2 time + visualize(s, "tests/assets/shogi/repetition_005.svg") + s = step(s, dlshogi_action1) + s = step(s, dlshogi_action2) + s = step(s, dlshogi_action3) + s = step(s, dlshogi_action4) + # 3 time + s = step(s, dlshogi_action1) + s = step(s, dlshogi_action2) + s = step(s, dlshogi_action3) + s = step(s, dlshogi_action4) + # 4 time(draw) + assert s.terminated + assert s.rewards[0] == s.rewards[1] + + # with check repetition + + + + def test_api(): import pgx env = pgx.make("shogi") From c67bc74a7c7fbdb67e195b78862bb2d60f9d1a9e Mon Sep 17 00:00:00 2001 From: youyou-ku Date: Thu, 8 Jun 2023 20:38:22 +0900 Subject: [PATCH 2/6] add with_check_repetition --- tests/assets/shogi/repetition_006.svg | 2 + tests/assets/shogi/repetition_007.svg | 2 + tests/assets/shogi/repetition_008.svg | 2 + tests/assets/shogi/repetition_009.svg | 2 + tests/assets/shogi/repetition_010.svg | 2 + tests/assets/shogi/repetition_011.svg | 2 + tests/assets/shogi/repetition_012.svg | 2 + tests/assets/shogi/repetition_013.svg | 2 + tests/assets/shogi/repetition_014.svg | 2 + tests/assets/shogi/repetition_015.svg | 2 + tests/test_shogi.py | 73 ++++++++++++++++++++++++--- 11 files changed, 86 insertions(+), 7 deletions(-) create mode 100644 tests/assets/shogi/repetition_006.svg create mode 100644 tests/assets/shogi/repetition_007.svg create mode 100644 tests/assets/shogi/repetition_008.svg create mode 100644 tests/assets/shogi/repetition_009.svg create mode 100644 tests/assets/shogi/repetition_010.svg create mode 100644 tests/assets/shogi/repetition_011.svg create mode 100644 tests/assets/shogi/repetition_012.svg create mode 100644 tests/assets/shogi/repetition_013.svg create mode 100644 tests/assets/shogi/repetition_014.svg create mode 100644 tests/assets/shogi/repetition_015.svg diff --git a/tests/assets/shogi/repetition_006.svg b/tests/assets/shogi/repetition_006.svg new file mode 100644 index 000000000..d4cbcd6d3 --- /dev/null +++ b/tests/assets/shogi/repetition_006.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_007.svg b/tests/assets/shogi/repetition_007.svg new file mode 100644 index 000000000..f732e5e36 --- /dev/null +++ b/tests/assets/shogi/repetition_007.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_008.svg b/tests/assets/shogi/repetition_008.svg new file mode 100644 index 000000000..15a6ce013 --- /dev/null +++ b/tests/assets/shogi/repetition_008.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_009.svg b/tests/assets/shogi/repetition_009.svg new file mode 100644 index 000000000..9ecb67e98 --- /dev/null +++ b/tests/assets/shogi/repetition_009.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_010.svg b/tests/assets/shogi/repetition_010.svg new file mode 100644 index 000000000..d4cbcd6d3 --- /dev/null +++ b/tests/assets/shogi/repetition_010.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_011.svg b/tests/assets/shogi/repetition_011.svg new file mode 100644 index 000000000..b68f6e5fc --- /dev/null +++ b/tests/assets/shogi/repetition_011.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_012.svg b/tests/assets/shogi/repetition_012.svg new file mode 100644 index 000000000..cc4c4abe3 --- /dev/null +++ b/tests/assets/shogi/repetition_012.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_013.svg b/tests/assets/shogi/repetition_013.svg new file mode 100644 index 000000000..15b6612bd --- /dev/null +++ b/tests/assets/shogi/repetition_013.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_014.svg b/tests/assets/shogi/repetition_014.svg new file mode 100644 index 000000000..0e41abea3 --- /dev/null +++ b/tests/assets/shogi/repetition_014.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_015.svg b/tests/assets/shogi/repetition_015.svg new file mode 100644 index 000000000..b68f6e5fc --- /dev/null +++ b/tests/assets/shogi/repetition_015.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/test_shogi.py b/tests/test_shogi.py index 505efaaee..64ed97918 100644 --- a/tests/test_shogi.py +++ b/tests/test_shogi.py @@ -410,16 +410,16 @@ def test_repetition(): sfen = "l2+B2knl/1r4g2/2n1gpsp1/p1pps1p1p/1p5P1/P1P1SPP1P/1PSPP4/2G2G3/LNK4RL b Pbn 1" s = State._from_sfen(sfen) visualize(s, "tests/assets/shogi/repetition_001.svg") - dlshogi_action1 = 243 + 54 + dlshogi_action1 = 243 + 54 # 7一馬(6一) s = step(s, dlshogi_action1) visualize(s, "tests/assets/shogi/repetition_002.svg") - dlshogi_action2 = 243 + 43 + dlshogi_action2 = 243 + 43 # 5二飛(8二) s = step(s, dlshogi_action2) visualize(s, "tests/assets/shogi/repetition_003.svg") - dlshogi_action3 = 324 + 45 + dlshogi_action3 = 324 + 45 # 6一馬(7一) s = step(s, dlshogi_action3) visualize(s, "tests/assets/shogi/repetition_004.svg") - dlshogi_action4 = 324 + 16 + dlshogi_action4 = 324 + 16 # 8二飛(5二) s = step(s, dlshogi_action4) # 2 time visualize(s, "tests/assets/shogi/repetition_005.svg") @@ -433,10 +433,69 @@ def test_repetition(): s = step(s, dlshogi_action3) s = step(s, dlshogi_action4) # 4 time(draw) - assert s.terminated - assert s.rewards[0] == s.rewards[1] + #assert s.terminated + #assert s.rewards[0] == s.rewards[1] - # with check repetition + # with check repetition(not continuous check) + sfen = "ln7/1ksR5/ppp6/9/9/9/9/9/8K b Ss 1" + s = State._from_sfen(sfen) + visualize(s, "tests/assets/shogi/repetition_006.svg") + dlshogi_action1 = 1863 + 47 # 6三銀打 + s = step(s, dlshogi_action1) + visualize(s, "tests/assets/shogi/repetition_007.svg") + dlshogi_action2 = 1863 + 35 # 6一銀打 + s = step(s, dlshogi_action2) + visualize(s, "tests/assets/shogi/repetition_008.svg") + dlshogi_action3 = 891 + 55 # 7二銀成(6三) + s = step(s, dlshogi_action3) + visualize(s, "tests/assets/shogi/repetition_009.svg") + dlshogi_action4 = 162 + 25 # 7二銀(6一) + s = step(s, dlshogi_action4) + # 2 time + visualize(s, "tests/assets/shogi/repetition_010.svg") + s = step(s, dlshogi_action1) + s = step(s, dlshogi_action2) + s = step(s, dlshogi_action3) + s = step(s, dlshogi_action4) + # 3 time + s = step(s, dlshogi_action1) + s = step(s, dlshogi_action2) + s = step(s, dlshogi_action3) + s = step(s, dlshogi_action4) + # 4 time(draw) + #assert s.terminated + #assert s.rewards[0] == s.rewards[1] + + # with continuous check repetition + sfen = "8l/6+P2/6+Rpk/8p/9/7S1/9/9/8K b - 1" + s = State._from_sfen(sfen) + visualize(s, "tests/assets/shogi/repetition_011.svg") + dlshogi_action1 = 162 + 10 # 2二龍(3一) + s = step(s, dlshogi_action1) + visualize(s, "tests/assets/shogi/repetition_012.svg") + dlshogi_action2 = 162 + 68 # 2四王(1三) + s = step(s, dlshogi_action2) + visualize(s, "tests/assets/shogi/repetition_013.svg") + dlshogi_action3 = 486 + 20 # 3一龍(2二) + s = step(s, dlshogi_action3) + visualize(s, "tests/assets/shogi/repetition_014.svg") + dlshogi_action4 = 486 + 78 # 1三王(2四) + s = step(s, dlshogi_action4) + # 2 time + visualize(s, "tests/assets/shogi/repetition_015.svg") + s = step(s, dlshogi_action1) + s = step(s, dlshogi_action2) + s = step(s, dlshogi_action3) + s = step(s, dlshogi_action4) + # 3 time + s = step(s, dlshogi_action1) + s = step(s, dlshogi_action2) + s = step(s, dlshogi_action3) + s = step(s, dlshogi_action4) + # 4 time(draw) + # assert s.terminated + #assert s.rewards[s.current_player] == -1 + #assert s.rewards[1 - s.current_player] == 1. From d9c3737121bda2f1d6cfe1fe9f7059d365fa4fa9 Mon Sep 17 00:00:00 2001 From: youyou-ku Date: Thu, 8 Jun 2023 21:23:49 +0900 Subject: [PATCH 3/6] add dif turn/hands repetition --- tests/assets/shogi/repetition_016.svg | 2 + tests/assets/shogi/repetition_017.svg | 2 + tests/assets/shogi/repetition_018.svg | 2 + tests/assets/shogi/repetition_019.svg | 2 + tests/assets/shogi/repetition_020.svg | 2 + tests/assets/shogi/repetition_021.svg | 2 + tests/assets/shogi/repetition_022.svg | 2 + tests/assets/shogi/repetition_023.svg | 2 + tests/assets/shogi/repetition_024.svg | 2 + tests/assets/shogi/repetition_025.svg | 2 + tests/assets/shogi/repetition_026.svg | 2 + tests/assets/shogi/repetition_027.svg | 2 + tests/assets/shogi/repetition_028.svg | 2 + tests/assets/shogi/repetition_029.svg | 2 + tests/assets/shogi/repetition_030.svg | 2 + tests/assets/shogi/repetition_031.svg | 2 + tests/assets/shogi/repetition_032.svg | 2 + tests/assets/shogi/repetition_033.svg | 2 + tests/assets/shogi/repetition_034.svg | 2 + tests/assets/shogi/repetition_035.svg | 2 + tests/assets/shogi/repetition_036.svg | 2 + tests/assets/shogi/repetition_037.svg | 2 + tests/assets/shogi/repetition_038.svg | 2 + tests/assets/shogi/repetition_039.svg | 2 + tests/assets/shogi/repetition_040.svg | 2 + tests/assets/shogi/repetition_041.svg | 2 + tests/assets/shogi/repetition_042.svg | 2 + tests/test_shogi.py | 81 ++++++++++++++++++++++++++- 28 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 tests/assets/shogi/repetition_016.svg create mode 100644 tests/assets/shogi/repetition_017.svg create mode 100644 tests/assets/shogi/repetition_018.svg create mode 100644 tests/assets/shogi/repetition_019.svg create mode 100644 tests/assets/shogi/repetition_020.svg create mode 100644 tests/assets/shogi/repetition_021.svg create mode 100644 tests/assets/shogi/repetition_022.svg create mode 100644 tests/assets/shogi/repetition_023.svg create mode 100644 tests/assets/shogi/repetition_024.svg create mode 100644 tests/assets/shogi/repetition_025.svg create mode 100644 tests/assets/shogi/repetition_026.svg create mode 100644 tests/assets/shogi/repetition_027.svg create mode 100644 tests/assets/shogi/repetition_028.svg create mode 100644 tests/assets/shogi/repetition_029.svg create mode 100644 tests/assets/shogi/repetition_030.svg create mode 100644 tests/assets/shogi/repetition_031.svg create mode 100644 tests/assets/shogi/repetition_032.svg create mode 100644 tests/assets/shogi/repetition_033.svg create mode 100644 tests/assets/shogi/repetition_034.svg create mode 100644 tests/assets/shogi/repetition_035.svg create mode 100644 tests/assets/shogi/repetition_036.svg create mode 100644 tests/assets/shogi/repetition_037.svg create mode 100644 tests/assets/shogi/repetition_038.svg create mode 100644 tests/assets/shogi/repetition_039.svg create mode 100644 tests/assets/shogi/repetition_040.svg create mode 100644 tests/assets/shogi/repetition_041.svg create mode 100644 tests/assets/shogi/repetition_042.svg diff --git a/tests/assets/shogi/repetition_016.svg b/tests/assets/shogi/repetition_016.svg new file mode 100644 index 000000000..bd4d65167 --- /dev/null +++ b/tests/assets/shogi/repetition_016.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_017.svg b/tests/assets/shogi/repetition_017.svg new file mode 100644 index 000000000..4bdae27a3 --- /dev/null +++ b/tests/assets/shogi/repetition_017.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_018.svg b/tests/assets/shogi/repetition_018.svg new file mode 100644 index 000000000..6d76ed40b --- /dev/null +++ b/tests/assets/shogi/repetition_018.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_019.svg b/tests/assets/shogi/repetition_019.svg new file mode 100644 index 000000000..52d5ac04e --- /dev/null +++ b/tests/assets/shogi/repetition_019.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_020.svg b/tests/assets/shogi/repetition_020.svg new file mode 100644 index 000000000..82a29629a --- /dev/null +++ b/tests/assets/shogi/repetition_020.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_021.svg b/tests/assets/shogi/repetition_021.svg new file mode 100644 index 000000000..5b83fd1d7 --- /dev/null +++ b/tests/assets/shogi/repetition_021.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_022.svg b/tests/assets/shogi/repetition_022.svg new file mode 100644 index 000000000..7e2925f84 --- /dev/null +++ b/tests/assets/shogi/repetition_022.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_023.svg b/tests/assets/shogi/repetition_023.svg new file mode 100644 index 000000000..b246a202b --- /dev/null +++ b/tests/assets/shogi/repetition_023.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_024.svg b/tests/assets/shogi/repetition_024.svg new file mode 100644 index 000000000..299263582 --- /dev/null +++ b/tests/assets/shogi/repetition_024.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_025.svg b/tests/assets/shogi/repetition_025.svg new file mode 100644 index 000000000..d0a44972b --- /dev/null +++ b/tests/assets/shogi/repetition_025.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_026.svg b/tests/assets/shogi/repetition_026.svg new file mode 100644 index 000000000..152fb1430 --- /dev/null +++ b/tests/assets/shogi/repetition_026.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_027.svg b/tests/assets/shogi/repetition_027.svg new file mode 100644 index 000000000..24e390b0c --- /dev/null +++ b/tests/assets/shogi/repetition_027.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_028.svg b/tests/assets/shogi/repetition_028.svg new file mode 100644 index 000000000..2d0a21314 --- /dev/null +++ b/tests/assets/shogi/repetition_028.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_029.svg b/tests/assets/shogi/repetition_029.svg new file mode 100644 index 000000000..afc34d255 --- /dev/null +++ b/tests/assets/shogi/repetition_029.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_030.svg b/tests/assets/shogi/repetition_030.svg new file mode 100644 index 000000000..347fdfa3a --- /dev/null +++ b/tests/assets/shogi/repetition_030.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_031.svg b/tests/assets/shogi/repetition_031.svg new file mode 100644 index 000000000..02d2afdb7 --- /dev/null +++ b/tests/assets/shogi/repetition_031.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_032.svg b/tests/assets/shogi/repetition_032.svg new file mode 100644 index 000000000..587088816 --- /dev/null +++ b/tests/assets/shogi/repetition_032.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_033.svg b/tests/assets/shogi/repetition_033.svg new file mode 100644 index 000000000..2d0a21314 --- /dev/null +++ b/tests/assets/shogi/repetition_033.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_034.svg b/tests/assets/shogi/repetition_034.svg new file mode 100644 index 000000000..ac4a5bdeb --- /dev/null +++ b/tests/assets/shogi/repetition_034.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_035.svg b/tests/assets/shogi/repetition_035.svg new file mode 100644 index 000000000..2af6fb7e8 --- /dev/null +++ b/tests/assets/shogi/repetition_035.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_036.svg b/tests/assets/shogi/repetition_036.svg new file mode 100644 index 000000000..7ccc09e3d --- /dev/null +++ b/tests/assets/shogi/repetition_036.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_037.svg b/tests/assets/shogi/repetition_037.svg new file mode 100644 index 000000000..e008e4a2c --- /dev/null +++ b/tests/assets/shogi/repetition_037.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_038.svg b/tests/assets/shogi/repetition_038.svg new file mode 100644 index 000000000..2d0a21314 --- /dev/null +++ b/tests/assets/shogi/repetition_038.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_039.svg b/tests/assets/shogi/repetition_039.svg new file mode 100644 index 000000000..afc34d255 --- /dev/null +++ b/tests/assets/shogi/repetition_039.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_040.svg b/tests/assets/shogi/repetition_040.svg new file mode 100644 index 000000000..347fdfa3a --- /dev/null +++ b/tests/assets/shogi/repetition_040.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_041.svg b/tests/assets/shogi/repetition_041.svg new file mode 100644 index 000000000..02d2afdb7 --- /dev/null +++ b/tests/assets/shogi/repetition_041.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_042.svg b/tests/assets/shogi/repetition_042.svg new file mode 100644 index 000000000..587088816 --- /dev/null +++ b/tests/assets/shogi/repetition_042.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/test_shogi.py b/tests/test_shogi.py index 64ed97918..5036a3afe 100644 --- a/tests/test_shogi.py +++ b/tests/test_shogi.py @@ -492,11 +492,90 @@ def test_repetition(): s = step(s, dlshogi_action2) s = step(s, dlshogi_action3) s = step(s, dlshogi_action4) - # 4 time(draw) + # 4 time(white win) # assert s.terminated #assert s.rewards[s.current_player] == -1 #assert s.rewards[1 - s.current_player] == 1. + # different hands + sfen = "lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL b 8G 1" + s = State._from_sfen(sfen) + visualize(s, "tests/assets/shogi/repetition_016.svg") + dlshogi_action1 = 2106 + 37 # 5二金打 + s = step(s, dlshogi_action1) + visualize(s, "tests/assets/shogi/repetition_017.svg") + dlshogi_action2 = 243 + 43 # 52飛(82) + s = step(s, dlshogi_action2) + visualize(s, "tests/assets/shogi/repetition_018.svg") + dlshogi_action3 = 2106 + 64 # 82金打 + s = step(s, dlshogi_action3) + visualize(s, "tests/assets/shogi/repetition_019.svg") + dlshogi_action4 = 324 + 16 # 82飛(52) + s = step(s, dlshogi_action4) + # 2 time + visualize(s, "tests/assets/shogi/repetition_020.svg") + s = step(s, dlshogi_action1) + visualize(s, "tests/assets/shogi/repetition_021.svg") + s = step(s, dlshogi_action2) + visualize(s, "tests/assets/shogi/repetition_022.svg") + s = step(s, dlshogi_action3) + visualize(s, "tests/assets/shogi/repetition_023.svg") + s = step(s, dlshogi_action4) + visualize(s, "tests/assets/shogi/repetition_024.svg") + # 3 time + s = step(s, dlshogi_action1) + visualize(s, "tests/assets/shogi/repetition_025.svg") + s = step(s, dlshogi_action2) + visualize(s, "tests/assets/shogi/repetition_026.svg") + s = step(s, dlshogi_action3) + visualize(s, "tests/assets/shogi/repetition_027.svg") + s = step(s, dlshogi_action4) + # 4 time(not repetition) + assert not s.terminated + + # different turn + sfen = "lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL b - 1" + s = State._from_sfen(sfen) + visualize(s, "tests/assets/shogi/repetition_028.svg") + dlshogi_action1 = 243 + 34 # 48飛(28) + s = step(s, dlshogi_action1) + visualize(s, "tests/assets/shogi/repetition_029.svg") + dlshogi_action2 = 324 + 7 # 92飛(82) + s = step(s, dlshogi_action2) + visualize(s, "tests/assets/shogi/repetition_030.svg") + dlshogi_action3 = 324 + 25 # 38飛(48) + s = step(s, dlshogi_action3) + visualize(s, "tests/assets/shogi/repetition_031.svg") + dlshogi_action4 = 243 + 16 # 82飛(92) + s = step(s, dlshogi_action4) + visualize(s, "tests/assets/shogi/repetition_032.svg") + dlshogi_action5 = 324 + 16 # 38飛(28) + s = step(s, dlshogi_action5) + # 2 time + visualize(s, "tests/assets/shogi/repetition_033.svg") + s = step(s, dlshogi_action1) + visualize(s, "tests/assets/shogi/repetition_034.svg") + s = step(s, dlshogi_action2) + visualize(s, "tests/assets/shogi/repetition_035.svg") + s = step(s, dlshogi_action3) + visualize(s, "tests/assets/shogi/repetition_036.svg") + s = step(s, dlshogi_action4) + visualize(s, "tests/assets/shogi/repetition_037.svg") + s = step(s, dlshogi_action5) + visualize(s, "tests/assets/shogi/repetition_038.svg") + # 3 time + s = step(s, dlshogi_action1) + visualize(s, "tests/assets/shogi/repetition_039.svg") + s = step(s, dlshogi_action2) + visualize(s, "tests/assets/shogi/repetition_040.svg") + s = step(s, dlshogi_action3) + visualize(s, "tests/assets/shogi/repetition_041.svg") + s = step(s, dlshogi_action4) + visualize(s, "tests/assets/shogi/repetition_042.svg") + s = step(s, dlshogi_action5) + # 4 time (not repetition) + assert not s.terminated + From e0c2f71348c05ef0c1141b0a56078d79af1c7738 Mon Sep 17 00:00:00 2001 From: youyou-ku Date: Mon, 12 Jun 2023 20:00:50 +0900 Subject: [PATCH 4/6] add 3 tests --- tests/assets/shogi/repetition_043.svg | 2 + tests/assets/shogi/repetition_044.svg | 2 + tests/assets/shogi/repetition_045.svg | 2 + tests/assets/shogi/repetition_046.svg | 2 + tests/assets/shogi/repetition_047.svg | 2 + tests/assets/shogi/repetition_048.svg | 2 + tests/assets/shogi/repetition_049.svg | 2 + tests/assets/shogi/repetition_050.svg | 2 + tests/assets/shogi/repetition_051.svg | 2 + tests/assets/shogi/repetition_052.svg | 2 + tests/assets/shogi/repetition_053.svg | 2 + tests/assets/shogi/repetition_054.svg | 2 + tests/assets/shogi/repetition_055.svg | 2 + tests/assets/shogi/repetition_056.svg | 2 + tests/assets/shogi/repetition_057.svg | 2 + tests/assets/shogi/repetition_058.svg | 2 + tests/assets/shogi/repetition_059.svg | 2 + tests/assets/shogi/repetition_060.svg | 2 + tests/assets/shogi/repetition_061.svg | 2 + tests/assets/shogi/repetition_062.svg | 2 + tests/assets/shogi/repetition_063.svg | 2 + tests/test_shogi.py | 122 +++++++++++++++++++++++++- 22 files changed, 163 insertions(+), 1 deletion(-) create mode 100644 tests/assets/shogi/repetition_043.svg create mode 100644 tests/assets/shogi/repetition_044.svg create mode 100644 tests/assets/shogi/repetition_045.svg create mode 100644 tests/assets/shogi/repetition_046.svg create mode 100644 tests/assets/shogi/repetition_047.svg create mode 100644 tests/assets/shogi/repetition_048.svg create mode 100644 tests/assets/shogi/repetition_049.svg create mode 100644 tests/assets/shogi/repetition_050.svg create mode 100644 tests/assets/shogi/repetition_051.svg create mode 100644 tests/assets/shogi/repetition_052.svg create mode 100644 tests/assets/shogi/repetition_053.svg create mode 100644 tests/assets/shogi/repetition_054.svg create mode 100644 tests/assets/shogi/repetition_055.svg create mode 100644 tests/assets/shogi/repetition_056.svg create mode 100644 tests/assets/shogi/repetition_057.svg create mode 100644 tests/assets/shogi/repetition_058.svg create mode 100644 tests/assets/shogi/repetition_059.svg create mode 100644 tests/assets/shogi/repetition_060.svg create mode 100644 tests/assets/shogi/repetition_061.svg create mode 100644 tests/assets/shogi/repetition_062.svg create mode 100644 tests/assets/shogi/repetition_063.svg diff --git a/tests/assets/shogi/repetition_043.svg b/tests/assets/shogi/repetition_043.svg new file mode 100644 index 000000000..838bf41bd --- /dev/null +++ b/tests/assets/shogi/repetition_043.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_044.svg b/tests/assets/shogi/repetition_044.svg new file mode 100644 index 000000000..8d9e93bb4 --- /dev/null +++ b/tests/assets/shogi/repetition_044.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_045.svg b/tests/assets/shogi/repetition_045.svg new file mode 100644 index 000000000..8298ff6b7 --- /dev/null +++ b/tests/assets/shogi/repetition_045.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_046.svg b/tests/assets/shogi/repetition_046.svg new file mode 100644 index 000000000..555746d24 --- /dev/null +++ b/tests/assets/shogi/repetition_046.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_047.svg b/tests/assets/shogi/repetition_047.svg new file mode 100644 index 000000000..4d3c01312 --- /dev/null +++ b/tests/assets/shogi/repetition_047.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_048.svg b/tests/assets/shogi/repetition_048.svg new file mode 100644 index 000000000..838bf41bd --- /dev/null +++ b/tests/assets/shogi/repetition_048.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_049.svg b/tests/assets/shogi/repetition_049.svg new file mode 100644 index 000000000..4895638c8 --- /dev/null +++ b/tests/assets/shogi/repetition_049.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_050.svg b/tests/assets/shogi/repetition_050.svg new file mode 100644 index 000000000..209444ab3 --- /dev/null +++ b/tests/assets/shogi/repetition_050.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_051.svg b/tests/assets/shogi/repetition_051.svg new file mode 100644 index 000000000..6f894f8bf --- /dev/null +++ b/tests/assets/shogi/repetition_051.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_052.svg b/tests/assets/shogi/repetition_052.svg new file mode 100644 index 000000000..1264f61fc --- /dev/null +++ b/tests/assets/shogi/repetition_052.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_053.svg b/tests/assets/shogi/repetition_053.svg new file mode 100644 index 000000000..838bf41bd --- /dev/null +++ b/tests/assets/shogi/repetition_053.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_054.svg b/tests/assets/shogi/repetition_054.svg new file mode 100644 index 000000000..24ced495f --- /dev/null +++ b/tests/assets/shogi/repetition_054.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_055.svg b/tests/assets/shogi/repetition_055.svg new file mode 100644 index 000000000..1a1955cc6 --- /dev/null +++ b/tests/assets/shogi/repetition_055.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_056.svg b/tests/assets/shogi/repetition_056.svg new file mode 100644 index 000000000..b3c97ffff --- /dev/null +++ b/tests/assets/shogi/repetition_056.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_057.svg b/tests/assets/shogi/repetition_057.svg new file mode 100644 index 000000000..e7efec12b --- /dev/null +++ b/tests/assets/shogi/repetition_057.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_058.svg b/tests/assets/shogi/repetition_058.svg new file mode 100644 index 000000000..24ced495f --- /dev/null +++ b/tests/assets/shogi/repetition_058.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_059.svg b/tests/assets/shogi/repetition_059.svg new file mode 100644 index 000000000..b31ef2237 --- /dev/null +++ b/tests/assets/shogi/repetition_059.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_060.svg b/tests/assets/shogi/repetition_060.svg new file mode 100644 index 000000000..614e53cbc --- /dev/null +++ b/tests/assets/shogi/repetition_060.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_061.svg b/tests/assets/shogi/repetition_061.svg new file mode 100644 index 000000000..eeb99abfa --- /dev/null +++ b/tests/assets/shogi/repetition_061.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_062.svg b/tests/assets/shogi/repetition_062.svg new file mode 100644 index 000000000..cbc9d6711 --- /dev/null +++ b/tests/assets/shogi/repetition_062.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_063.svg b/tests/assets/shogi/repetition_063.svg new file mode 100644 index 000000000..b31ef2237 --- /dev/null +++ b/tests/assets/shogi/repetition_063.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/test_shogi.py b/tests/test_shogi.py index 5036a3afe..4b1f07174 100644 --- a/tests/test_shogi.py +++ b/tests/test_shogi.py @@ -498,7 +498,7 @@ def test_repetition(): #assert s.rewards[1 - s.current_player] == 1. # different hands - sfen = "lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL b 8G 1" + sfen = "lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL b 8G 1" s = State._from_sfen(sfen) visualize(s, "tests/assets/shogi/repetition_016.svg") dlshogi_action1 = 2106 + 37 # 5二金打 @@ -576,6 +576,126 @@ def test_repetition(): # 4 time (not repetition) assert not s.terminated + sfen = "4k4/3r5/9/4p4/9/3P5/9/4R4/4K4 b Pp 1" + s = State._from_sfen(sfen) + visualize(s, "tests/assets/shogi/repetition_043.svg") + dlshogi_action1 = 1620 + 40 # 55歩 + s = step(s, dlshogi_action1) + visualize(s, "tests/assets/shogi/repetition_044.svg") + dlshogi_action2 = 0 + 40 + s = step(s, dlshogi_action2) + visualize(s, "tests/assets/shogi/repetition_045.svg") + dlshogi_action3 = 0 + 40 + s = step(s, dlshogi_action3) + visualize(s, "tests/assets/shogi/repetition_046.svg") + dlshogi_action4 = 1620 + 41 + s = step(s, dlshogi_action4) + visualize(s, "tests/assets/shogi/repetition_047.svg") + dlshogi_action5 = 405 + 43 + s = step(s, dlshogi_action5) + visualize(s, "tests/assets/shogi/repetition_048.svg") + # 2 time + dlshogi_action6 = 1620 + 31 + s = step(s, dlshogi_action6) + visualize(s, "tests/assets/shogi/repetition_049.svg") + dlshogi_action7 = 0 + 49 + s = step(s, dlshogi_action7) + visualize(s, "tests/assets/shogi/repetition_050.svg") + dlshogi_action8 = 0 + 31 + s = step(s, dlshogi_action8) + visualize(s, "tests/assets/shogi/repetition_051.svg") + dlshogi_action9 = 1620 + 50 + s = step(s, dlshogi_action9) + visualize(s, "tests/assets/shogi/repetition_052.svg") + dlshogi_action10 = 405 + 34 + s = step(s, dlshogi_action10) + visualize(s, "tests/assets/shogi/repetition_053.svg") + # 3 time + s = step(s, dlshogi_action1) + s = step(s, dlshogi_action2) + s = step(s, dlshogi_action3) + s = step(s, dlshogi_action4) + s = step(s, dlshogi_action5) + # 4 time + assert not s.terminated + s = step(s, dlshogi_action6) + s = step(s, dlshogi_action7) + s = step(s, dlshogi_action8) + s = step(s, dlshogi_action9) + s = step(s, dlshogi_action10) + assert not s.terminated + s = step(s, dlshogi_action1) + s = step(s, dlshogi_action2) + s = step(s, dlshogi_action3) + s = step(s, dlshogi_action4) + s = step(s, dlshogi_action5) + assert not s.terminated + s = step(s, dlshogi_action6) + s = step(s, dlshogi_action7) + s = step(s, dlshogi_action8) + s = step(s, dlshogi_action9) + s = step(s, dlshogi_action10) + # assert s.terminated + + sfen = "4k4/2G3+RG1/9/9/9/9/9/9/4K4 b - 1" + s = State._from_sfen(sfen) + visualize(s, "tests/assets/shogi/repetition_054.svg") + dlshogi_action1 = 243 + 46 # 55歩 + s = step(s, dlshogi_action1) + visualize(s, "tests/assets/shogi/repetition_055.svg") + dlshogi_action2 = 243 + 53 + s = step(s, dlshogi_action2) + visualize(s, "tests/assets/shogi/repetition_056.svg") + dlshogi_action3 = 324 + 19 + s = step(s, dlshogi_action3) + visualize(s, "tests/assets/shogi/repetition_057.svg") + dlshogi_action4 = 324 + 44 + s = step(s, dlshogi_action4) + visualize(s, "tests/assets/shogi/repetition_058.svg") + # 2 time + assert not s.terminated + s = step(s, dlshogi_action1) + s = step(s, dlshogi_action2) + s = step(s, dlshogi_action3) + s = step(s, dlshogi_action4) + # 3 time + assert not s.terminated + s = step(s, dlshogi_action1) + s = step(s, dlshogi_action2) + s = step(s, dlshogi_action3) + s = step(s, dlshogi_action4) + # 4 time + # assert s.terminated + + sfen = "3sk4/4s4/5S3/4R4/9/9/9/9/8K b - 1" + s = State._from_sfen(sfen) + visualize(s, "tests/assets/shogi/repetition_059.svg") + dlshogi_action1 = 891 + 37 + s = step(s, dlshogi_action1) + visualize(s, "tests/assets/shogi/repetition_060.svg") + dlshogi_action2 = 81 + 43 + s = step(s, dlshogi_action2) + visualize(s, "tests/assets/shogi/repetition_061.svg") + dlshogi_action3 = 1863 + 29 + s = step(s, dlshogi_action3) + visualize(s, "tests/assets/shogi/repetition_062.svg") + dlshogi_action4 = 1863 + 35 + s = step(s, dlshogi_action4) + # 2 time + visualize(s, "tests/assets/shogi/repetition_063.svg") + s = step(s, dlshogi_action1) + s = step(s, dlshogi_action2) + s = step(s, dlshogi_action3) + s = step(s, dlshogi_action4) + # 3 time + s = step(s, dlshogi_action1) + s = step(s, dlshogi_action2) + s = step(s, dlshogi_action3) + s = step(s, dlshogi_action4) + # 4 time(draw) + # assert s.terminated + # assert s.rewards[0] == s.rewards[1] + From 85c654f4ecc37a0bd0775cc7275a4e32d4d80de9 Mon Sep 17 00:00:00 2001 From: youyou-ku Date: Mon, 12 Jun 2023 21:03:56 +0900 Subject: [PATCH 5/6] add tests --- tests/assets/shogi/repetition_064.svg | 2 + tests/assets/shogi/repetition_065.svg | 2 + tests/assets/shogi/repetition_066.svg | 2 + tests/assets/shogi/repetition_067.svg | 2 + tests/assets/shogi/repetition_068.svg | 2 + tests/assets/shogi/repetition_069.svg | 2 + tests/assets/shogi/repetition_070.svg | 2 + tests/assets/shogi/repetition_071.svg | 2 + tests/assets/shogi/repetition_072.svg | 2 + tests/assets/shogi/repetition_073.svg | 2 + tests/assets/shogi/repetition_074.svg | 2 + tests/assets/shogi/repetition_075.svg | 2 + tests/assets/shogi/repetition_076.svg | 2 + tests/assets/shogi/repetition_077.svg | 2 + tests/test_shogi.py | 75 +++++++++++++++++++++++++++ 15 files changed, 103 insertions(+) create mode 100644 tests/assets/shogi/repetition_064.svg create mode 100644 tests/assets/shogi/repetition_065.svg create mode 100644 tests/assets/shogi/repetition_066.svg create mode 100644 tests/assets/shogi/repetition_067.svg create mode 100644 tests/assets/shogi/repetition_068.svg create mode 100644 tests/assets/shogi/repetition_069.svg create mode 100644 tests/assets/shogi/repetition_070.svg create mode 100644 tests/assets/shogi/repetition_071.svg create mode 100644 tests/assets/shogi/repetition_072.svg create mode 100644 tests/assets/shogi/repetition_073.svg create mode 100644 tests/assets/shogi/repetition_074.svg create mode 100644 tests/assets/shogi/repetition_075.svg create mode 100644 tests/assets/shogi/repetition_076.svg create mode 100644 tests/assets/shogi/repetition_077.svg diff --git a/tests/assets/shogi/repetition_064.svg b/tests/assets/shogi/repetition_064.svg new file mode 100644 index 000000000..68cfbd1c1 --- /dev/null +++ b/tests/assets/shogi/repetition_064.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_065.svg b/tests/assets/shogi/repetition_065.svg new file mode 100644 index 000000000..c56de99fd --- /dev/null +++ b/tests/assets/shogi/repetition_065.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_066.svg b/tests/assets/shogi/repetition_066.svg new file mode 100644 index 000000000..1c0ce4001 --- /dev/null +++ b/tests/assets/shogi/repetition_066.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_067.svg b/tests/assets/shogi/repetition_067.svg new file mode 100644 index 000000000..3e070f70a --- /dev/null +++ b/tests/assets/shogi/repetition_067.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_068.svg b/tests/assets/shogi/repetition_068.svg new file mode 100644 index 000000000..218cb0597 --- /dev/null +++ b/tests/assets/shogi/repetition_068.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_069.svg b/tests/assets/shogi/repetition_069.svg new file mode 100644 index 000000000..c9cf8ebed --- /dev/null +++ b/tests/assets/shogi/repetition_069.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_070.svg b/tests/assets/shogi/repetition_070.svg new file mode 100644 index 000000000..68cfbd1c1 --- /dev/null +++ b/tests/assets/shogi/repetition_070.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_071.svg b/tests/assets/shogi/repetition_071.svg new file mode 100644 index 000000000..c4d4941f8 --- /dev/null +++ b/tests/assets/shogi/repetition_071.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_072.svg b/tests/assets/shogi/repetition_072.svg new file mode 100644 index 000000000..02a66e1e5 --- /dev/null +++ b/tests/assets/shogi/repetition_072.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_073.svg b/tests/assets/shogi/repetition_073.svg new file mode 100644 index 000000000..8acde1760 --- /dev/null +++ b/tests/assets/shogi/repetition_073.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_074.svg b/tests/assets/shogi/repetition_074.svg new file mode 100644 index 000000000..799d64b54 --- /dev/null +++ b/tests/assets/shogi/repetition_074.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_075.svg b/tests/assets/shogi/repetition_075.svg new file mode 100644 index 000000000..71adcff2a --- /dev/null +++ b/tests/assets/shogi/repetition_075.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_076.svg b/tests/assets/shogi/repetition_076.svg new file mode 100644 index 000000000..a0852e644 --- /dev/null +++ b/tests/assets/shogi/repetition_076.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_077.svg b/tests/assets/shogi/repetition_077.svg new file mode 100644 index 000000000..8acde1760 --- /dev/null +++ b/tests/assets/shogi/repetition_077.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/test_shogi.py b/tests/test_shogi.py index 4b1f07174..3922800b8 100644 --- a/tests/test_shogi.py +++ b/tests/test_shogi.py @@ -666,6 +666,8 @@ def test_repetition(): s = step(s, dlshogi_action4) # 4 time # assert s.terminated + # assert s.rewards[s.current_player] == -1 + # assert s.rewards[1 - s.current_player] == 1. sfen = "3sk4/4s4/5S3/4R4/9/9/9/9/8K b - 1" s = State._from_sfen(sfen) @@ -696,6 +698,79 @@ def test_repetition(): # assert s.terminated # assert s.rewards[0] == s.rewards[1] + sfen = "r3k4/9/9/9/9/9/9/9/4K3R b - 1" + s = State._from_sfen(sfen) + visualize(s, "tests/assets/shogi/repetition_064.svg") + dlshogi_action1 = 7 + s = step(s, dlshogi_action1) + visualize(s, "tests/assets/shogi/repetition_065.svg") + s = step(s, dlshogi_action1) + visualize(s, "tests/assets/shogi/repetition_066.svg") + dlshogi_action2 = 6 + s = step(s, dlshogi_action2) + visualize(s, "tests/assets/shogi/repetition_067.svg") + s = step(s, dlshogi_action2) + visualize(s, "tests/assets/shogi/repetition_068.svg") + dlshogi_action3 = 405 + 8 + s = step(s, dlshogi_action3) + visualize(s, "tests/assets/shogi/repetition_069.svg") + s = step(s, dlshogi_action3) + # 2 time + visualize(s, "tests/assets/shogi/repetition_070.svg") + assert not s.terminated + s = step(s, dlshogi_action1) + s = step(s, dlshogi_action1) + s = step(s, dlshogi_action2) + s = step(s, dlshogi_action2) + s = step(s, dlshogi_action3) + s = step(s, dlshogi_action3) + # 3 time + assert not s.terminated + s = step(s, dlshogi_action1) + s = step(s, dlshogi_action1) + s = step(s, dlshogi_action2) + s = step(s, dlshogi_action2) + s = step(s, dlshogi_action3) + s = step(s, dlshogi_action3) + # 4 time + # assert s.terminated + + sfen = "1r2k4/9/9/9/9/9/9/9/4K3R b - 1" + s = State._from_sfen(sfen) + visualize(s, "tests/assets/shogi/repetition_071.svg") + dlshogi_action1 = 810 + 1 + s = step(s, dlshogi_action1) + visualize(s, "tests/assets/shogi/repetition_072.svg") + dlshogi_action2 = 810 + 10 + s = step(s, dlshogi_action2) + visualize(s, "tests/assets/shogi/repetition_073.svg") + dlshogi_action3 = 405 + 8 + s = step(s, dlshogi_action3) + visualize(s, "tests/assets/shogi/repetition_074.svg") + dlshogi_action4 = 405 + 17 + s = step(s, dlshogi_action4) + # 2 time(駒成り含) + visualize(s, "tests/assets/shogi/repetition_075.svg") + dlshogi_action5 = 1 + s = step(s, dlshogi_action5) + visualize(s, "tests/assets/shogi/repetition_076.svg") + dlshogi_action6 = 10 + s = step(s, dlshogi_action6) + # 2 time + visualize(s, "tests/assets/shogi/repetition_077.svg") + s = step(s, dlshogi_action3) + s = step(s, dlshogi_action4) + s = step(s, dlshogi_action5) + s = step(s, dlshogi_action6) + s = step(s, dlshogi_action3) + s = step(s, dlshogi_action4) + assert not s.terminated + s = step(s, dlshogi_action5) + s = step(s, dlshogi_action6) + # 4 time + # assert s.terminated + + From bf02a2dd395892605dcce40b888ede968dc55404 Mon Sep 17 00:00:00 2001 From: youyou-ku Date: Mon, 12 Jun 2023 21:36:38 +0900 Subject: [PATCH 6/6] add tests --- tests/assets/shogi/repetition_078.svg | 2 + tests/assets/shogi/repetition_079.svg | 2 + tests/assets/shogi/repetition_080.svg | 2 + tests/assets/shogi/repetition_081.svg | 2 + tests/assets/shogi/repetition_082.svg | 2 + tests/assets/shogi/repetition_083.svg | 2 + tests/assets/shogi/repetition_084.svg | 2 + tests/assets/shogi/repetition_085.svg | 2 + tests/assets/shogi/repetition_086.svg | 2 + tests/assets/shogi/repetition_087.svg | 2 + tests/test_shogi.py | 55 ++++++++++++++++++++++++++- 11 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 tests/assets/shogi/repetition_078.svg create mode 100644 tests/assets/shogi/repetition_079.svg create mode 100644 tests/assets/shogi/repetition_080.svg create mode 100644 tests/assets/shogi/repetition_081.svg create mode 100644 tests/assets/shogi/repetition_082.svg create mode 100644 tests/assets/shogi/repetition_083.svg create mode 100644 tests/assets/shogi/repetition_084.svg create mode 100644 tests/assets/shogi/repetition_085.svg create mode 100644 tests/assets/shogi/repetition_086.svg create mode 100644 tests/assets/shogi/repetition_087.svg diff --git a/tests/assets/shogi/repetition_078.svg b/tests/assets/shogi/repetition_078.svg new file mode 100644 index 000000000..a60ef9cef --- /dev/null +++ b/tests/assets/shogi/repetition_078.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_079.svg b/tests/assets/shogi/repetition_079.svg new file mode 100644 index 000000000..821e7affa --- /dev/null +++ b/tests/assets/shogi/repetition_079.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_080.svg b/tests/assets/shogi/repetition_080.svg new file mode 100644 index 000000000..3b363115a --- /dev/null +++ b/tests/assets/shogi/repetition_080.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_081.svg b/tests/assets/shogi/repetition_081.svg new file mode 100644 index 000000000..67ac2efa2 --- /dev/null +++ b/tests/assets/shogi/repetition_081.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_082.svg b/tests/assets/shogi/repetition_082.svg new file mode 100644 index 000000000..a60ef9cef --- /dev/null +++ b/tests/assets/shogi/repetition_082.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_083.svg b/tests/assets/shogi/repetition_083.svg new file mode 100644 index 000000000..1aee4d7c2 --- /dev/null +++ b/tests/assets/shogi/repetition_083.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_084.svg b/tests/assets/shogi/repetition_084.svg new file mode 100644 index 000000000..56baa291c --- /dev/null +++ b/tests/assets/shogi/repetition_084.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_085.svg b/tests/assets/shogi/repetition_085.svg new file mode 100644 index 000000000..d479e8951 --- /dev/null +++ b/tests/assets/shogi/repetition_085.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_086.svg b/tests/assets/shogi/repetition_086.svg new file mode 100644 index 000000000..654ae1529 --- /dev/null +++ b/tests/assets/shogi/repetition_086.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/assets/shogi/repetition_087.svg b/tests/assets/shogi/repetition_087.svg new file mode 100644 index 000000000..1aee4d7c2 --- /dev/null +++ b/tests/assets/shogi/repetition_087.svg @@ -0,0 +1,2 @@ + +123456789 \ No newline at end of file diff --git a/tests/test_shogi.py b/tests/test_shogi.py index 3922800b8..15adc6ea5 100644 --- a/tests/test_shogi.py +++ b/tests/test_shogi.py @@ -770,8 +770,61 @@ def test_repetition(): # 4 time # assert s.terminated + sfen = "9/9/9/9/9/9/K8/1G7/k8 b - 1" + s = State._from_sfen(sfen) + visualize(s, "tests/assets/shogi/repetition_078.svg") + dlshogi_action1 = 243 + 79 + s = step(s, dlshogi_action1) + visualize(s, "tests/assets/shogi/repetition_079.svg") + dlshogi_action2 = 243 + 9 + s = step(s, dlshogi_action2) + visualize(s, "tests/assets/shogi/repetition_080.svg") + dlshogi_action3 = 324 + 70 + s = step(s, dlshogi_action3) + visualize(s, "tests/assets/shogi/repetition_081.svg") + dlshogi_action4 = 324 + s = step(s, dlshogi_action4) + visualize(s, "tests/assets/shogi/repetition_082.svg") + s = step(s, dlshogi_action1) + s = step(s, dlshogi_action2) + s = step(s, dlshogi_action3) + s = step(s, dlshogi_action4) + s = step(s, dlshogi_action1) + s = step(s, dlshogi_action2) + s = step(s, dlshogi_action3) + s = step(s, dlshogi_action4) + # 4 time + # assert s.terminated + # assert s.rewards[s.current_player] == -1 + # assert s.rewards[1 - s.current_player] == 1. - + sfen = "8K/7g1/8k/9/9/9/9/9/9 w - 1" + s = State._from_sfen(sfen) + visualize(s, "tests/assets/shogi/repetition_083.svg") + dlshogi_action1 = 243 + 79 + s = step(s, dlshogi_action1) + visualize(s, "tests/assets/shogi/repetition_084.svg") + dlshogi_action2 = 243 + 9 + s = step(s, dlshogi_action2) + visualize(s, "tests/assets/shogi/repetition_085.svg") + dlshogi_action3 = 324 + 70 + s = step(s, dlshogi_action3) + visualize(s, "tests/assets/shogi/repetition_086.svg") + dlshogi_action4 = 324 + s = step(s, dlshogi_action4) + visualize(s, "tests/assets/shogi/repetition_087.svg") + s = step(s, dlshogi_action1) + s = step(s, dlshogi_action2) + s = step(s, dlshogi_action3) + s = step(s, dlshogi_action4) + s = step(s, dlshogi_action1) + s = step(s, dlshogi_action2) + s = step(s, dlshogi_action3) + s = step(s, dlshogi_action4) + # 4 time + # assert s.terminated + # assert s.rewards[s.current_player] == -1 + # assert s.rewards[1 - s.current_player] == 1. def test_api():