Sjaak II, Wa Shogi and XBoard 4.9

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

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

Re: Sjaak II, Wa Shogi and XBoard 4.9

Post by hgm »

Normally winboard.nl is just a mirror of hgm.nubati.net. But there seems to be a problem with the ssh keys for hgm.nubati.net which prevents me from pushing anything to it. Untill I solve that winboard.nl is ahead of hgm.nubati.net.

I think I had the same problem yesterday evening, XBoard choking on the 'piece' commands for promoted pieces when I was making HaChu emit those. It turned out the code there was not yet adapted to the new piece ordering. The latest version in the winboard.nl repository should have this fixed.

I used washogi as variant name before in HaChu, but it looked very ugly on the variant-selection button. Fairy-Max already used a few variant names with dashes in them too (king-of-the-hill, team-mate, light-brigade, almost-wildebeest). Perhaps I should call it dropless-wa, however, to distinguish it from wa-with-drops.

As to XBoard's ability to play Wa with drops: I think it can currently do it, but only by defining the board as 11x16 (or 11x14 if you have CE and TF demote on capture), and blacking out anything beyond rank 11. This is pretty ugly. I see no easy way to fix it, though. The way XBoard handles holdings (the blacked-out column between holdings and board containing the holdings counts) is not easy to generalize to multi-column holdings. Wa with drops seems the only game that suffers from this, which doesn't provide a very large incentive to completely overhaul the system. It would be nice if the blacked-out board space could be distributed symmetrically above and under the board, but that would lead to unnatural board coordinates in the move notation, which is much worse than a cosmetically flawed display. (Omega Chess suffers from this too, BTW.)

A hack that might work for Wa is to alter the board-drawing routine to not draw all ranks of the board (which would be defined as 11x16+16), but just the first 11 (configurable by an option) of the proper board, and squeeze out all empty squares from the holdings. When doing this it would have to prepare a translation table for mouse clicks in the holdings, to translate the rank coordinate of the actual click back to the rank coordinate of the internal representation. But if you get more than 11 piece types in hand you are cooked. Although you could always type the move to drop a piece that is currently not displayed. (But is it realistic to assume this would ever happen?)
User avatar
Evert
Posts: 2929
Joined: Sat Jan 22, 2011 12:42 am
Location: NL

Re: Sjaak II, Wa Shogi and XBoard 4.9

Post by Evert »

hgm wrote:Normally winboard.nl is just a mirror of hgm.nubati.net. But there seems to be a problem with the ssh keys for hgm.nubati.net which prevents me from pushing anything to it. Untill I solve that winboard.nl is ahead of hgm.nubati.net.

I think I had the same problem yesterday evening, XBoard choking on the 'piece' commands for promoted pieces when I was making HaChu emit those. It turned out the code there was not yet adapted to the new piece ordering. The latest version in the winboard.nl repository should have this fixed.
Ok, I'll check that out later today.
As to XBoard's ability to play Wa with drops: I think it can currently do it, but only by defining the board as 11x16 (or 11x14 if you have CE and TF demote on capture), and blacking out anything beyond rank 11. This is pretty ugly. I see no easy way to fix it, though. The way XBoard handles holdings (the blacked-out column between holdings and board containing the holdings counts) is not easy to generalize to multi-column holdings. Wa with drops seems the only game that suffers from this, which doesn't provide a very large incentive to completely overhaul the system. It would be nice if the blacked-out board space could be distributed symmetrically above and under the board, but that would lead to unnatural board coordinates in the move notation, which is much worse than a cosmetically flawed display. (Omega Chess suffers from this too, BTW.)

A hack that might work for Wa is to alter the board-drawing routine to not draw all ranks of the board (which would be defined as 11x16+16), but just the first 11 (configurable by an option) of the proper board, and squeeze out all empty squares from the holdings. When doing this it would have to prepare a translation table for mouse clicks in the holdings, to translate the rank coordinate of the actual click back to the rank coordinate of the internal representation. But if you get more than 11 piece types in hand you are cooked. Although you could always type the move to drop a piece that is currently not displayed. (But is it realistic to assume this would ever happen?)
Hmm... I might be able to work around that, then, but it requires a bit of work. Internally, 11x11 is the limit of what SjaakII can represent, so 11x16 as an internal representation is right out. Doesn't matter, because it only needs to translate the internal 11x11 to 11x16 for XBoard, but that translation needs a bit of thought behind it...
It's almost as simple as fudging the starting FEN with extra blacked-out back ranks if #holdings > #ranks, except that it needs to know to skip those on input as well.
User avatar
hgm
Posts: 27787
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Sjaak II, Wa Shogi and XBoard 4.9

