Page 1 of 1

Trouble with used-defined variants and chess engines

PostPosted: 29 Dec 2022, 23:11
by Ivan P
Hello again!

After a year and a half my interests circled back to chess variants which led me back to WinBoard. Last time I've had trouble with Sjaak II and it was partially solved to the point where I only have to wait for a new version of either to drop. Having checked and seen that nothing new came out yet, I've decided to give Fairy-Stockfish a try.

As an exercise/test, I've decided to define a replica of the standard Shogi rules. This is the code:
Code: Select all
# 9×9 shogi
[shogic]
variantTemplate = shogi
maxRank = 9
maxFile = 9
shogiPawn = p
lance = l
shogiKnight = n
silver = s
gold = g
bishop = b
dragonHorse = h
rook = r
bers = d
king = k
startFen = lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL[-] w 0 1
pieceDrops = true
capturesToHand = true
promotionRank = 7
doubleStep = false
castling = false
promotedPieceType = l:g n:g p:g s:g b:h r:d
dropNoDoubled = p
immobilityIllegal = true
shogiPawnDropMateIllegal = true
stalemateValue = loss
nFoldRule = 4
nMoveRule = 0
perpetualCheckIllegal = true
pocketSize = 7
nFoldValue = loss
nFoldValueAbsolute = true
pieceToCharTable = PNBR.S...G........L..Kpnbr.s...g........l..k


The board loads correctly, and when I switch to "two engines" mode everything seems okay for a while. However, once a promoted piece gets captured, something weird happens. The piece enters the "pocket" still promoted, and it can't be brought out anymore. And then, when the bot tries to bring out a piece it thinks it has, WinBoard calls illegal move.

I've raised the issue with the author of Fairy-Stockfish: https://github.com/ianfab/Fairy-Stockfish/issues/561 The author said that I've configured Fairy-Stockfish correctly and that the issue is likely with WinBoard. Can I get some help?

Thank you for your time.

Re: Trouble with used-defined variants and chess engines

