Perft for Xiangqi & Shogi

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

Patrice Duhamel
Posts: 193
Joined: Sat May 25, 2013 11:17 am
Location: France
Full name: Patrice Duhamel

Perft for Xiangqi & Shogi

Post by Patrice Duhamel »

I made move generation for Xiangqi and Shogi, I'm looking for engines with a perft option or other results
for usefull positions.

My results :

Xiangqi : rheakaehr/9/1c5c1/p1p1p1p1p/9/9/P1P1P1P1P/1C5C1/9/RHEAKAEHR r

Code: Select all

depth  nodes         captures    checks      checkmates

1      44            2           0           0
2      1920          72          6           0
3      79666         3159        384         0
4      3290240       115365      19380       0
5      133312995     4917734     953251      584
6      5392831844    185194510   39288662    29150
7      217154523878  7806689172  1793957429  4091560
Shogi : lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL[-] w 0 1

Code: Select all

depth  nodes          captures     drops     promotions  checks    checkmates

1      30             0            0         0           0         0
2      900            0            0         0           0         0
3      25470          59           0         30          48        0
4      719731         1803         0         842         1121      0
5      19861490       113680       2776      57214       71434     0
6      547581517      3387051      393476    1588324     1730177   0
7      15086269607    156289904    22189844  78496954    79636812  29
User avatar
hgm
Posts: 27790
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Perft for Xiangqi & Shogi

Post by hgm »