Post by hgm »

Perhaps the FEN problem should be solved in XBoard, as FENs are not only used for comunication with the engine. In the interpretation of the 'setup' command I could intercept the case FxR+H where H > R, and make XBoard in that case set R=H, but also set a variable deadRanks to H-R (while normally it would be kept at 0). This deadRanks would then only be used in the FEN parser and generator: When parsing it would imagine that many uppermost ranks to be DarkSquares. And when generating it would simply ignore those ranks.

This should make the whole issue invisible to the engine. Which is as it should be, as this is purely a display issue.
User avatar
hgm
Posts: 27787
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Sjaak II, Wa Shogi and XBoard 4.9

Post by hgm »

I think I fixed it: engines can set the holdings size larger than the board height now. Not sure what the effect is on loading PGN files, though, as I reset deadRanks to 0 in XBoard's Reset() function (which is called when you press New Game), assuming that this will send a new variant command to the engine, and that this will set it back before its FEN is going to be parsed. The PGN can also contain a FEN, however. But IIRC I avoided Reset() on PGN load when the variant does not change, as this would give trouble with engine-defined variants anyway. So I hope everything will work.
User avatar
Evert
Posts: 2929
Joined: Sat Jan 22, 2011 12:42 am
Location: NL

Re: Sjaak II, Wa Shogi and XBoard 4.9

Post by Evert »

hgm wrote:I think I fixed it: engines can set the holdings size larger than the board height now. Not sure what the effect is on loading PGN files, though, as I reset deadRanks to 0 in XBoard's Reset() function (which is called when you press New Game), assuming that this will send a new variant command to the engine, and that this will set it back before its FEN is going to be parsed. The PGN can also contain a FEN, however. But IIRC I avoided Reset() on PGN load when the variant does not change, as this would give trouble with engine-defined variants anyway. So I hope everything will work.
Seems to work great; the board display is rather ugly (with the large empty black space above it), but the fact that this works is a significant improvement either way. Cosmetic fixes, if feasible at all, can come later.

I'm using the following rules definition for SjaakII, which should work with the last release (there are some funny bits in the Betza output that I've fixed since, but nothing that should completely break things):

Code: Select all

####################### 
# WaShogi, with drops # 
####################### 
Variant: WaShogi (11x11) 
Board: 11x11 
FEN: "hmlcvkwgudo/1e3s3f1/ppprpppxppp/3p3p3/11/11/11/3P3P3/PPPXPPPRPPP/1F3S3E1/ODUGWKVCLMH w 0 1"
XBoard pieces: "P..^S^FV..^LW^OH.F.^R.E....R...D.GOL^M..^H.M.C.^CU.^W/.......^V.^P.^U..^DS.^GXKp..^s^fv..^lw^oh.f.^r.e....r...d.gol^m..^h.m.c.^cu.^w/.......^v.^p.^u..^ds.^gxk"
XBoard parent:  "chu" 
Zone: white_promotion = a11,b11,c11,d11,e11,f11,g11,h11,i11,j11,k11,a10,b10,c10,d10,e10,f10,g10,h10,i10,j10,k10,a9,b9,c9,d9,e9,f9,g9,h9,i9,j9,k9
Zone: black_promotion = a3,b3,c3,d3,e3,f3,g3,h3,i3,j3,k3,a2,b2,c2,d2,e2,f2,g2,h2,i2,j2,k2,a1,b1,c1,d1,e1,f1,g1,h1,i1,j1,k1 

