Shogi Perft numbers

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

Ferdy
Posts: 4833
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: Shogi Perft numbers

Post by Ferdy »

Patrice Duhamel wrote: Fri Aug 16, 2019 9:09 am The Lance must promote on the last rank, h2h9 is not legal.
:oops: Completely missed it. Got it now. Thanks.

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: 85
2: 639
3: 10786
4: 167089
Ferdy
Posts: 4833
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: Shogi Perft numbers

Post by Ferdy »

Patrice Duhamel wrote: Thu Aug 15, 2019 10: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.
Perft 2 is now the same.

Code: Select all

perft 3

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

Siyam v0.44
1: 7
2: 1021
3: 201233
Ferdy
Posts: 4833
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: Shogi Perft numbers

Post by Ferdy »

JohnWoe wrote: Fri Aug 16, 2019 1:10 am 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.

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
This position also gives me trouble, turns out a bug in knight move generation on forced promotion. This is fixed now.

Code: Select all

new
setboard 7k1/9/9/9/l2s5/6snb/9/9/8K[GG] w 0 1
7k1/9/9/9/l2s5/6snb/9/9/8K[GG] w 0 1

perft 5

9   .  .  .  .  .  .  .  k  .
8   .  .  .  .  .  .  .  .  .
7   .  .  .  .  .  .  .  .  .
6   .  .  .  .  .  .  .  .  .
5   l  .  .  s  .  .  .  .  .
4   .  .  .  .  .  .  s  n  b
3   .  .  .  .  .  .  .  .  .
2   .  .  .  .  .  .  .  .  .
1   .  .  .  .  .  .  .  .  K

    a  b  c  d  e  f  g  h  i

Siyam v0.44
1: 76
2: 2606
3: 201658
4: 6768869
5: 122826857
The figures are matched by Sjaak II 1.3.0

Code: Select all

new
# New game 'Chess'
variant shogi
# New game 'shogi'
setboard 7k1/9/9/9/l2s5/6snb/9/9/8K[GG] w 0 1
perft 5
 1         76  0.00  76000000.00nps
 2       2606 18446744073709.55         0.00nps
 3     201658  0.09   2168365.59nps
 4    6768869  2.56   2645122.70nps
 5  122826857 44.20   2779202.56nps
Patrice Duhamel
Posts: 193
Joined: Sat May 25, 2013 11:17 am
Location: France
Full name: Patrice Duhamel

Re: Shogi Perft numbers

Post by Patrice Duhamel »

I don't have the good result for this one, at depth 2 :

Code: Select all

FEN : 7k1/9/9/9/l2s5/6snb/9/9/8K[GG]

   Ki1h1 : 39
   Ki1h2 : 39
    G@a1 : 39
    G@b1 : 39
    G@c1 : 39
    G@d1 : 39
    G@e1 : 39
    G@f1 : 39
    G@g1 : 39
    G@h1 : 39
    G@a2 : 38
    G@b2 : 39
    G@c2 : 39
    G@d2 : 39
    G@e2 : 39
    G@f2 : 39
    G@g2 : 37
    G@h2 : 39
    G@i2 : 39
    G@a3 : 36
    G@b3 : 39
    G@c3 : 39
    G@d3 : 39
    G@e3 : 39
    G@f3 : 39
    G@g3 : 39
    G@h3 : 35
    G@i3 : 39
    G@a4 : 34
    G@b4 : 39
    G@c4 : 39
    G@d4 : 39
    G@e4 : 39
    G@f4 : 39
    G@b5 : 39
    G@c5 : 39
    G@e5 : 39
    G@f5 : 39
    G@g5 : 39
    G@h5 : 35
    G@i5 : 39
    G@a6 : 39
    G@b6 : 39
    G@c6 : 39
    G@d6 : 39
    G@e6 : 39
    G@f6 : 39
    G@g6 : 36
    G@h6 : 39
    G@i6 : 39
    G@a7 : 39
    G@b7 : 39
    G@c7 : 39
    G@d7 : 39
    G@e7 : 39
    G@f7 : 36
    G@g7 : 37
    G@h7 : 36
    G@i7 : 37
    G@a8 : 39
    G@b8 : 39
    G@c8 : 39
    G@d8 : 39
    G@e8 : 38
    G@f8 : 37
    G@g8 : 3
    G@h8 : 1
    G@i8 : 3
    G@a9 : 39
    G@b9 : 39
    G@c9 : 39
    G@d9 : 39
    G@e9 : 39
    G@f9 : 38
    G@g9 : 4
    G@i9 : 4

total = 2748
Anything that can go wrong will go wrong.
Ferdy
Posts: 4833
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: Shogi Perft numbers

Post by Ferdy »

Patrice Duhamel wrote: Sat Aug 17, 2019 11:07 am I don't have the good result for this one, at depth 2 :

