Shogi Perft numbers

Discussion of chess software programming and technical issues.

Moderators: bob, hgm, Harvey Williamson

Forum rules
This textbox is used to restore diagrams posted with the [d] tag before the upgrade.
JohnWoe
Posts: 92
Joined: Sat Mar 02, 2013 10:31 pm

Shogi Perft numbers

Post by JohnWoe » Wed Aug 14, 2019 11:23 pm

My engine RubyShogi seems to get startpos perft numbers correct per se: http://tonyjh.com/chess/technical/
I wrote a random position generator to see whether RubyShogi gets all perft numbers correct?
At least RubyShogi plays under Xboard w/o issues.

Code: Select all

~~~ suite( 5 ) ~~~
0: 1 | 0.0s | 1 nps | ok
1: 30 | 0.001s | 22666 nps | ok
2: 900 | 0.044s | 20438 nps | ok
3: 25470 | 1.088s | 23420 nps | ok
4: 719731 | 33.952s | 21198 nps | ok
5: 19861490 | 824.894s | 24077 nps | ok
= 20607622 | 859.978s | 23962 nps

Code: Select all

~~~ perft( 2 ) ~~~
[ fen: 5k3/b8/1n5G1/1B2l+R2+P/+S4K1+NK/7G1/9/9/8K[LSGnps] w 0 1 ]
0: 1 | 0.0s | 1 nps
1: 244 | 0.007s | 32551 nps
2: 1026 | 0.601s | 1706 nps
= 1271 | 0.609s | 2087 nps

Code: Select all

~~~ perft( 2 ) ~~~
[ fen: 2k6/L8/+b6p1/+b1+b2+n2P/5P1s+N/9/9/7K1/9[LPPpsn] w 0 1 ]
0: 1 | 0.0s | 1 nps
1: 171 | 0.009s | 19936 nps
2: 38191 | 1.093s | 34939 nps
= 38363 | 1.102s | 34823 nps

Code: Select all

~~~ perft( 2 ) ~~~
[ fen: 5k3/+n8/1G5R1/2+s+P3b1/n+s2l+B+N2/5s+prp/9/7K1/9[SPGnpn] w 0 1 ]
0: 1 | 0.0s | 1 nps
1: 235 | 0.01s | 24406 nps
2: 43506 | 1.82s | 23899 nps
= 43742 | 1.83s | 23902 nps

Code: Select all

~~~ perft( 2 ) ~~~
[ fen: 9/+l4k3/+P1+r2L1+l1/+l3+B2S1/1n5rR/5+l+l2/9/9/1K7[LGNpgl] w 0 1 ]
0: 1 | 0.0s | 1 nps
1: 214 | 0.009s | 23151 nps
2: 1066 | 0.552s | 1929 nps
= 1281 | 0.562s | 2280 nps

Ferdy
Posts: 4077
Joined: Sun Aug 10, 2008 1:15 pm
Location: Philippines

Re: Shogi Perft numbers

Post by Ferdy » Thu Aug 15, 2019 3:21 am

JohnWoe wrote:
Wed Aug 14, 2019 11:23 pm
My engine RubyShogi seems to get startpos perft numbers correct per se: http://tonyjh.com/chess/technical/
I wrote a random position generator to see whether RubyShogi gets all perft numbers correct?
At least RubyShogi plays under Xboard w/o issues.

Code: Select all

~~~ suite( 5 ) ~~~
0: 1 | 0.0s | 1 nps | ok
1: 30 | 0.001s | 22666 nps | ok
2: 900 | 0.044s | 20438 nps | ok
3: 25470 | 1.088s | 23420 nps | ok
4: 719731 | 33.952s | 21198 nps | ok
5: 19861490 | 824.894s | 24077 nps | ok
= 20607622 | 859.978s | 23962 nps

Code: Select all

~~~ perft( 2 ) ~~~
[ fen: 5k3/b8/1n5G1/1B2l+R2+P/+S4K1+NK/7G1/9/9/8K[LSGnps] w 0 1 ]
0: 1 | 0.0s | 1 nps
1: 244 | 0.007s | 32551 nps
2: 1026 | 0.601s | 1706 nps
= 1271 | 0.609s | 2087 nps

Code: Select all

~~~ perft( 2 ) ~~~
[ fen: 2k6/L8/+b6p1/+b1+b2+n2P/5P1s+N/9/9/7K1/9[LPPpsn] w 0 1 ]
0: 1 | 0.0s | 1 nps
1: 171 | 0.009s | 19936 nps
2: 38191 | 1.093s | 34939 nps
= 38363 | 1.102s | 34823 nps

Code: Select all

~~~ perft( 2 ) ~~~
[ fen: 5k3/+n8/1G5R1/2+s+P3b1/n+s2l+B+N2/5s+prp/9/7K1/9[SPGnpn] w 0 1 ]
0: 1 | 0.0s | 1 nps
1: 235 | 0.01s | 24406 nps
2: 43506 | 1.82s | 23899 nps
= 43742 | 1.83s | 23902 nps