# crane King, K=King 
# cloud Eagle, E
# flying Falcon F promotes to *Tenacious Falcon 
# Swallows wings, S promotes to *Gliding Swallow 
# treacherous foX, X
# running Rabbit, R promotes to *Treacherous fox 
# violent Wolf, W promotes to *Bear's Eyes 
# Violent stag, V promotes to *Roaming Boar 
# flying Goose, G promotes to *Swallow's Wings 
# flying Cock, C promotes to *Raiding Falcon 
# strUtting crow, U promotes to *Flying Falcon 
# swooping owL, L promotes to *Cloud Eagle 
# blind Dog, D promotes to *Violent Wolf 
# climbing Monkey, M promotes to *Violent Stag 
# liberated Horse, H promotes to  *Heavenly Horse 
# Oxcart, O promotes to *Plodding Ox 
# sparrow Pawn, P=Pawn promotes to *Golden Bird 


# Define the pieces 

Piece: Crane King 
Symbol: "K", "K,k" 
Move: leap (0,1)|(1,1) 
Flags: royal 

Piece: Cloud Eagle 
Symbol: "E", "E,e" 
Move: slide (V) 
Move: step W,E,SW,SE,3NW,3NE 
Value: 850 

Piece: Treacherous Fox 
Symbol: "X", "X,x" 
Move: aleap (1,1)|(2,2)|(-1,1)|(-2,2)|(1,-1)|(2,-2)|(-1,-1)|(-2,-2)|(0,1)|(0,2)|(0,-1)|(0,-2)
Value: 750 

Piece: Flying Falcon 
Symbol: "F", "F,f" 
Move: slide (D,A) 
Move: step N 
Promotion: white_promotion, black_promotion, "+" 
Value: 600 

Piece: Tenacious Falcon 
Symbol: "+F", "+F,+f" 
Move: slide (V,A,D) 
Move: step W,E 
Value: 700 

Piece: Running Rabbit 
Symbol: "R", "R,r" 
Move: step NE,NW,SE,S,SW,10N
Promotion: white_promotion, black_promotion, "+" 
Value: 400 

Piece: Promoted Running Rabbit 
Symbol: "+R", "+R,+r" 
Move: aleap (1,1)|(2,2)|(-1,1)|(-2,2)|(1,-1)|(2,-2)|(-1,-1)|(-2,-2)|(0,1)|(0,2)|(0,-1)|(0,-2)
Value: 750 

Piece: Violent Wolf 
Symbol: "W", "W,w" 
Move: aleap (1,0)|(-1,0)|(0,1)|(0,-1)|(1,1)|(-1,1)
Promotion: white_promotion, black_promotion, "+" 
Value: 400 

Piece: Bears Eyes 
Symbol: "+W", "+W,+w" 
Move: leap (0,1)|(1,1) 

Piece: Violent Stag 
Symbol: "V", "V,v" 
Move: aleap (0,1)|(1,1)|(1,-1)|(-1,-1)|(-1,1)
Promotion: white_promotion, black_promotion, "+" 

Piece: Roaming Boar 
Symbol: "+V", "+V,+v" 
Move: aleap (1,0)|(-1,0)|(0,1)|(1,1)|(-1,1)|(-1,-1)|(1,-1)

Piece: Blind Dog 
Symbol: "D", "D,d" 
Move: aleap (-1,1)|(1,1)|(-1,0)|(1,0)|(0,-1)
Promotion: white_promotion, black_promotion, "+" 

Piece: Promoted Blind Dog 
Symbol: "+D", "+D,+d" 
Move: aleap (1,0)|(-1,0)|(0,1)|(0,-1)|(1,1)|(-1,1)

Piece: Climbing Monkey 
Symbol: "M", "M,m" 
Move: aleap (-1,1)|(0,1)|(1,1)|(0,-1)
Promotion: white_promotion, black_promotion, "+" 

Piece: Promoted Climbing Monkey 
Symbol: "+M", "+M,+m" 
Move: aleap (0,1)|(1,1)|(1,-1)|(-1,-1)|(-1,1)

Piece: Flying Goose 
Symbol: "G", "G,g" 
Move: aleap (-1,1)|(0,1)|(1,1)|(0,-1)
Promotion: white_promotion, black_promotion, "+" 

Piece: Promoted Flying Goose 
Symbol: "+G", "+G,+g" 
Move: slide (H) 
Move: aleap (0,1)|(0,-1)

Piece: Flying Cock 
Symbol: "C", "C,c" 
Move: aleap (-1,1)|(-1,0)|(1,1)|(1,0)
Promotion: white_promotion, black_promotion, "+" 