Code: Select all

FEN : 7k1/9/9/9/l2s5/6snb/9/9/8K[GG]

   Ki1h1 : 39
   Ki1h2 : 39
    G@a1 : 39
    G@b1 : 39
    G@c1 : 39
    G@d1 : 39
    G@e1 : 39
    G@f1 : 39
    G@g1 : 39
    G@h1 : 39
    G@a2 : 38
    G@b2 : 39
    G@c2 : 39
    G@d2 : 39
    G@e2 : 39
    G@f2 : 39
    G@g2 : 37
    G@h2 : 39
    G@i2 : 39
    G@a3 : 36
    G@b3 : 39
    G@c3 : 39
    G@d3 : 39
    G@e3 : 39
    G@f3 : 39
    G@g3 : 39
    G@h3 : 35
    G@i3 : 39
    G@a4 : 34
    G@b4 : 39
    G@c4 : 39
    G@d4 : 39
    G@e4 : 39
    G@f4 : 39
    G@b5 : 39
    G@c5 : 39
    G@e5 : 39
    G@f5 : 39
    G@g5 : 39
    G@h5 : 35
    G@i5 : 39
    G@a6 : 39
    G@b6 : 39
    G@c6 : 39
    G@d6 : 39
    G@e6 : 39
    G@f6 : 39
    G@g6 : 36
    G@h6 : 39
    G@i6 : 39
    G@a7 : 39
    G@b7 : 39
    G@c7 : 39
    G@d7 : 39
    G@e7 : 39
    G@f7 : 36
    G@g7 : 37
    G@h7 : 36
    G@i7 : 37
    G@a8 : 39
    G@b8 : 39
    G@c8 : 39
    G@d8 : 39
    G@e8 : 38
    G@f8 : 37
    G@g8 : 3
    G@h8 : 1
    G@i8 : 3
    G@a9 : 39
    G@b9 : 39
    G@c9 : 39
    G@d9 : 39
    G@e9 : 39
    G@f9 : 38
    G@g9 : 4
    G@i9 : 4

total = 2748
This is my perft divide 2.

Code: Select all

new
setboard 7k1/9/9/9/l2s5/6snb/9/9/8K[GG] w
7k1/9/9/9/l2s5/6snb/9/9/8K[GG] w

divide 2

9   .  .  .  .  .  .  .  k  .
8   .  .  .  .  .  .  .  .  .
7   .  .  .  .  .  .  .  .  .
6   .  .  .  .  .  .  .  .  .
5   l  .  .  s  .  .  .  .  .
4   .  .  .  .  .  .  s  n  b
3   .  .  .  .  .  .  .  .  .
2   .  .  .  .  .  .  .  .  .
1   .  .  .  .  .  .  .  .  K

    a  b  c  d  e  f  g  h  i

Siyam v0.45

  i1h1 - 37
  i1h2 - 37
  G@a9 - 37
  G@b9 - 37
  G@c9 - 37
  G@d9 - 37
  G@e9 - 37
  G@f9 - 36
  G@g9 - 4
  G@i9 - 4
  G@a8 - 37
  G@b8 - 37
  G@c8 - 37
  G@d8 - 37
  G@e8 - 36
  G@f8 - 35
  G@g8 - 3
  G@h8 - 1
  G@i8 - 3
  G@a7 - 37
  G@b7 - 37
  G@c7 - 37
  G@d7 - 37
  G@e7 - 37
  G@f7 - 34
  G@g7 - 35
  G@h7 - 34
  G@i7 - 35
  G@a6 - 37
  G@b6 - 37
  G@c6 - 37
  G@d6 - 37
  G@e6 - 37
  G@f6 - 37
  G@g6 - 34
  G@h6 - 37
  G@i6 - 37
  G@b5 - 37
  G@c5 - 37
  G@e5 - 37
  G@f5 - 37
  G@g5 - 37
  G@h5 - 33
  G@i5 - 37
  G@a4 - 32
  G@b4 - 37
  G@c4 - 37
  G@d4 - 37
  G@e4 - 37
  G@f4 - 37
  G@a3 - 34
  G@b3 - 37
  G@c3 - 37
  G@d3 - 37
  G@e3 - 37
  G@f3 - 37
  G@g3 - 37
  G@h3 - 33
  G@i3 - 37
  G@a2 - 36
  G@b2 - 37
  G@c2 - 37
  G@d2 - 37
  G@e2 - 37
  G@f2 - 37
  G@g2 - 35
  G@h2 - 37
  G@i2 - 37
  G@a1 - 37
  G@b1 - 37
  G@c1 - 37
  G@d1 - 37
  G@e1 - 37
  G@f1 - 37
  G@g1 - 37
  G@h1 - 37

 Perft 2 Summary
 Nodes: 2606
 Time: 0.05 sec
 Nodes/sec: 55447