Code: Select all

~~~ perft( 2 ) ~~~
[ fen: 9/+l4k3/+P1+r2L1+l1/+l3+B2S1/1n5rR/5+l+l2/9/9/1K7[LGNpgl] w 0 1 ]
0: 1 | 0.0s | 1 nps
1: 214 | 0.009s | 23151 nps
2: 1066 | 0.552s | 1929 nps
= 1281 | 0.562s | 2280 nps
I have a 9x9 shogi called it Siyam, a Filipino name meaning nine in english.
Startpos:

Code: Select all

perft 5

9   l  n  s  g  k  g  s  n  l
8   .  r  .  .  .  .  .  b  .
7   p  p  p  p  p  p  p  p  p
6   .  .  .  .  .  .  .  .  .
5   .  .  .  .  .  .  .  .  .
4   .  .  .  .  .  .  .  .  .
3   P  P  P  P  P  P  P  P  P
2   .  B  .  .  .  .  .  R  .
1   L  N  S  G  K  G  S  N  L

    a  b  c  d  e  f  g  h  i


  a3a4 - 879050
  b3b4 - 721424
  c3c4 - 1099961
  d3d4 - 722473
  e3e4 - 728065
  f3f4 - 727359
  g3g4 - 777353
  h3h4 - 763797
  i3i4 - 821423
  a1a2 - 721423
  i1i2 - 623123
  c1c2 - 643428
  c1d2 - 604467
  g1f2 - 495883
  g1g2 - 455271
  d1c2 - 596975
  d1d2 - 606016
  d1e2 - 524756
  f1e2 - 529913
  f1f2 - 534086
  f1g2 - 454476
  h2g2 - 687521
  h2f2 - 650175
  h2e2 - 647634
  h2d2 - 638030
  h2c2 - 666383
  h2i2 - 713800
  e1e2 - 614526
  e1d2 - 645667
  e1f2 - 567032

 Perft 5 Summary
 Nodes: 19861490
 Time: 2.26 sec
 Nodes/sec: 8772743
Result is the same.


From your 1st fen:

Code: Select all

new
setboard 5k3/b8/1n5G1/1B2l+R2+P/+S4K1+NK/7G1/9/9/8K[LSGnps] w 0 1
5k3/b8/1n5G1/1B2l+R2+P/+S4K1+NK/7G1/9/9/8K[LSGnps] w 0 1
# On-hold materials:
# pocket L color 0, cnt 1
# pocket S color 0, cnt 1
# pocket G color 0, cnt 1
# pocket P color 1, cnt 1
# pocket N color 1, cnt 1
# pocket S color 1, cnt 1
# fen err: too many white king
# reset to orig board position
There are more than 1 white king.


From your 2nd fen:

Code: Select all

new
setboard 2k6/L8/+b6p1/+b1+b2+n2P/5P1s+N/9/9/7K1/9[LPPpsn] w 0 1
2k6/L8/+b6p1/+b1+b2+n2P/5P1s+N/9/9/7K1/9[LPPpsn] w 0 1
# On-hold materials:
# pocket P color 0, cnt 2
# pocket L color 0, cnt 1
# pocket P color 1, cnt 1
# pocket N color 1, cnt 1
# pocket S color 1, cnt 1
perft 2