PostPosted: 29 Dec 2022, 23:16
by Ivan P
Oh, right. This is the debug file:
Code: Select all
recognized 'shogic' (-1) as variant normal
recognized 'shogic' (-1) as variant normal
shuffleOpenings = 0
Version: WinBoard 4.9.1 + fairy-stockfish-largeboard_x86-64-bmi2
Reset(1, 0) from gameMode 0
recognized 'shogic' (-1) as variant shogic
GameEnds(0, (null), 2)
shuffleOpenings = 0
StartChildProcess (dir="E:\Downloads\Winboard-4.9.1\Winboard-4.9.1\Fairy-Stockfish") E:\Downloads\Winboard-4.9.1\Winboard-4.9.1\Fairy-Stockfish\fairy-stockfish-largeboard_x86-64-bmi2.exe load variants.ini
572 >first : xboard
protover 2
580 <first : Fairy-Stockfish 14.0.1 XQ by Fabian Fichter
604 <first : feature setboard=1 usermove=1 time=1 memory=1 smp=1 colors=0 draw=0 highlight=1 name=0 sigint=0 ping=1 myname="Fairy-Stockfish 14.0.1 XQ" variants="chess,3check,5check,ai-wok,almost,amazon,antichess,armageddon,asean,ataxx,atomic,breakthrough,bughouse,cambodian,capablanca,capahouse,caparandom,centaur,chancellor,chaturanga,chessgi,chigorin,chogi,clobber,clobber10,codrus,coregal,courier,crazyhouse,dobutsu,embassy,euroshogi,extinction,fairy,fischerandom,gardner,giveaway,gorogoro,gothic,grand,grasshopper,hoppelpoppel,horde,janggi,janggicasual,janggimodern,janggitraditional,janus,jesonmor,judkins,karouk,kinglet,kingofthehill,knightmate,koedem,kyotoshogi,loop,losalamos,losers,makpong,makruk,manchu,micro,mini,minishogi,minixiangqi,modern,newzealand,nightrider,nocastle,nocheckatomic,normal,okisakishogi,opulent,placement,pocketknight,racingkings,seirawan,shako,shatar,shatranj,shogi,shogic,shoshogi,shoshogic,shouse,sittuyin,suicide,supply,tencubed,threekings,torishogi,xiangqi,yarishogi"
607 >first : accepted setboard
607 >first : accepted usermove
607 >first : accepted time
607 >first : accepted memory
607 >first : accepted smp
607 >first : accepted colors
607 >first : accepted draw
607 >first : accepted highlight
607 >first : accepted name
607 >first : accepted sigint
607 >first : accepted ping
607 >first : accepted myname
607 >first : accepted variants
608 <first : feature option="Debug Log File -string "
608 >first : accepted option
608 <first : feature option="Clear Hash -button"
608 >first : accepted option
608 <first : feature option="Ponder -check 0"
608 >first : accepted option
608 <first : feature option="MultiPV -spin 1 1 500"
608 >first : accepted option
608 <first : feature option="Skill Level -spin 20 -20 20"
609 >first : accepted option
609 <first : feature option="Move Overhead -spin 10 0 5000"
609 >first : accepted option
609 <first : feature option="Slow Mover -spin 100 10 1000"
609 >first : accepted option
609 <first : feature option="nodestime -spin 0 0 10000"
609 >first : accepted option
609 <first : feature option="UCI_Chess960 -check 0"
609 >first : accepted option
610 <first : feature option="UCI_AnalyseMode -check 0"
610 >first : accepted option
610 <first : feature option="UCI_LimitStrength -check 0"
610 >first : accepted option
610 <first : feature option="UCI_Elo -spin 1350 500 2850"
610 >first : accepted option
610 <first : feature option="UCI_ShowWDL -check 0"
610 >first : accepted option
610 <first : feature option="SyzygyPath -string <empty>"
611 >first : accepted option
611 <first : feature option="SyzygyProbeDepth -spin 1 1 100"
611 >first : accepted option
611 <first : feature option="Syzygy50MoveRule -check 1"
611 >first : accepted option
611 <first : feature option="SyzygyProbeLimit -spin 7 0 7"
611 >first : accepted option
611 <first : feature option="Use NNUE -check 1"
611 >first : accepted option
611 <first : feature option="EvalFile -string xiangqi-83f16c17fe26.nnue;janggi-85de3dae670a.nnue"
612 >first : accepted option
612 <first : feature option="TsumeMode -check 0"
612 >first : accepted option
612 <first : feature option="VariantPath -string <empty>"
612 >first : accepted option
612 <first : feature done=1
612 >first : accepted done
634 >first : memory 68
634 >first : cores 1
634 >first : new
random
634 >first : variant shogic
634 >first : level 500 1 0
634 >first : post
634 >first : hard
634 >first : ping 1
Impossible move , type = 0
678 <first : Error (unknown command): random
681 <first : setup (PNBR.S...G........L..Kpnbr.s...g........l..k) 9x9+7_shogi lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL[-] w 0 1
recognized 'shogi' (-1) as variant shogic
shuffleOpenings = 0
701 <first : piece B& B@9
701 <first : piece +B& BW
701 <first : piece R& R@9
701 <first : piece +R& RF
702 <first : piece S& FfW@9
702 <first : piece +S& WfF
702 <first : piece D& RF@9
702 <first : piece P& fWf@9
702 <first : piece +P& WfF
702 <first : piece L& fR@9
702 <first : piece +L& WfF
702 <first : piece N& fN@9
702 <first : piece +N& WfF
702 <first : piece G& WfF@9
702 <first : piece H& BW@9
702 <first : piece K& K@9
702 <first : Error (unknown command): post
703 <first : pong 1
6346 >first : force
StartChildProcess (dir="E:\Downloads\Winboard-4.9.1\Winboard-4.9.1\Fairy-Stockfish") E:\Downloads\Winboard-4.9.1\Winboard-4.9.1\Fairy-Stockfish\fairy-stockfish-largeboard_x86-64-bmi2.exe load variants.ini
6858 >second: xboard
protover 2
6858 <second: Fairy-Stockfish 14.0.1 XQ by Fabian Fichter
6887 <second: feature setboard=1 usermove=1 time=1 memory=1 smp=1 colors=0 draw=0 highlight=1 name=0 sigint=0 ping=1 myname="Fairy-Stockfish 14.0.1 XQ" variants="chess,3check,5check,ai-wok,almost,amazon,antichess,armageddon,asean,ataxx,atomic,breakthrough,bughouse,cambodian,capablanca,capahouse,caparandom,centaur,chancellor,chaturanga,chessgi,chigorin,chogi,clobber,clobber10,codrus,coregal,courier,crazyhouse,dobutsu,embassy,euroshogi,extinction,fairy,fischerandom,gardner,giveaway,gorogoro,gothic,grand,grasshopper,hoppelpoppel,horde,janggi,janggicasual,janggimodern,janggitraditional,janus,jesonmor,judkins,karouk,kinglet,kingofthehill,knightmate,koedem,kyotoshogi,loop,losalamos,losers,makpong,makruk,manchu,micro,mini,minishogi,minixiangqi,modern,newzealand,nightrider,nocastle,nocheckatomic,normal,okisakishogi,opulent,placement,pocketknight,racingkings,seirawan,shako,shatar,shatranj,shogi,shogic,shoshogi,shoshogic,shouse,sittuyin,suicide,supply,tencubed,threekings,torishogi,xiangqi,yarishogi"
6890 >second: accepted setboard
6890 >second: accepted usermove
6890 >second: accepted time
6890 >second: accepted memory
6890 >second: accepted smp
6890 >second: accepted colors
6891 >second: accepted draw
6891 >second: accepted highlight
6891 >second: accepted name
6891 >second: accepted sigint
6891 >second: accepted ping
6891 >second: accepted myname
6891 >second: accepted variants
6891 <second: feature option="Debug Log File -string "
6891 >second: accepted option
6891 <second: feature option="Clear Hash -button"
6891 >second: accepted option
6892 <second: feature option="Ponder -check 0"
6892 >second: accepted option
6892 <second: feature option="MultiPV -spin 1 1 500"
6892 >second: accepted option
6892 <second: feature option="Skill Level -spin 20 -20 20"
6892 >second: accepted option
6892 <second: feature option="Move Overhead -spin 10 0 5000"
6892 >second: accepted option
6892 <second: feature option="Slow Mover -spin 100 10 1000"
6893 >second: accepted option
6893 <second: feature option="nodestime -spin 0 0 10000"
6893 >second: accepted option
6893 <second: feature option="UCI_Chess960 -check 0"
6893 >second: accepted option
6893 <second: feature option="UCI_AnalyseMode -check 0"
6893 >second: accepted option
6893 <second: feature option="UCI_LimitStrength -check 0"
6893 >second: accepted option
6893 <second: feature option="UCI_Elo -spin 1350 500 2850"
6893 >second: accepted option
6894 <second: feature option="UCI_ShowWDL -check 0"
6894 >second: accepted option
6894 <second: feature option="SyzygyPath -string <empty>"
6894 >second: accepted option
6894 <second: feature option="SyzygyProbeDepth -spin 1 1 100"
6894 >second: accepted option
6894 <second: feature option="Syzygy50MoveRule -check 1"
6894 >second: accepted option
6894 <second: feature option="SyzygyProbeLimit -spin 7 0 7"
6895 >second: accepted option
6895 <second: feature option="Use NNUE -check 1"
6895 >second: accepted option
6895 <second: feature option="EvalFile -string xiangqi-83f16c17fe26.nnue;janggi-85de3dae670a.nnue"
6895 >second: accepted option
6895 <second: feature option="TsumeMode -check 0"
6895 >second: accepted option
6895 <second: feature option="VariantPath -string <empty>"
6896 >second: accepted option
6897 <second: feature done=1
6897 >second: accepted done
6921 >second: memory 68
6921 >second: cores 1
6921 >second: new
random
6921 >second: variant shogic
6921 >second: level 500 1 0
6921 >second: post
6921 >second: hard
6921 >second: ping 1
Impossible move , type = 0
6922 >second: force
6965 <second: Error (unknown command): random
6968 <second: setup (PNBR.S...G........L..Kpnbr.s...g........l..k) 9x9+7_shogi lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL[-] w 0 1
6969 <second: piece B& B@9
6969 <second: piece +B& BW
6969 <second: piece R& R@9
6969 <second: piece +R& RF
6969 <second: piece S& FfW@9
6969 <second: piece +S& WfF
6969 <second: piece D& RF@9
6969 <second: piece P& fWf@9
6969 <second: piece +P& WfF
6969 <second: piece L& fR@9
6969 <second: piece +L& WfF
6970 <second: piece N& fN@9
6970 <second: piece +N& WfF
6970 <second: piece G& WfF@9
6970 <second: piece H& BW@9
6970 <second: piece K& K@9
6970 <second: Error (unknown command): post
6970 <second: pong 1
write FEN 50-move: 0 0 0
e0. p=-1
6982 >second: setboard lnsgkgsnl/1r5b1/ppppppppp/9/9/9/PPPPPPPPP/1B5R1/LNSGKGSNL[-] w 0 1
Two Machines
New game (0): Fairy-Stockfish 14.0.1 XQ-Fairy-Stockfish 14.0.1 XQ (w)
6982 >first : computer
6982 >second: computer
6983 >first : time 6000
6983 >first : otim 6000
book hit = (NULL)
6983 >first : go
nps: w=-1, b=-1
6983 <second: Error (unknown command): computer
6983 <first : Error (unknown command): computer
6983 <first : info string classical evaluation enabled
6984 <first : 1 30 0 30 1 30000 0    c3c4
Impossible move , type = 32
[...]
34160 <first : 5 -15 0 93 5 93000 0    B@e2 f3e2 f1e2 h8g7 d1c1
LegalDrop: 68 @ 6,1)
Impossible move B@e2, type = 25
34161 <first : 6 -15 0 123 6 123000 0    B@e2 f3e2 f1e2 h8g7 d1c1 B@b6
LegalDrop: 68 @ 6,1)
Impossible move B@e2, type = 25
34162 <first : 7 -15 0 160 7 160000 0    B@e2 f3e2 f1e2 h8g7 d1c1 B@b6 d2d3
LegalDrop: 68 @ 6,1)
Impossible move B@e2, type = 25
34163 <first : 8 -15 0 208 8 208000 0    B@e2 f3e2 f1e2 h8g7 d1c1 B@b6 d2d3 g8c8
LegalDrop: 68 @ 6,1)
Impossible move B@e2, type = 25
34164 <first : 9 -15 0 467 10 233500 0    B@e2 f3e2 f1e2 B@b6 d2d3 h8g7 d1c1 g8c8 h2f2 f7f6
LegalDrop: 68 @ 6,1)
Impossible move B@e2, type = 25
34166 <first : 10 38 0 1714 14 428500 0    B@e2 f3e2 f1e2 B@b6 d2d3 h8g7 d1c1 f7f6 f5e6 e7e6
LegalDrop: 68 @ 6,1)
Impossible move B@e2, type = 25
34169 <first : 11 30 1 7988 14 420421 0    B@e2 f3e2 f1e2 h8g7 d1c1 B@b6 d2d3 f9g9 B@f3 g8c8 f3h5 c8g8 b1c3
LegalDrop: 68 @ 6,1)
Impossible move B@e2, type = 25
34170 <first : 12 -23 7 28972 16 381210 0    B@e2 f3e2+ f1e2 h8g7 d1c1 f9g9 h2f2 g9h8 d2d3 f7f6 f5g4 g8c8 f2f1
LegalDrop: 68 @ 6,1)
Impossible move B@e2, type = 25
34171 <first : 13 -7 11 42726 18 374789 0    B@e2 f3e2+ f1e2 h8g7 d1c1 B@b6 d2d3 f9g9 h2f2 g8c8 B@h5 c8g8 h5f3 g8c8 f5e4 f7f6 f4f5
LegalDrop: 68 @ 6,1)
Impossible move B@e2, type = 25
34265 <first : 14 -30 22 84906 19 370768 0    B@e2 f3e2+ f1e2 h8g7 d1c1 f9g9 h2f2 d9e9 B@e4 f7f6 f5g4 g8c8 f4f5 e6e5 e4d3 c6c5 f5f6 c5c4
LegalDrop: 68 @ 6,1)
Impossible move B@e2, type = 25
34341 <second: 16 30 70 249386 28 352738 0    B@f3 B@e2 f3e2+ f1e2 h8g7 d1c1 g8c8 B@d3 c8g8 c2c3 f7f6 f5e4 e6e5 e4f3 c6c5 c4c5 B@f7 c5c6 g8c8 h2f2 c8c6 P@c4
LegalDrop: 68 @ 7,2)
Impossible move B@f3, type = 25
34437 <first : 15 -23 40 146910 23 366359 0    B@e2 f3e2+ f1e2 h8g7 d1c1 f9g9 h2f2 B@b6 d2c3 d6e5 e2d3 f7f6 e3e4 f6f5 e4e5 e6e5 f4f5
LegalDrop: 68 @ 6,1)
Impossible move B@e2, type = 25
34662 <first : 16 -23 62 227827 24 363360 0    B@e2 f3e2+ f1e2 h8g7 d1c1 f9g9 h2f2 d9e9 B@e4 f7f6 f5g4 g8c8 f4f5 d6e5 f5f6 e5f6 e2d3 P@f9 g4f5 f6f5 e4f5 B@f6
LegalDrop: 68 @ 6,1)
Impossible move B@e2, type = 25
34866 <first : 17 -15 83 302193 26 363649 0    B@e2 f3e2+ f1e2 h8g7 d1c1 f9g9 h2f2 B@b6 d2d3 g9h8 i3i4 b9c7 B@f3 f7f6 f5g4 d6e5 f3c6 d9c8
LegalDrop: 68 @ 6,1)
Impossible move B@e2, type = 25
35166 <second: 17 38 153 534672 27 349002 0    B@f3 B@e2 f3e2 f1e2 h8g7 h2f2 f9g9 e2d3 g9h8 d1c1 d9e9 B@f3 f7f6 f5g4 g8c8 g4h5 d6e5 d2c3
LegalDrop: 68 @ 7,2)
Impossible move B@f3, type = 25
35168 <second: move B@f3
LegalDrop: 68 @ 7,2)
Impossible move B@f3, type = 25
GameEnds(26, Xboard: Forfeit due to invalid move: B@f3 (_1_1 via ^0, ^0) res=25, 4)
35171 >first : result 1-0 {Xboard: Forfeit due to invalid move: B@f3 (_1_1 via ^0, ^0) res=25}
35171 >second: result 1-0 {Xboard: Forfeit due to invalid move: B@f3 (_1_1 via ^0, ^0) res=25}
35171 >first : force
35171 >first : ping 2
35171 >second: force
35171 >second: ping 2
35172 <second: Hint: B@e2
35172 <second: info string classical evaluation enabled
35172 <second: 1 38 0 60 1 60000 0    f3e2 f1e2
35172 <second: 2 38 0 118 2 118000 0    f3e2 f1e2
35172 <second: 3 38 0 180 3 180000 0    f3e2 f1e2 h8g7
35172 <second: 4 38 0 244 4 122000 0    f3e2 f1e2 h8g7 h2f2
35172 <second: 5 38 0 314 5 157000 0    f3e2 f1e2 h8g7 h2f2 f9g9
35172 <second: 6 38 0 392 6 196000 0    f3e2 f1e2 h8g7 h2f2 f9g9 e2d3
35173 <second: 7 38 0 503 10 251500 0    f3e2 f1e2 h8g7 h2f2 f9g9 e2d3 g9h8 d1c1 d9e9 B@f3
35173 <second: 8 38 0 662 12 331000 0    f3e2 f1e2 h8g7 h2f2 f9g9 e2d3 g9h8 d1c1 d9e9 B@f3 f7f6 f5g4
35173 <second: 9 38 0 871 16 435500 0    f3e2 f1e2 h8g7 h2f2 f9g9 e2d3 g9h8 d1c1 d9e9 B@f3 f7f6 f5g4 g8c8 g4h5 d6e5 d2c3
35173 <first : 18 -15 113 407544 26 358753 0    B@e2 f3e2+ f1e2 h8g7 d1c1 f9g9 h2f2 B@b6 d2d3 g9h8 i3i4 b9c7 B@f3 f7f6 f5g4 d6e5 f3c6 d9c8
35174 <second: 10 38 0 2545 16 363571 0    f3e2 f1e2 h8g7 h2f2 f9g9 e2d3 g9h8 d1c1 d9e9 B@f3 f7f6 f5g4 g8c8 g4h5 d6e5 d2c3
35174 <second: pong 2
35174 <first : pong 2
GameEnds(26, Xboard: Forfeit due to invalid move: B@f3 (_1_1 via ^0, ^0) res=25, 2)
45018 >first : quit
45029 >second: quit