Piece: Raiding Falcon 
Symbol: "+C", "+C,+c" 
Move: aleap (-1,1)|(-1,0)|(1,1)|(1,0)
Move: slide (V)

Piece: Swallows Wings 
Symbol: "S", "S,s" 
Move: slide (H) 
Move: aleap (0,1)|(0,-1)
Promotion: white_promotion, black_promotion, "+" 

Piece: Gliding Swallow 
Symbol: "+S", "+S,+s" 
Move: slide (H,V)

Piece: Strutting Crow 
Symbol: "U", "U,u" 
Move: aleap (-1,-1)|(1,-1)|(0,1)
Promotion: white_promotion, black_promotion, "+" 

Piece: Promoted Strutting Cow 
Symbol: "+U", "+U,+u" 
Move: slide (D,A) 
Move: step N 

Piece: Swooping Owl 
Symbol: "L", "L,l" 
Move: aleap (-1,-1)|(1,-1)|(0,1)
Promotion: white_promotion, black_promotion, "+" 

Piece: Cloud Eagle (Promoted Swooping Owl) 
Symbol: "+L", "+L,+l" 
Move: slide (V) 
Move: step W,E,SW,SE,3NW,3NE 

Piece: Liberated Horse 
Symbol: "H", "H,h" 
Move: step 10N,2S 
Promotion: white_promotion, black_promotion, "+" 

Piece: Heavenly Horse 
Symbol: "+H", "+H,+h" 
Move: aleap (1,2)|(-1,2)|(1,-2)|(-1,-2) 

Piece: Oxcart 
Symbol: "O", "O,o" 
Move: step 10N 
Promotion: white_promotion, black_promotion, "+" 

Piece: Plodding Ox (Promoted Oxcart) 
Symbol: "+O", "+O,+o" 
Move: leap (0,1)|(1,1) 

Piece: Sparrow Pawn 
Symbol: "P", "P,p" 
Move: step N
Promotion: white_promotion, black_promotion, "+" 
Flags: drop_no_mate, drop_one_file 
Value: 80 

Piece: Golden Bird (Promoted Sparrow Pawn)
Symbol: "+P", "+P,+p" 
Move: aleap (1,0)|(-1,0)|(0,1)|(0,-1)|(1,1)|(-1,1) 
Value: 450 

Rule: keep capture, allow drops 
Rule: repeat4 = draw 
Rule: perpetual4 = loss 
Commenting (or removing) the "Rule: keep capture, allow drops" line will make it play without drops.
Search depth is atrocious, as is perhaps to be expected.
User avatar
Evert
Posts: 2929
Joined: Sat Jan 22, 2011 12:42 am
Location: NL

Re: Sjaak II, Wa Shogi and XBoard 4.9

Post by Evert »

Something doesn't appear to be right:

Code: Select all

New game (1): Sjaak II 583:584M-HaChu 0.21 (w)
1005 >first : computer
1005 >second: computer
1005 >first : time 1000
1005 >first : otim 1000
book hit = (NULL)
1005 >first : go
nps: w=-1, b=-1
1006 <first &#58; # Begin iterative deepening loop for position "hmlcvkwgudo/1e3s3f1/ppprpppxppp/3p3p3/11/11/11/3P3P3/PPPXPPPRPPP/1F3S3E1/ODUGWKVCLMH w 0 1"
1006 <second&#58; # in &#40;mode = 1,0&#41;&#58; setboard
1006 <second&#58; # convert FEN 'hmlcvkwgudo/1e3s3f1/ppprpppxppp/3p3p3/11/11/11/3P3P3/PPPXPPPRPPP/1F3S3E1/ODUGWKVCLMH w - 0 1'
1006 <second&#58; # flipped FEN 'ODUGWKVCLMH/1F3S3E1/PPPXPPPRPPP/3P3P3/11/11/11/3p3p3/ppprpppxppp/1e3s3f1/hmlcvkwgudo'
1006 <second&#58; # converted FEN '&#58;KN&#58;DKUG&#58;EWK&#58;VMCL&#58;SM&#58;DH/.&#58;FL...S...&#58;DE./PPP&#58;PHPPPRPPP/...P...P.../.........../.........../.........../...p...p.../ppprppp&#58;phppp/.&#58;de...s...&#58;fl./&#58;dh&#58;smlc&#58;vmk&#58;ewgu&#58;dk&#58;kn'
1006 <second&#58; tellusererror Unknown piece 'U' in setup
1019 <first &#58;   2   -47      0       220  1. Rg4 Re8
Impossible move , type = 32
1019 <first &#58;   3   -39      0       485  1. Rg4 Re8 2. Ei2 Rxe3+ 3. Rxg9+
Impossible move , type = 32
GameEnds&#40;26, Error&#58; second chess program &#40;hachu&#41; exited unexpectedly, 2&#41;
User avatar
Evert
Posts: 2929
Joined: Sat Jan 22, 2011 12:42 am
Location: NL