9   .  .  k  .  .  .  .  .  .
8   L  .  .  .  .  .  .  .  .
7  +b  .  .  .  .  .  .  p  .
6  +b  . +b  .  . +n  .  .  P
5   .  .  .  .  .  P  .  s +N
4   .  .  .  .  .  .  .  .  .
3   .  .  .  .  .  .  .  .  .
2   .  .  .  .  .  .  .  K  .
1   .  .  .  .  .  .  .  .  .

    a  b  c  d  e  f  g  h  i


 i6i7+ - 228
  i6i7 - 228
  f5f6 - 225
 a8a9+ - 227
  i5h5 - 226
  i5h6 - 229
  i5i4 - 228
  h2h3 - 227
  h2i2 - 227
  h2g3 - 226
  h2i3 - 226
  h2i1 - 228
  P@b8 - 224
  L@b8 - 224
  P@c8 - 6
  L@c8 - 6
  P@d8 - 224
  L@d8 - 224
  P@e8 - 224
  L@e8 - 224
  L@f8 - 225
  P@g8 - 225
  L@g8 - 225
  P@h8 - 226
  L@h8 - 226
  L@i8 - 225
  P@b7 - 221
  L@b7 - 220
  P@c7 - 224
  L@c7 - 9
  P@d7 - 222
  L@d7 - 221
  P@e7 - 225
  L@e7 - 225
  L@f7 - 225
  P@g7 - 225
  L@g7 - 225
  L@i7 - 225
  P@b6 - 220
  L@b6 - 218
  P@d6 - 225
  L@d6 - 223
  P@e6 - 225
  L@e6 - 225
  P@g6 - 225
  L@g6 - 225
  P@h6 - 226
  L@h6 - 226
  P@a5 - 225
  L@a5 - 225
  P@b5 - 220
  L@b5 - 218
  P@c5 - 221
  L@c5 - 207
  P@d5 - 221
  L@d5 - 219
  P@e5 - 225
  L@e5 - 225
  P@g5 - 225
  L@g5 - 225
  P@a4 - 225
  L@a4 - 225
  P@b4 - 225
  L@b4 - 223
  P@c4 - 222
  L@c4 - 208
  P@d4 - 222
  L@d4 - 220
  P@e4 - 222
  L@e4 - 222
  L@f4 - 225
  P@g4 - 225
  L@g4 - 225
  P@h4 - 226
  L@h4 - 226
  L@i4 - 225
  P@a3 - 225
  L@a3 - 225
  P@b3 - 225
  L@b3 - 223
  P@c3 - 225
  L@c3 - 211
  P@d3 - 223
  L@d3 - 221
  P@e3 - 223
  L@e3 - 223
  L@f3 - 223
  P@g3 - 225
  L@g3 - 225
  P@h3 - 226
  L@h3 - 226
  L@i3 - 225
  P@a2 - 226
  L@a2 - 226
  P@b2 - 226
  L@b2 - 224
  P@c2 - 226
  L@c2 - 212
  P@d2 - 226
  L@d2 - 224
  P@e2 - 225
  L@e2 - 225
  L@f2 - 225
  P@g2 - 225
  L@g2 - 225
  L@i2 - 226
  P@a1 - 227
  L@a1 - 227
  P@b1 - 227
  L@b1 - 225
  P@c1 - 227
  L@c1 - 213
  P@d1 - 227
  L@d1 - 225
  P@e1 - 227
  L@e1 - 227
  L@f1 - 227
  P@g1 - 227
  L@g1 - 227
  P@h1 - 227
  L@h1 - 227
  L@i1 - 227

 Perft 2 Summary
 Nodes: 26689
 Time: 0.03 sec
 Nodes/sec: 834031
Result is not the same.


From your 3rd fen:

Code: Select all

new
setboard 5k3/+n8/1G5R1/2+s+P3b1/n+s2l+B+N2/5s+prp/9/7K1/9[SPGnpn] w 0 1
5k3/+n8/1G5R1/2+s+P3b1/n+s2l+B+N2/5s+prp/9/7K1/9[SPGnpn] w 0 1
# On-hold materials:
# pocket P color 0, cnt 1
# pocket S color 0, cnt 1
# pocket G color 0, cnt 1
# pocket P color 1, cnt 1
# pocket N color 1, cnt 2
perft 2

9   .  .  .  .  .  k  .  .  .
8  +n  .  .  .  .  .  .  .  .
7   .  G  .  .  .  .  .  R  .
6   .  . +s +P  .  .  .  b  .
5   n +s  .  .  l +B +N  .  .
4   .  .  .  .  .  s +p  r  p
3   .  .  .  .  .  .  .  .  .
2   .  .  .  .  .  .  .  K  .
1   .  .  .  .  .  .  .  .  .

    a  b  c  d  e  f  g  h  i


  h2g2 - 149
  h2i2 - 150
  h2i1 - 150
  h2g1 - 150
  P@h3 - 143
  S@h3 - 143
  G@h3 - 143

 Perft 2 Summary
 Nodes: 1028
 Time: 0.00 sec
 Nodes/sec: 1
Result is not the same.


From your 4th fen:

Code: Select all

new
setboard 9/+l4k3/+P1+r2L1+l1/+l3+B2S1/1n5rR/5+l+l2/9/9/1K7[LGNpgl] w 0 1
9/+l4k3/+P1+r2L1+l1/+l3+B2S1/1n5rR/5+l+l2/9/9/1K7[LGNpgl] w 0 1
# On-hold materials:
# pocket L color 0, cnt 1
# pocket N color 0, cnt 1
# pocket G color 0, cnt 1
# pocket P color 1, cnt 1
# pocket L color 1, cnt 1
# pocket G color 1, cnt 1
perft 2

9   .  .  .  .  .  .  .  .  .
8  +l  .  .  .  .  k  .  .  .
7  +P  . +r  .  .  L  . +l  .
6  +l  .  .  . +B  .  .  S  .
5   .  n  .  .  .  .  .  r  R
4   .  .  .  .  . +l +l  .  .
3   .  .  .  .  .  .  .  .  .
2   .  .  .  .  .  .  .  .  .
1   .  K  .  .  .  .  .  .  .

    a  b  c  d  e  f  g  h  i


bking was captured legally
 f7f8+ - 244