Tony Hecker posts some perft numbers on his website ( http://tonyjh.com/chess/technical/ ). So I suppose TJshogi / TJxiangqi do contain a perft function. I have no idea how it could be activated, though.

I vaguely recall Ilari Pihlajisto did make a dedicated perft utility that could also do Shogi and Xiangqi.

I guess in general it should need some additional specification as to what 'perft' means in these variants, in relation to repetitions and checks. In Chess perft does ignore repetitions, which is justified, because FIDE rules do not define these as a forced game termination, but just as a claim possibility. But in Shogi and Xiangqi perpetual checking is forbidden (and in the latter a whole lot more), so that continuing it at some point would be an illegal move. In Shogi it is not completely clear whether the game ends at checkmate or at King capture. Unlike Chess, where illegal moves have to be taken back, and the game then continues, illegal moves in Shogi forfeit the game. This makes it a moot point whether you lose because the King is captured, or because you exposed it to capture.
User avatar
Evert
Posts: 2929
Joined: Sat Jan 22, 2011 12:42 am
Location: NL

Re: Perft for Xiangqi & Shogi

Post by Evert »

SjaakII has a perft command, just run it as a terminal application.

Perft results for Shogi and Xiangqi (and others) are here: http://www.eglebbk.dds.nl/program/chess-perft.html, though not as deep as the ones you listed. It has some test positions that are checked when you run "test movegen", you can find them in xboard.c

The game is taken to end on checkmate, repetitions receive no special treatment (in general, anything that requires search or game history to determine whether it is illegal or not is assumed to be legal; come to think of it, that probably means it's quite happy to count checkmate by pawn drop as legal in Shogi).
Ferdy
Posts: 4833
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: Perft for Xiangqi & Shogi

Post by Ferdy »

Patrice Duhamel wrote:I made move generation for Xiangqi and Shogi, I'm looking for engines with a perft option or other results
for usefull positions.

My results :

Xiangqi : rheakaehr/9/1c5c1/p1p1p1p1p/9/9/P1P1P1P1P/1C5C1/9/RHEAKAEHR r

Code: Select all

depth  nodes         captures    checks      checkmates

1      44            2           0           0
2      1920          72          6           0
3      79666         3159        384         0
4      3290240       115365      19380       0
5      133312995     4917734     953251      584
6      5392831844    185194510   39288662    29150
7      217154523878  7806689172  1793957429  4091560
Shogi : lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL[-] w 0 1

Code: Select all

depth  nodes          captures     drops     promotions  checks    checkmates

1      30             0            0         0           0         0
2      900            0            0         0           0         0
3      25470          59           0         30          48        0
4      719731         1803         0         842         1121      0
5      19861490       113680       2776      57214       71434     0
6      547581517      3387051      393476    1588324     1730177   0
7      15086269607    156289904    22189844  78496954    79636812  29
My engine Makulit, a xiangqi engine, matches with your perft 6.

Code: Select all

rheakaehr/9/1c5c1/p1p1p1p1p/9/9/P1P1P1P1P/1C5C1/9/RHEAKAEHR w
perft 6

9  r h e a k a e h r
8  . . . . . . . . .
7  . c . . . . . c .
6  p . p . p . p . p
5  . . . . . . . . .
4  . . . . . . . . .
3  s . s . s . s . s
2  . C . . . . . C .
1  . . . . . . . . .
0  R H E A K A E H R

   a b c d e f g h i


 a3a4 - 139717285
 c3c4 - 131860248
 e3e4 - 131678248
 g3g4 - 131860248
 i3i4 - 139717285
 d0e1 - 133570951
 f0e1 - 133570951
 c0a2 - 119406192
 c0e2 - 106392867
 g0e2 - 106392867
 g0i2 - 119406192
 b0c2 - 109665880
 b0a2 - 118306342
 h0i2 - 118306342
 h0g2 - 109665880
 b2a2 - 109967806
 b2b3 - 107084963
 b2b4 - 138990645
 b2b5 - 130206793
 b2b6 - 95627148
 b2b9 - 87371213
 b2c2 - 113026940
 b2d2 - 142231273
 b2e2 - 98347250
 b2f2 - 132756134
 b2g2 - 96631495
 b2b1 - 146048563
 h2g2 - 113026940
 h2f2 - 142231273
 h2e2 - 98347250
 h2d2 - 132756134
 h2c2 - 96631495
 h2h3 - 107084963
 h2h4 - 138990645
 h2h5 - 130206793
 h2h6 - 95627148
 h2h9 - 87371213
 h2i2 - 109967806
 h2h1 - 146048563
 a0a1 - 184572281
 a0a2 - 119980068
 i0i1 - 184572281
 i0i2 - 119980068
 e0e1 - 137628922

 Perft 6 Summary
 Nodes: 5392831844
 Time: 919.83 sec
 Nodes/sec: 5862857
My engine Siyam, a shogi 9x9 engine, matches with your perft 6.

Code: Select all

lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL[-] w
perft 6

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 - 24243519
  b3b4 - 19907745
  c3c4 - 29957753
  d3d4 - 19852453
  e3e4 - 20084010
  f3f4 - 20068603
  g3g4 - 21454558
  h3h4 - 21077049
  i3i4 - 22670449
  a1a2 - 19908353
  i1i2 - 17192943
  c1c2 - 17752452
  c1d2 - 16694739
  g1f2 - 13675365
  g1g2 - 12555151
  d1c2 - 16472699
  d1d2 - 16734160
  d1e2 - 14474297
  f1e2 - 14618238
  f1f2 - 14732208
  f1g2 - 12534398
  h2g2 - 18971676
  h2f2 - 17938641
  h2e2 - 17868556
  h2d2 - 17615109
  h2c2 - 18388324
  h2i2 - 19697773
  e1e2 - 16972039
  e1d2 - 17808729
  e1f2 - 15659528

 Perft 6 Summary
 Nodes: 547581517
 Time: 116.68 sec
 Nodes/sec: 4693060
Patrice Duhamel
Posts: 193
Joined: Sat May 25, 2013 11:17 am
Location: France
Full name: Patrice Duhamel

Re: Perft for Xiangqi & Shogi

Post by Patrice Duhamel »

Thanks, I will try Sjaak II with custom positions.
Evert wrote: The game is taken to end on checkmate, repetitions receive no special treatment (in general, anything that requires search or game history to determine whether it is illegal or not is assumed to be legal; come to think of it, that probably means it's quite happy to count checkmate by pawn drop as legal in Shogi).
I'm not sure to understand the problem ?
I count the mate from a pawn drop as illegal.
Patrice Duhamel
Posts: 193
Joined: Sat May 25, 2013 11:17 am
Location: France
Full name: Patrice Duhamel

Re: Perft for Xiangqi & Shogi

Post by Patrice Duhamel »

Thanks, you have released your engines somewhere ?
User avatar
Evert
Posts: 2929
Joined: Sat Jan 22, 2011 12:42 am
Location: NL

Re: Perft for Xiangqi & Shogi

Post by Evert »

Patrice Duhamel wrote: I'm not sure to understand the problem ?
I count the mate from a pawn drop as illegal.
It is illegal, of course, but SjaakII's perft function doesn't know this. It's very simple and basic, simply skipping positions where the other side was left in check as illegal.

During game play, illegal pawn drops are caught by the search: if the current position is mate and the last move was a pawn drop, it returns an "ILLEGAL" score rather than a "MATE" score, which is caught and handled one level up. The perft function doesn't do this check, so it actually returns the wrong number if the tree contains a mate by pawn-drop.

There's more it doesn't check: it doesn't know to end the game after three checks in "three-check" either, as mentioned it doesn't consider chases in XiangQi and it doesn't handle the special mating rules of Shatar. I suppose I could fix all those, but it hasn't been high on my list of priorities...
User avatar
hgm
Posts: 27790
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Perft for Xiangqi & Shogi

Post by hgm »

In Shokidoki I do not consider Pawn-drop mates as illegal but as moves that lose. This is just a score correction similar to the stalemate correction in Chess. In the latter case you correct the score of a no-legal-moves position (which naturally would be -INF) to zero if you are not in check, in the former case you correct it to +INF if the move leading to it was a Pawn drop.

But Shokidoki has no perft anyway.
Ferdy
Posts: 4833
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: Perft for Xiangqi & Shogi

Post by Ferdy »

Patrice Duhamel wrote:Thanks, you have released your engines somewhere ?
https://sites.google.com/site/deuteriumengine/files

Only Siyam can generate perft, makulit could not as it was disabled in that version.
Patrice Duhamel
Posts: 193
Joined: Sat May 25, 2013 11:17 am
Location: France
Full name: Patrice Duhamel

Re: Perft for Xiangqi & Shogi

Post by Patrice Duhamel »

I see, it can be faster to detect in the search, but I only have the move generation + perft now.