We differ on i1h1, I will push this and generate divide 1, then manually checking the possible legal moves is easier.

Code: Select all

i1h1
fen
7k1/9/9/9/l2s5/6snb/9/9/7K1[GG] b
divide 1

9   .  .  .  .  .  .  .  k  .
8   .  .  .  .  .  .  .  .  .
7   .  .  .  .  .  .  .  .  .
6   .  .  .  .  .  .  .  .  .
5   l  .  .  s  .  .  .  .  .
4   .  .  .  .  .  .  s  n  b
3   .  .  .  .  .  .  .  .  .
2   .  .  .  .  .  .  .  .  .
1   .  .  .  .  .  .  .  K  .

    a  b  c  d  e  f  g  h  i

Siyam v0.45

  a5a4 - 1
 a5a3+ - 1
  a5a3 - 1
 a5a2+ - 1
  a5a2 - 1
 a5a1+ - 1
 h4i2+ - 1
 h4g2+ - 1
  d5e4 - 1
  d5d4 - 1
  d5c4 - 1
  d5c6 - 1
  d5e6 - 1
 g4h3+ - 1
  g4h3 - 1
 g4g3+ - 1
  g4g3 - 1
 g4f3+ - 1
  g4f3 - 1
  g4f5 - 1
  g4h5 - 1
  i4h5 - 1
  i4g6 - 1
  i4f7 - 1
  i4e8 - 1
  i4d9 - 1
 i4h3+ - 1
  i4h3 - 1
 i4g2+ - 1
  i4g2 - 1
 i4f1+ - 1
  i4f1 - 1
  h9g9 - 1
  h9i9 - 1
  h9h8 - 1
  h9i8 - 1
  h9g8 - 1

 Perft 1 Summary
 Nodes: 37
 Time: 0.05 sec
 Nodes/sec: 787
Lets see your perf divide at ply 1.
Patrice Duhamel
Posts: 193
Joined: Sat May 25, 2013 11:17 am
Location: France
Full name: Patrice Duhamel

Re: Shogi Perft numbers

Post by Patrice Duhamel »

Thanks, the difference is Nh4g2 and Nh4i2 illegal because of the forced promotion of the Knight.

Code: Select all

FEN : 7k1/9/9/9/l2s5/6snb/9/9/7K1[GG] b

  Bi4f1+ : 1
  Bi4g2+ : 1
  Bi4h3+ : 1
  La5a1+ : 1
  La5a2+ : 1
  La5a3+ : 1
  Nh4g2+ : 1
  Nh4i2+ : 1
  Sg4f3+ : 1
  Sg4g3+ : 1
  Sg4h3+ : 1
   La5a2 : 1
   La5a3 : 1
   La5a4 : 1
   Nh4g2 : 1
   Nh4i2 : 1
   Sg4f3 : 1
   Sg4g3 : 1
   Sg4h3 : 1
   Sg4f5 : 1
   Sg4h5 : 1
   Sd5c4 : 1
   Sd5d4 : 1
   Sd5e4 : 1
   Sd5c6 : 1
   Sd5e6 : 1
   Bi4f1 : 1
   Bi4g2 : 1
   Bi4h3 : 1
   Bi4h5 : 1
   Bi4g6 : 1
   Bi4f7 : 1
   Bi4e8 : 1
   Bi4d9 : 1
   Kh9g8 : 1
   Kh9h8 : 1
   Kh9i8 : 1
   Kh9g9 : 1
   Kh9i9 : 1

total = 39
Anything that can go wrong will go wrong.
Ferdy
Posts: 4833
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: Shogi Perft numbers

Post by Ferdy »

Extracted sfen from Alphazero-elmo game 1 from https://deepmind.com/research/open-sour ... -resources where there is a lance or a knight in the on-hand. Then convert the sfen to winboard shogi fen. Run Siyam on 20/123 positions selected randomly to get the perft 1 and 2 counts.

Siyam v0.46 perft 1 and 2 results:

Code: Select all