bking was captured legally
  f7f8 - 244
 h6g7+ - 4
  h6g7 - 4
 h6h7+ - 4
  h6h7 - 5
 h6i7+ - 6
  h6i7 - 6
  h6g5 - 6
  a7a8 - 5
  a7b8 - 5
  a7b7 - 5
  a7a6 - 5
  i5h5 - 5
  i5i6 - 5
 i5i7+ - 5
  i5i7 - 5
 i5i8+ - 2
  i5i8 - 2
 i5i9+ - 3
  i5i9 - 3
  i5i4 - 5
  i5i3 - 5
  i5i2 - 5
  i5i1 - 5
  e6d7 - 4
  e6c8 - 7
  e6b9 - 7
  e6f5 - 7
  e6g4 - 7
  e6d5 - 6
  e6c4 - 6
  e6b3 - 6
  e6a2 - 6
  e6d6 - 4
  e6e7 - 3
  e6f6 - 5
  e6e5 - 7
  b1a1 - 5
  b1b2 - 5
  b1a2 - 5
  G@a9 - 5
  G@b9 - 5
  G@c9 - 5
  G@d9 - 4
  G@e9 - 4
  G@f9 - 2
  G@g9 - 4
  G@h9 - 4
  G@i9 - 5
  L@b8 - 5
  G@b8 - 5
  L@c8 - 5
  G@c8 - 5
  L@d8 - 5
  G@d8 - 3
  L@e8 - 4
  G@e8 - 3
  L@g8 - 4
  G@g8 - 3
  L@h8 - 5
  G@h8 - 3
  L@i8 - 5
  G@i8 - 5
  N@b7 - 5
  L@b7 - 5
  G@b7 - 5
  N@d7 - 3
  L@d7 - 4
  G@d7 - 3
  N@e7 - 4
  L@e7 - 2
  G@e7 - 3
  N@g7 - 5
  L@g7 - 3
  G@g7 - 3
  N@i7 - 5
  L@i7 - 5
  G@i7 - 5
  N@b6 - 5
  L@b6 - 5
  G@b6 - 5
  N@c6 - 5
  L@c6 - 5
  G@c6 - 5
  N@d6 - 4
  L@d6 - 5
  G@d6 - 5
  N@f6 - 3
  L@f6 - 5
  G@f6 - 5
  N@g6 - 4
  L@g6 - 3
  G@g6 - 5
  N@i6 - 5
  L@i6 - 5
  G@i6 - 5
  N@a5 - 5
  L@a5 - 5
  G@a5 - 5
  N@c5 - 5
  L@c5 - 5
  G@c5 - 5
  N@d5 - 5
  L@d5 - 5
  G@d5 - 5
  N@e5 - 5
  L@e5 - 5
  G@e5 - 5
  N@f5 - 5
  L@f5 - 5
  G@f5 - 5
  N@g5 - 5
  L@g5 - 3
  G@g5 - 5
  N@a4 - 5
  L@a4 - 5
  G@a4 - 5
  N@b4 - 5
  L@b4 - 5
  G@b4 - 5
  N@c4 - 5
  L@c4 - 5
  G@c4 - 5
  N@d4 - 5
  L@d4 - 5
  G@d4 - 5
  N@e4 - 5
  L@e4 - 5
  G@e4 - 5
  N@h4 - 5
  L@h4 - 5
  G@h4 - 5
  N@i4 - 5
  L@i4 - 5
  G@i4 - 5
  N@a3 - 5
  L@a3 - 5
  G@a3 - 5
  N@b3 - 5
  L@b3 - 5
  G@b3 - 5
  N@c3 - 5
  L@c3 - 5
  G@c3 - 5
  N@d3 - 5
  L@d3 - 5
  G@d3 - 5
  N@e3 - 5
  L@e3 - 5
  G@e3 - 5
  N@f3 - 5
  L@f3 - 5
  G@f3 - 5
  N@g3 - 5
  L@g3 - 5
  G@g3 - 5
  N@h3 - 5
  L@h3 - 5
  G@h3 - 5
  N@i3 - 5
  L@i3 - 5
  G@i3 - 5
  N@a2 - 5
  L@a2 - 5
  G@a2 - 5
  N@b2 - 5
  L@b2 - 5
  G@b2 - 5
  N@c2 - 5
  L@c2 - 5
  G@c2 - 5
  N@d2 - 5
  L@d2 - 5
  G@d2 - 5
  N@e2 - 5
  L@e2 - 5
  G@e2 - 5
  N@f2 - 5
  L@f2 - 5
  G@f2 - 5
  N@g2 - 5
  L@g2 - 5
  G@g2 - 5
  N@h2 - 5
  L@h2 - 5
  G@h2 - 5
  N@i2 - 5
  L@i2 - 5
  G@i2 - 5
  N@a1 - 5
  L@a1 - 5
  G@a1 - 5
  N@c1 - 5
  L@c1 - 5
  G@c1 - 5
  N@d1 - 5
  L@d1 - 5
  G@d1 - 5
  N@e1 - 5
  L@e1 - 5
  G@e1 - 5
  N@f1 - 5
  L@f1 - 5
  G@f1 - 5
  N@g1 - 5
  L@g1 - 5
  G@g1 - 5
  N@h1 - 5
  L@h1 - 5
  G@h1 - 5
  N@i1 - 5
  L@i1 - 5
  G@i1 - 5

 Perft 2 Summary
 Nodes: 1508
 Time: 0.05 sec
 Nodes/sec: 32085