Re: Sjaak II, Wa Shogi and XBoard 4.9

Post by Evert »

Unrelated, but I keep dragging along the following patch, which I guess I've never shared:

Code: Select all

--- board.c.old	2016-04-28 23&#58;37&#58;13.000000000 +0200
+++ board.c	2016-04-28 23&#58;39&#58;57.000000000 +0200
@@ -236,12 +236,14 @@
     int square_color;
 
     if &#40;gameInfo.variant == VariantXiangqi&#41; &#123;
-        if &#40;column >= 3 && column <= 5 && row >= 0 && row <= 2&#41; &#123;
-            square_color = 1;
-        &#125; else if &#40;column >= 3 && column <= 5 && row >= 7 && row <= 9&#41; &#123;
-            square_color = 0;
-        &#125; else if &#40;row <= 4&#41; &#123;
+        int col1 = gameInfo.boardWidth / 3;
+        int col2 = col1 + 2;
+        if &#40;column >= col1 && column <= col2 && row >= 0 && row <= 2&#41; &#123;
+            square_color = 1 - &#40;gameInfo.boardHeight & 1&#41;;
+        &#125; else if &#40;column >= col1 && column <= col2 && row >= gameInfo.boardHeight-3 && row < gameInfo.boardHeight&#41; &#123;
             square_color = 0;
+        &#125; else if &#40;row < gameInfo.boardHeight/2&#41; &#123;
+            square_color = gameInfo.boardHeight & 1;
         &#125; else &#123;
             square_color = 1;
         &#125;
It changes the way the Palace (and both river banks) are drawn in XiangQi variants. Basically, it centres the Palace on the central file, and it flips the colour for the lower half of the board for odd board ranks (which presumes there is no river, but the alternative looks odd).

The only variant this influences is "mini_xiangqi", which is perhaps not so important, but it'd be nice to not have to carry this patch around.
User avatar
hgm
Posts: 27787
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Sjaak II, Wa Shogi and XBoard 4.9

Post by hgm »

Should the Palace always be 3x3, irrespective of board size? My fix for Advisor confinement would not work if the Palace isn't 3x3.
User avatar
hgm
Posts: 27787
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Sjaak II, Wa Shogi and XBoard 4.9

Post by hgm »

As to HaChu, I guess it cannot handle setboard commands in Wa. I am currently re-writing the position setup, as the old one was awful. (HaChu had an internal two-letter system for labeling pieces, and it translated FEN IDs to those labels, but unfortunately in an almost variant-independent way, which force me to tabulate pieces with very inappropriate two-letter names in variants that differed significantly from Chu Shogi. I never fixed this, as it was clear that FEN would break down for the larger variants, but it was not clear what would replace it. Now that I adopted the dressed-letter IDs in XBoard, this has finally become clear, so I can finally fix it. In any case I will add a variant-dependent translation table for dressed letters to internal sensible two-letter names.)
User avatar
Evert
Posts: 2929
Joined: Sat Jan 22, 2011 12:42 am
Location: NL

Re: Sjaak II, Wa Shogi and XBoard 4.9

Post by Evert »

hgm wrote:Should the Palace always be 3x3, irrespective of board size? My fix for Advisor confinement would not work if the Palace isn't 3x3.
Well, in terms of XinagQi variants, I know exactly 2 in addition to the "normal" game. One is the Korean variant, which uses the same board, and the "mini" variant I mentioned. They all have 3x3 palaces.

Conceptually it could be any size, of course, but with no way to communicate that picking 3x3 as a fixed size is as good as any other choice.