l2kg2+R1/4n3+L/p1gpps3/4np3/6P1N/PP+rP2pS1/1pG2P3/4P1G2/LN3KB1+p[SPbslpppp] w,107,20080
l+Rl2+R3/3k1s2+L/p1p1p4/2Ppnp1S1/4n1Pbp/PP2G4/1G3P+n2/Kp2P4/L8[GSPPPPbgsnp] b,240,39392
l+Rl2g2+R/3k1s2+L/p1p1p4/2Ppnp1S1/4n1Pbp/PP2G4/1G3P+n2/Kp2P4/L8[SPPPPbgsnp] w,110,24582
l2kgb1+R1/4n3+L/p1gpps3/4np3/6P1N/PPGP2pS1/1p3P3/4P1G2/LN3KB1+p[RSPslpppp] w,158,21443
l8/1r1gk3+L/p1Npp2S1/2Psnpg2/5+r2N/PP1P2pS1/1pG1BP3/4P1G2/LN3KB1+p[SPPlppp] w,109,10902
lr6l/3g1kg2/p2pp2s+P/2Ps1ppp1/8L/P1nP2PR1/1P3PS2/1SGK5/LN3G3[BNNPPPbpp] w,7,755
lr7/3g1kg2/p2pp2s+L/2Ps1ppp1/9/PP1P1BPS1/5P1PS/1G6+r/LN3KB2[GNNLPPPnpp] w,184,18331
l+Rl2g2+R/2p+Sks2+L/p3p4/2Ppnp1S1/4n1Pbp/PP2G4/1G3P+n2/Kp2P4/L8[GSPPPPbnp] b,2,326
l2s5/3kn2R+L/p1gpp+B3/4np3/2+r3P1N/PP1P2pS1/1pG2P3/4P1G2/LN3KB1+p[GLPsspppp] w,165,16018
lr7/3g1kg2/p2pp2s+L/2Psnp1p1/5+rS2/PP1P5/4BPS2/1G2P1G2/LN3KB1L[NNPPPpppp] b,72,6928
lr7/3g1kg2/p2pp2s+L/2Ps1ppp1/9/P2P1BPS1/1P3P3/1G3B3/LN2KG1r1[NNNLPPPsppp] b,123,16661
l+Rl2+R3/3k1s2+L/p1p1p4/2Ppnp1S1/4n1Pbp/PP2G4/KG3P+n2/1p2P4/Ls7[GSPPPPbgnp] b,188,30364
lr6l/3g1kg2/p2pp2s+P/2Ps1ppp1/7nL/P2P2PR1/1P3PN2/1SGK2S2/LN3G3[BNPPPbpp] b,109,14585
l1S6/r3k3+L/p1gppl3/4np+B2/2+r3P1N/PP1P2pS1/1pG2P3/4P1G2/LN3KB1+p[GSPsnpppp] w,163,21883
lr7/3g1kg2/p2pp2sl/2Ps1ppp1/8L/P2P2PR1/1P3PS2/1G7/LN2KG3[BNNNPPPbsppp] w,145,23120
l8/1r1g1k3/p1Npp1gs+L/2Psnp1p1/5+rS2/PP1P2pS1/1pG1BP3/4P1G1p/LN3KB1L[NPPpp] w,84,4399
lr7/3g1kg2/p2pp2s+L/2Ps1p1p1/5+rp2/PP1P1B1S1/5PP1S/1G2P1G2/LN3KB1L[NNPnpppp] w,86,8763
l2kgs1+R1/4n+B2+L/p1gpp4/4np3/6P1N/PP+rP2pS1/1pG2P3/4P1G2/LN3KB1+p[SSPlpppp] b,95,10625
l8/1r1gk3+L/p1Npp4/2Psnp+r2/8N/PP1P2pS1/1pG1BP3/4P1G2/LN3KB1+p[GSPPslppp] w,156,22669
lr7/3g1kg2/p2pp2s+L/2Ps1ppp1/9/PP1P1BPS1/5P1P1/1G3B1g1/LN3KN1+r[SNNLPPPpp] w,181,12037
First entry is fen, second entry is perft 1 and third entry is perft 2.
Patrice Duhamel
Posts: 193
Joined: Sat May 25, 2013 11:17 am
Location: France
Full name: Patrice Duhamel

Re: Shogi Perft numbers

Post by Patrice Duhamel »

Ferdy wrote: Sun Aug 18, 2019 2:03 pm Siyam v0.46 perft 1 and 2 results:
Same results for me.

I would like to find time to make a Shogi and Xiangqi engine from my move genenerator.
Anything that can go wrong will go wrong.
Ferdy
Posts: 4833
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: Shogi Perft numbers

Post by Ferdy »

Patrice Duhamel wrote: Sun Aug 18, 2019 4:29 pm
Ferdy wrote: Sun Aug 18, 2019 2:03 pm Siyam v0.46 perft 1 and 2 results:
Same results for me.

I would like to find time to make a Shogi and Xiangqi engine from my move genenerator.
Just in case you will support usi, I have a forked on python-shogi, and created and perft divide at https://github.com/fsmosca/python-shogi ... er/scripts

I plan to implement usi in my shogi engine.
Patrice Duhamel
Posts: 193
Joined: Sat May 25, 2013 11:17 am
Location: France
Full name: Patrice Duhamel

Re: Shogi Perft numbers

Post by Patrice Duhamel »

What GUI are using USI protocol ?
Anything that can go wrong will go wrong.