Result is not the same.


You may get Siyam at https://sites.google.com/site/deuterium ... /shogi-9x9

To test perft:
1. Run it in console
2. new
3. setboard [your fen]
4. perft n
where n >= 1

Patrice Duhamel
Posts: 131
Joined: Sat May 25, 2013 9:17 am
Location: France
Full name: Patrice Duhamel
Contact:

Re: Shogi Perft numbers

Post by Patrice Duhamel » Thu Aug 15, 2019 8:54 am

I have only a move generator for Shogi, and I have the same result than Ferdy, but not for the 3rd position :

Code: Select all

FEN : 5k3/+n8/1G5R1/2+s+P3b1/n+s2l+B+N2/5s+prp/9/7K1/9[SPGnpn]

   Kh2g1 : 149
   Kh2i1 : 149
   Kh2g2 : 148
   Kh2i2 : 149
    P@h3 : 142
    S@h3 : 142
    G@h3 : 142

total = 1021
I didn't spend lots of time on it, I must be wrong.
Anything that can go wrong will go wrong.

Ferdy
Posts: 4077
Joined: Sun Aug 10, 2008 1:15 pm
Location: Philippines

Re: Shogi Perft numbers

Post by Ferdy » Thu Aug 15, 2019 11:15 am

Patrice Duhamel wrote:
Thu Aug 15, 2019 8:54 am
I have only a move generator for Shogi, and I have the same result than Ferdy, but not for the 3rd position :

Code: Select all

FEN : 5k3/+n8/1G5R1/2+s+P3b1/n+s2l+B+N2/5s+prp/9/7K1/9[SPGnpn]

   Kh2g1 : 149
   Kh2i1 : 149
   Kh2g2 : 148
   Kh2i2 : 149
    P@h3 : 142
    S@h3 : 142
    G@h3 : 142

total = 1021
I didn't spend lots of time on it, I must be wrong.
I think mine is not correct as it does not consider a pawn drop checkmate in 1 move. But when playing it will not make such move.

Will try to find the source code.

Ferdy
Posts: 4077
Joined: Sun Aug 10, 2008 1:15 pm
Location: Philippines

Re: Shogi Perft numbers

Post by Ferdy » Thu Aug 15, 2019 2:27 pm

Tony had an interesting shogi position for perft from viewtopic.php?f=7&t=32014&hilit=perft+shogi


Or

Image

The perft of current released Siyam v0.43 is wrong here because it considers a pawn drop at i8 as legal.

Code: Select all

Perft 1 Summary
Nodes: 87
I modified its perft in unreleased v0.44 correcting this specific issue and now it gets 86.

Code: Select all

new
setboard 7lk/9/8S/9/9/9/9/7L1/8K[P] w 0 1
7lk/9/8S/9/9/9/9/7L1/8K[P] w 0 1

# On-hold materials:
# pocket P color 0, cnt 1
perft 1

9   .  .  .  .  .  .  .  l  k
8   .  .  .  .  .  .  .  .  .
7   .  .  .  .  .  .  .  .  S
6   .  .  .  .  .  .  .  .  .
5   .  .  .  .  .  .  .  .  .
4   .  .  .  .  .  .  .  .  .
3   .  .  .  .  .  .  .  .  .
2   .  .  .  .  .  .  .  L  .
1   .  .  .  .  .  .  .  .  K

    a  b  c  d  e  f  g  h  i


  h2h3 - 1
  h2h4 - 1
  h2h5 - 1
  h2h6 - 1
 h2h7+ - 1
  h2h7 - 1
 h2h8+ - 1
  h2h8 - 1
 h2h9+ - 1
  h2h9 - 1
 i7h8+ - 1
  i7h8 - 1
 i7i8+ - 1
  i7i8 - 1
 i7h6+ - 1
  i7h6 - 1
  i1h1 - 1
  i1i2 - 1
  P@a8 - 1
  P@b8 - 1
  P@c8 - 1
  P@d8 - 1
  P@e8 - 1
  P@f8 - 1
  P@g8 - 1
  P@h8 - 1
  P@a7 - 1
  P@b7 - 1
  P@c7 - 1
  P@d7 - 1
  P@e7 - 1
  P@f7 - 1
  P@g7 - 1
  P@h7 - 1
  P@a6 - 1
  P@b6 - 1
  P@c6 - 1
  P@d6 - 1
  P@e6 - 1
  P@f6 - 1
  P@g6 - 1
  P@h6 - 1
  P@i6 - 1
  P@a5 - 1
  P@b5 - 1
  P@c5 - 1
  P@d5 - 1
  P@e5 - 1
  P@f5 - 1
  P@g5 - 1
  P@h5 - 1
  P@i5 - 1
  P@a4 - 1
  P@b4 - 1
  P@c4 - 1
  P@d4 - 1
  P@e4 - 1
  P@f4 - 1
  P@g4 - 1
  P@h4 - 1
  P@i4 - 1
  P@a3 - 1
  P@b3 - 1
  P@c3 - 1
  P@d3 - 1
  P@e3 - 1
  P@f3 - 1
  P@g3 - 1
  P@h3 - 1
  P@i3 - 1
  P@a2 - 1
  P@b2 - 1
  P@c2 - 1
  P@d2 - 1
  P@e2 - 1
  P@f2 - 1
  P@g2 - 1
  P@i2 - 1
  P@a1 - 1
  P@b1 - 1
  P@c1 - 1
  P@d1 - 1
  P@e1 - 1
  P@f1 - 1
  P@g1 - 1
  P@h1 - 1

 Perft 1 Summary
 Nodes: 86
 Time: 0.05 sec
 Nodes/sec: 1654