I've had to cut out the middle because of the character limit.

Re: Trouble with used-defined variants and chess engines

PostPosted: 03 Jan 2023, 15:54
by H.G.Muller
It doesn't seem configured correctly: you promote pieces, but the promoted types are not in the pieceToCharTable. WinBoard probably still uses the legacy way to promote the pieces (i.e. changes them in the piece type 11 places further in the pieceToCharTable, even when this piece type does not have an ID defined for it). But since it is specified nowhere that they should demore on capture, it doesn't do that. So the unpromoted version is then not in the 'pocket', and when an engine tries to drop a piece that is not in hand it will of course be flagged as an illegal move.

The legacy way of defining the promoted pieces is to write a + for them in the pieceToCharTable. That tells WinBoard they should demote when captured. A more advanced way is to write a two-character combination ^ plus letter in the position of the image you want to represent the promoted type with. (Which then can be an arbitrary image, rather than only the image 11 places further in the table). Like ^S for a promoted Silver, etc.

Re: Trouble with used-defined variants and chess engines

PostPosted: 03 Jan 2023, 21:47
by Ivan P
I have entered the promoted pieces into the char table.
Now it reads:
Code: Select all
pieceToCharTable = PNBR.S...G...HD...L..Kpnbr.s...g...hd...l..k