3rd fen from JohnWoe is
5k3/+n8/1G5R1/2+s+P3b1/n+s2l+B+N2/5s+prp/9/7K1/9[SPGnpn] w 0 1

Code: Select all

Siyam v0.44 perft 1 and 2 are:
Perft 1 Summary
Nodes: 7

Perft 2 Summary
Nodes: 1028
So in this position Siyam v0.43 and v0.44 perft 2 is the same.

JohnWoe
Posts: 92
Joined: Sat Mar 02, 2013 10:31 pm

Re: Shogi Perft numbers

Post by JohnWoe » Thu Aug 15, 2019 11:10 pm

Big thanks to Ferdy!

Yeah my RubyShogi was full of bugs. Horse moves were buggy. This pawn drop checkmate was wrong. Drops were wrong...

Hopefully my numbers are now correct. I can finally start polishing RubyShogi.

Code: Select all

~~~ suite( 4 ) ~~~
[ round: 1 / 3 ]
[ fen: 7lk/9/8S/9/9/9/9/7L1/8K[P] w 0 1 ]
0: 1 | 0.0s | 1 nps | ok
1: 85 | 0.003s | 24859 nps | ok
2: 639 | 0.034s | 18778 nps | ok
3: 10786 | 0.431s | 25016 nps | ok
4: 167089 | 7.699s | 21703 nps | ok
= 178600 | 8.167s | 21867 nps

[ round: 2 / 3 ]
[ fen: lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL[-] w 0 1 ]
0: 1 | 0.0s | 1 nps | ok
1: 30 | 0.002s | 17519 nps | ok
2: 900 | 0.05s | 18004 nps | ok
3: 25470 | 1.38s | 18453 nps | ok
4: 719731 | 38.998s | 18455 nps | ok
= 746132 | 40.43s | 18454 nps

[ round: 3 / 3 ]
[ fen: 2k6/L8/+b6p1/+b1+b2+n2P/5P1s+N/9/9/7K1/9[LPPpsn] w 0 1 ]
0: 1 | 0.0s | 1 nps | ok
1: 122 | 0.007s | 16446 nps | error
2: 26689 | 1.025s | 26045 nps | ok
3: 2308091 | 144.336s | 15991 nps | error
Random position generator + perft:

Code: Select all

ruby ruby_shogi.rb -randperft
~~~ randperft( 10 ) ~~~

[ Round: 1 / 10 ]
[ fen: 7k1/9/9/9/l2s5/6snb/9/9/8K[GG] w 0 1 ]
0: 1 | 0.0s | 1 nps
1: 76 | 0.003s | 22554 nps
2: 2606 | 0.101s | 25874 nps
= 2683 | 0.104s | 25776 nps

[ Round: 2 / 10 ]
[ fen: 8k/9/9/9/b+S7/9/9/9/8K[P] w 0 1 ]
0: 1 | 0.0s | 1 nps
1: 78 | 0.003s | 23804 nps
2: 1040 | 0.041s | 25351 nps
= 1119 | 0.044s | 25258 nps

[ Round: 3 / 10 ]
[ fen: 2k6/9/9/9/3G5/5+n3/9/9/8K[L] w 0 1 ]
0: 1 | 0.0s | 1 nps
1: 78 | 0.003s | 27837 nps
2: 783 | 0.035s | 22396 nps
= 862 | 0.038s | 22825 nps

[ Round: 4 / 10 ]
[ fen: 5k3/9/9/9/l8/5+B1+R1/9/9/3K5[NL] w 0 1 ]
0: 1 | 0.0s | 1 nps
1: 164 | 0.006s | 29004 nps
2: 1681 | 0.102s | 16538 nps
= 1846 | 0.107s | 17204 nps

[ Round: 5 / 10 ]
[ fen: 6k2/9/9/9/9/8B/9/K8/9[Sl] w 0 1 ]
0: 1 | 0.0s | 1 nps
1: 94 | 0.003s | 29014 nps
2: 6659 | 0.278s | 23967 nps
= 6754 | 0.281s | 24029 nps

[ Round: 6 / 10 ]
[ fen: k8/9/9/9/1G7/9/9/9/6K2[Plg] w 0 1 ]
0: 1 | 0.0s | 1 nps
1: 81 | 0.003s | 29905 nps
2: 11947 | 0.416s | 28736 nps
= 12029 | 0.418s | 28746 nps

[ Round: 7 / 10 ]
[ fen: 7k1/9/9/9/3+s5/8+P/9/9/1K7[Nln] w 0 1 ]
0: 1 | 0.0s | 1 nps
1: 69 | 0.003s | 27562 nps
2: 9288 | 0.326s | 28465 nps
= 9358 | 0.329s | 28461 nps

[ Round: 8 / 10 ]
[ fen: 1k7/9/9/9/3B5/5+P1B+P/9/9/1K7[Gpl] w 0 1 ]
0: 1 | 0.0s | 1 nps
1: 121 | 0.004s | 28847 nps
2: 15249 | 0.864s | 17640 nps
= 15371 | 0.869s | 17695 nps

[ Round: 9 / 10 ]
[ fen: 3k5/9/9/9/l1+l6/8+b/9/9/6K2[Sp] w 0 1 ]
0: 1 | 0.0s | 1 nps
1: 79 | 0.004s | 22040 nps
2: 7132 | 0.266s | 26831 nps
= 7212 | 0.269s | 26771 nps

[ Round: 10 / 10 ]
[ fen: 1k7/9/9/9/+n8/5N1+rb/9/9/1K7[LLg] w 0 1 ]
0: 1 | 0.0s | 1 nps
1: 74 | 0.004s | 19761 nps
2: 7257 | 0.275s | 26341 nps
= 7332 | 0.279s | 26256 nps

User avatar
hgm
Posts: 23616
Joined: Fri Mar 10, 2006 9:06 am
Location: Amsterdam
Full name: H G Muller
Contact:

Re: Shogi Perft numbers

Post by hgm » Fri Aug 16, 2019 12:37 am

Note that in Shogi it is a matter of taste whether you consider some moves as illegal, or as a legal move that loses, as it has the rule that any illegal move loses. In an engine it is usually simpler to consider Pawn-drop mates as a move that loses. Then you can use the normal mate detection, and just flip the result if the previous move was a Pawn drop. But in perft this approach gives different results.

A similar concern applies to repetitions; I don't think that Chess perfts take account of 50-move draws or 3-fold repetitions. (And there is some justification for that, as these are just claiming opportunities, and not forced game ends.) In Shogi perpetual checking is forbidden, though. (but only on 4-fold repetition.) Also here there is the choice to consider it legal but losing (where it should be counted in perft) or illegal.

There actually is a true ambiguity in the official Shogi rules here. Someone designed a problem where one side must perpetually check to avoid being mated in one. But in one point of the loop the only evasion to this check is a Pawn drop that also checks. From which the only evasion then is to capture that dropped Pawn, again checking. The 4th time you get to that position, one can argue that capturing the Pawn would be illegal, because it completes a 4-fold repeated perpetual check sequence. But then the Pawn drop is a checkmate, since its capture was the only evasion, and would be illegal too. That player then has to play something different, and is subsequently checkmated in one. OTOH, if the repetition is legal but losing, the Pawn drop just forces a losing move. Which is allowed, after which the other side must go on making the losing perpetual or deviate and get mated. The current rules do not resolve this ambiguity.

Ferdy
Posts: 4077
Joined: Sun Aug 10, 2008 1:15 pm
Location: Philippines

Re: Shogi Perft numbers

Post by Ferdy » Fri Aug 16, 2019 3:02 am

hgm wrote:
Fri Aug 16, 2019 12:37 am
Note that in Shogi it is a matter of taste whether you consider some moves as illegal, or as a legal move that loses, as it has the rule that any illegal move loses.
In wiki/shogi at https://en.wikipedia.org/wiki/Shogi, disregarding its consequences, the wording for pawn drop checkmate seemed like it is really not allowed.
A pawn cannot be dropped to give an immediate checkmate.
So in Siyam's perft I will not count such move, just like a king moving into check is not considered in perft. Will release the version that implements it later.

Ferdy
Posts: 4077
Joined: Sun Aug 10, 2008 1:15 pm
Location: Philippines

Re: Shogi Perft numbers

Post by Ferdy » Fri Aug 16, 2019 5:43 am

JohnWoe wrote:
Thu Aug 15, 2019 11:10 pm
Big thanks to Ferdy!

Yeah my RubyShogi was full of bugs. Horse moves were buggy. This pawn drop checkmate was wrong. Drops were wrong...

Hopefully my numbers are now correct. I can finally start polishing RubyShogi.

Code: Select all