however, the problem with promotion still persists.

Also, even when I load a game of this custom replica of shogi played by the engine (and converted to pgn), the problem still shows up:
Player A takes B's promoted piece -> promoted piece ends up in A's hand.
A few turns later, A tries to place (what it thinks is) the unpromoted piece -> WinBoard throws an error and stops loading the game.

Re: Trouble with used-defined variants and chess engines

PostPosted: 04 Jan 2023, 08:34
by Ivan P
Update. I've tried some additional stuff.
Firstly, I've changed the first line to:
Code: Select all
[shogic:shogi]

so that Fairy-SF's default shogi settings get inherited. It didn't work.
However, when I try to load Fairy-SF's shogi itself, the captured pieces "unpromote" correctly.

The way I've written the game, it works correctly on fairy-SF's testing website: https://fairyground.vercel.app/

Re: Trouble with used-defined variants and chess engines

PostPosted: 04 Jan 2023, 09:32
by H.G.Muller
Well, so the Fairy-SF testing website is broken...

By defining the promoted Bishop and Rook as H and D, you define the variant as 'Loop Shogi', where promoted pieces do not demote when they are captured. To define a demotable piece you would have to specify it as a '+':

pieceToCharTable = PNBR.S...G...++...L..Kpnbr.s...g...++...l..k

WinBoard will then always use +B and +R for the piece in notation; there is no way to assign an independent ID for demotable pieces.

Another flaw is that you did not define promoted versions of Pawn, Knight, Silver and Lance.

Furthermore, beware that in Shogi (and thus also in engine-defined variants that use Shogi as a parent variant) WinBoard uses an alternate set of piece images, for legacy reasons. In particular, the Queen would show up as a Lance (and would also have the preprogrammed move of it). It then uses the (non-configurable) rule that the first 6 piece types promote on reaching the enemy camp. By default WinBoard uses for Shogi:

pieceToCharTable = PNBRLS...G.+++++.....Kpnbrls...g.+++++.....k

Re: Trouble with used-defined variants and chess engines

PostPosted: 19 Jan 2023, 18:23
by haojim
Ivan P wrote:Update. I've tried some additional stuff.
Firstly, I've changed the first line to:
Code: Select all
[shogic:shogi]

so that Fairy-SF's default shogi settings get inherited. It didn't work.
However, when I try to load Fairy-SF's shogi itself, the captured pieces "unpromote" correctly.

The way I've written the game, it works correctly on fairy-SF's testing website: https://fairyground.vercel.app/


I have just played it and I love it. Nice board and pieces, good job man. I hope you sort out the problems.