~~~ suite( 4 ) ~~~
[ round: 1 / 3 ]
[ fen: 7lk/9/8S/9/9/9/9/7L1/8K[P] w 0 1 ]
0: 1 | 0.0s | 1 nps | ok
1: 85 | 0.003s | 24859 nps | ok
2: 639 | 0.034s | 18778 nps | ok
3: 10786 | 0.431s | 25016 nps | ok
4: 167089 | 7.699s | 21703 nps | ok
= 178600 | 8.167s | 21867 nps
Regarding that fen I got,

Code: Select all

perft 4

9   .  .  .  .  .  .  .  l  k
8   .  .  .  .  .  .  .  .  .
7   .  .  .  .  .  .  .  .  S
6   .  .  .  .  .  .  .  .  .
5   .  .  .  .  .  .  .  .  .
4   .  .  .  .  .  .  .  .  .
3   .  .  .  .  .  .  .  .  .
2   .  .  .  .  .  .  .  L  .
1   .  .  .  .  .  .  .  .  K

    a  b  c  d  e  f  g  h  i

1: 86
2: 640
3: 10937
4: 177644
I am curious with your 85 at ply 1. Mine is 86. Can you generate a perft divide? Mine is,

Code: Select all

divide 1

9   .  .  .  .  .  .  .  l  k
8   .  .  .  .  .  .  .  .  .
7   .  .  .  .  .  .  .  .  S
6   .  .  .  .  .  .  .  .  .
5   .  .  .  .  .  .  .  .  .
4   .  .  .  .  .  .  .  .  .
3   .  .  .  .  .  .  .  .  .
2   .  .  .  .  .  .  .  L  .
1   .  .  .  .  .  .  .  .  K

    a  b  c  d  e  f  g  h  i


  h2h3 - 1
  h2h4 - 1
  h2h5 - 1
  h2h6 - 1
 h2h7+ - 1
  h2h7 - 1
 h2h8+ - 1
  h2h8 - 1
 h2h9+ - 1
  h2h9 - 1
 i7h8+ - 1
  i7h8 - 1
 i7i8+ - 1
  i7i8 - 1
 i7h6+ - 1
  i7h6 - 1
  i1h1 - 1
  i1i2 - 1
  P@h6 - 1
  P@a8 - 1
  P@g1 - 1
  P@c3 - 1
  P@c7 - 1
  P@h5 - 1
  P@i2 - 1
  P@b5 - 1
  P@d5 - 1
  P@a6 - 1
  P@h3 - 1
  P@d2 - 1
  P@c4 - 1
  P@b2 - 1
  P@a7 - 1
  P@e4 - 1
  P@e1 - 1
  P@b1 - 1
  P@g7 - 1
  P@e6 - 1
  P@d1 - 1
  P@d4 - 1
  P@i6 - 1
  P@h8 - 1
  P@e8 - 1
  P@b8 - 1
  P@g4 - 1
  P@f8 - 1
  P@i5 - 1
  P@f3 - 1
  P@a1 - 1
  P@i3 - 1
  P@a2 - 1
  P@e3 - 1
  P@f4 - 1
  P@h4 - 1
  P@e5 - 1
  P@e2 - 1
  P@c2 - 1
  P@c1 - 1
  P@i4 - 1
  P@g5 - 1
  P@h7 - 1
  P@g2 - 1
  P@c6 - 1
  P@d8 - 1
  P@b4 - 1
  P@f2 - 1
  P@g3 - 1
  P@d6 - 1
  P@a3 - 1
  P@f7 - 1
  P@a4 - 1
  P@f5 - 1
  P@e7 - 1
  P@d7 - 1
  P@f6 - 1
  P@c8 - 1
  P@b6 - 1
  P@c5 - 1
  P@b3 - 1
  P@g8 - 1
  P@d3 - 1
  P@f1 - 1
  P@a5 - 1
  P@b7 - 1
  P@g6 - 1
  P@h1 - 1

 Perft 1 Summary
 Nodes: 86
 Time: 0.01 sec
 Nodes/sec: 5733
 
Counting manually:
Total squares = 9 x 9 = 81
Pieces on board = 5
Empty sq = 81 - 5 = 76
Pawn cannot drop at i8 = 1
Pawn cannot drop at empty row 9 = 7
Pawn drop moves = 76 - 1 - 7 = 68
Silver moves = 3 non_promote + 3 promote = 6
Lance moves = 7 non_promote + 3 promote = 10
King moves = 2

Total = Pawn drop moves + Silver moves + Lance moves + King moves = 68+6+10+2 = 86

Patrice Duhamel
Posts: 131
Joined: Sat May 25, 2013 9:17 am
Location: France
Full name: Patrice Duhamel
Contact:

Re: Shogi Perft numbers

Post by Patrice Duhamel » Fri Aug 16, 2019 7:09 am

The Lance must promote on the last rank, h2h9 is not legal.
Anything that can go wrong will go wrong.

Post Reply