Did anyone write a xiangqi chess engine?

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
maksimKorzh
Posts: 771
Joined: Sat Sep 08, 2018 5:37 pm
Location: Ukraine
Full name: Maksim Korzh

Re: Did anyone write a xiangqi chess engine?

Post by maksimKorzh »

hgm wrote: Thu Jan 28, 2021 2:40 pm I suppose it depends on what you consider UCI for Xiangqi. The Fairy-Stockfish developers insist that rank counting starts at 1 then. Chinese UCI Xiangqi engines count 0-9. But they also omit the 'position' keyword, do not know 'startpos', and expect the color in the FEN to be indicated as r or b. This is sometimes called the UCI-Cyclone dialect. UCI2WB uses the cyclone dialect only when called with the argument -c, but counts ranks from 0 for a 10-rank board even in UCI.
Hmmm, this is a bit strange - I've been reading through some source google translated from Chinese and it used 0-9 but also position startpos and position fen.

Ok, in this case the question is how should I do the following to play in winboard GUI mode without any params:
1. 0-9 or 1-10?
2. how to do "position startpos" and "position fen"?
3. go depth n seems to the same?
4. What format for go time? I read UCCI does not use wtime/btime

In simple words - what's the bare minimum command set including set opthion hash in MB?

EDIT:
Without seeing commands GUI sends to engine it's very tricky to develop.
I'm sorry but winboard cli mode and command line args are a bit too tricky for me especially bearing in mind
that I'm still using it via wine. I tried Xboard but the version I've downloaded via apt install xboard doesn't have
traditional board and piece and I don't know how to get newer versions.

Winboard is great for those used to work on WIndows but for me as a convinced linux user it's just uncomfortable to work with,
I admire though that winboard is awesome itself and for those using all the power of it's cli it's just a perfect environment.

I also tried XieXie GUI + engine it very looks like winboard but seeml like it doesn't support connecting other engines.

I wish I could have some Arena equivalent for xiangqi, preferably under linux.
Do you know any xiangqi GUIs like that?

P.S. I'm not going to run extensive tests vs other engines just want to play a few matches as a proof of concept.
The main goal is still a friendly environment for beginners to master the game.
User avatar
hgm
Posts: 27796
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Did anyone write a xiangqi chess engine?

Post by hgm »

maksimKorzh wrote: Thu Jan 28, 2021 4:07 pmOk, in this case the question is how should I do the following to play in winboard GUI mode without any params:
1. 0-9 or 1-10?
0-9
[/quote]2. how to do "position startpos" and "position fen"?
3. go depth n seems to the same?
4. What format for go time? I read UCCI does not use wtime/btime
[/quote]
Indeed, UCCI sort of redefined all UCI keywords, or omits them. WinBoard + UCI2WB uses UCI exactly as it would in Chess (except for the 0-9 rank counting, but that is triggered by the board size, independent of the variant.)
Without seeing commands GUI sends to engine it's very tricky to develop.
I'm sorry but winboard cli mode and command line args are a bit too tricky for me especially bearing in mind
that I'm still using it via wine. I tried Xboard but the version I've downloaded via apt install xboard doesn't have
traditional board and piece and I don't know how to get newer versions.
Well, you never know what these maintainers put in their binary packages, but this is a bit surprising. The source repository for XBoard does contain a 'themes' directory with Shogi and Xiangqi pieces, plus a png image for a grid board (and has done so 'for ages'), and these are not large files The included Makefile would automatically install those (on 'make install') in XBoard's 'themes' directory, so that you can select them through the View -> Themes dialog, which should offer Oriental Xiangqi as a pre-configured theme. And usually the binary packages just mimic the "make install". What Linux distro are you using, and what version of XBoard do they offer?

Anyway, it seems to me that to see what goes on between the GUI and the engine it is not very relevant how the pieces look.
Winboard is great for those used to work on WIndows but for me as a convinced linux user it's just uncomfortable to work with,
I admire though that winboard is awesome itself and for those using all the power of it's cli it's just a perfect environment.
This is why there is WinBoard fro Windows, and XBoard for Linux / OS X.
I also tried XieXie GUI + engine it very looks like winboard but seeml like it doesn't support connecting other engines.

I wish I could have some Arena equivalent for xiangqi, preferably under linux.
Do you know any xiangqi GUIs like that?
The only free Xiangqi GUIs I know are XQ Wizard (companion project of the Elephant Eye engine), and BingheWusi. But I think they are both UCCI only (and I am not sure if there are versions with English menus).
User avatar
maksimKorzh
Posts: 771
Joined: Sat Sep 08, 2018 5:37 pm
Location: Ukraine
Full name: Maksim Korzh

Re: Did anyone write a xiangqi chess engine?

Post by maksimKorzh »

hgm wrote: Thu Jan 28, 2021 5:39 pm
maksimKorzh wrote: Thu Jan 28, 2021 4:07 pmOk, in this case the question is how should I do the following to play in winboard GUI mode without any params:
1. 0-9 or 1-10?
0-9
2. how to do "position startpos" and "position fen"?
3. go depth n seems to the same?
4. What format for go time? I read UCCI does not use wtime/btime
[/quote]
Indeed, UCCI sort of redefined all UCI keywords, or omits them. WinBoard + UCI2WB uses UCI exactly as it would in Chess (except for the 0-9 rank counting, but that is triggered by the board size, independent of the variant.)
Without seeing commands GUI sends to engine it's very tricky to develop.
I'm sorry but winboard cli mode and command line args are a bit too tricky for me especially bearing in mind
that I'm still using it via wine. I tried Xboard but the version I've downloaded via apt install xboard doesn't have
traditional board and piece and I don't know how to get newer versions.
Well, you never know what these maintainers put in their binary packages, but this is a bit surprising. The source repository for XBoard does contain a 'themes' directory with Shogi and Xiangqi pieces, plus a png image for a grid board (and has done so 'for ages'), and these are not large files The included Makefile would automatically install those (on 'make install') in XBoard's 'themes' directory, so that you can select them through the View -> Themes dialog, which should offer Oriental Xiangqi as a pre-configured theme. And usually the binary packages just mimic the "make install". What Linux distro are you using, and what version of XBoard do they offer?

Anyway, it seems to me that to see what goes on between the GUI and the engine it is not very relevant how the pieces look.
Winboard is great for those used to work on WIndows but for me as a convinced linux user it's just uncomfortable to work with,
I admire though that winboard is awesome itself and for those using all the power of it's cli it's just a perfect environment.
This is why there is WinBoard fro Windows, and XBoard for Linux / OS X.
I also tried XieXie GUI + engine it very looks like winboard but seeml like it doesn't support connecting other engines.

I wish I could have some Arena equivalent for xiangqi, preferably under linux.
Do you know any xiangqi GUIs like that?
The only free Xiangqi GUIs I know are XQ Wizard (companion project of the Elephant Eye engine), and BingheWusi. But I think they are both UCCI only (and I am not sure if there are versions with English menus).
[/quote]

Thanks, I'll hack around Xboard. Just need to download latest version and build on my own.
User avatar
maksimKorzh
Posts: 771
Joined: Sat Sep 08, 2018 5:37 pm
Location: Ukraine
Full name: Maksim Korzh

Re: Did anyone write a xiangqi chess engine?

Post by maksimKorzh »

hgm wrote: Thu Jan 28, 2021 5:39 pm
maksimKorzh wrote: Thu Jan 28, 2021 4:07 pmOk, in this case the question is how should I do the following to play in winboard GUI mode without any params:
1. 0-9 or 1-10?
0-9
2. how to do "position startpos" and "position fen"?
3. go depth n seems to the same?
4. What format for go time? I read UCCI does not use wtime/btime
[/quote]
Indeed, UCCI sort of redefined all UCI keywords, or omits them. WinBoard + UCI2WB uses UCI exactly as it would in Chess (except for the 0-9 rank counting, but that is triggered by the board size, independent of the variant.)
Without seeing commands GUI sends to engine it's very tricky to develop.
I'm sorry but winboard cli mode and command line args are a bit too tricky for me especially bearing in mind
that I'm still using it via wine. I tried Xboard but the version I've downloaded via apt install xboard doesn't have
traditional board and piece and I don't know how to get newer versions.
Well, you never know what these maintainers put in their binary packages, but this is a bit surprising. The source repository for XBoard does contain a 'themes' directory with Shogi and Xiangqi pieces, plus a png image for a grid board (and has done so 'for ages'), and these are not large files The included Makefile would automatically install those (on 'make install') in XBoard's 'themes' directory, so that you can select them through the View -> Themes dialog, which should offer Oriental Xiangqi as a pre-configured theme. And usually the binary packages just mimic the "make install". What Linux distro are you using, and what version of XBoard do they offer?

Anyway, it seems to me that to see what goes on between the GUI and the engine it is not very relevant how the pieces look.
Winboard is great for those used to work on WIndows but for me as a convinced linux user it's just uncomfortable to work with,
I admire though that winboard is awesome itself and for those using all the power of it's cli it's just a perfect environment.
This is why there is WinBoard fro Windows, and XBoard for Linux / OS X.
I also tried XieXie GUI + engine it very looks like winboard but seeml like it doesn't support connecting other engines.

I wish I could have some Arena equivalent for xiangqi, preferably under linux.
Do you know any xiangqi GUIs like that?
The only free Xiangqi GUIs I know are XQ Wizard (companion project of the Elephant Eye engine), and BingheWusi. But I think they are both UCCI only (and I am not sure if there are versions with English menus).
[/quote]

I'm having issues with installing my xiangqi engine into xboard.
Here's a line I took from registered engines:
"Wukong" -fcp "/home/maksim/Desktop_CMK/wukong-xiangqi/src/engine/uci.js" -fd "/home/maksim/Downloads/node-v14.15.3-linux-x64/bin" -fn "Wukong" -fUCI

My actual paths are:
Engine's UCI interface: "/home/maksim/Desktop_CMK/wukong-xiangqi/src/engine/uci.js"
Nodejs binary: "/home/maksim/Downloads/node-v14.15.3-linux-x64/bin"

But when I select them and try to run it prints the error path not found.
It prints "Wukong" as -fn (filename?) but it's wrong - it should be "node" and I can't change that.

How can I setup engine executed by nodejs into xboard?

P.S. Above was resulted after specifying "node" directory (it doesn't allow to pick up file, only directory!! Why?!)
as engine executable and this "/home/maksim/Desktop_CMK/wukong-xiangqi/src/engine/uci.js" as command line prameter.
I tried with and without double quotes around path but it doesn't help.
User avatar
gbtami
Posts: 389
Joined: Wed Sep 26, 2012 1:29 pm
Location: Hungary

Re: Did anyone write a xiangqi chess engine?

Post by gbtami »

maksimKorzh wrote: Thu Jan 28, 2021 4:07 pm I wish I could have some Arena equivalent for xiangqi, preferably under linux.
Do you know any xiangqi GUIs like that?
There is a pending PR by gaintpd for Xiangqi support in cutechess github repo.
https://github.com/gaintpd/cutechess/tree/xiangqi
https://github.com/cutechess/cutechess/pull/565

There is an interesting (and lengthy!) discussion about all of the protocols you can choose from for Xiangqi engines: CECP, UCI, UCCI, UCI-Cyclone
https://github.com/ianfab/Fairy-Stockfish/issues/194
User avatar
hgm
Posts: 27796
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Did anyone write a xiangqi chess engine?

Post by hgm »

maksimKorzh wrote: Fri Jan 29, 2021 12:57 amI'm having issues with installing my xiangqi engine into xboard.
Here's a line I took from registered engines:
"Wukong" -fcp "/home/maksim/Desktop_CMK/wukong-xiangqi/src/engine/uci.js" -fd "/home/maksim/Downloads/node-v14.15.3-linux-x64/bin" -fn "Wukong" -fUCI

My actual paths are:
Engine's UCI interface: "/home/maksim/Desktop_CMK/wukong-xiangqi/src/engine/uci.js"
Nodejs binary: "/home/maksim/Downloads/node-v14.15.3-linux-x64/bin"

But when I select them and try to run it prints the error path not found.
It prints "Wukong" as -fn (filename?) but it's wrong - it should be "node" and I can't change that.

How can I setup engine executed by nodejs into xboard?

P.S. Above was resulted after specifying "node" directory (it doesn't allow to pick up file, only directory!! Why?!)
as engine executable and this "/home/maksim/Desktop_CMK/wukong-xiangqi/src/engine/uci.js" as command line prameter.
I tried with and without double quotes around path but it doesn't help.
".../uci.js" is not a valid command, is it? I never have used nodejs under Linux, but I don't think that Linux would automatically invoke it (and certainly not if it wasn't in a standard place like /usr/bin) when you try to execute a .js file, like it would invoke the shell if you try to execute a text file with a shell script. (And then only when you had given it an executable mode.) Does what you give as -fcp work if you type it on the command line? What doesn't work from the command line (possibly after changing to what you specified as -fd) would also not work as -fcp argument.

I expect that you have to specify nodejs as engine binary, with uci.js as argument. Like

-fcp "nodejs uci.js"

where you could use pathnames to make it independent on the directory you are in. Linux-compliant engines usually don't care what directory they run in; they know where their support files (such as books) are to be found, and these would not be in the current directory anyway. I don't know whether nodejs cares from which directory you run it. I suppose the path to it would be in your search path, and then a simple "nodejs" command would work from anywhere; if not then you would have to specify the path name. Note that even when you change to its directory first, you could still not run it through "nodejs", but Linux would insist that you specify it as "./nodejs".

I suppose you did install UCI2WB as well as XBoard?
User avatar
maksimKorzh
Posts: 771
Joined: Sat Sep 08, 2018 5:37 pm
Location: Ukraine
Full name: Maksim Korzh

Re: Did anyone write a xiangqi chess engine?

Post by maksimKorzh »

gbtami wrote: Fri Jan 29, 2021 10:20 am
maksimKorzh wrote: Thu Jan 28, 2021 4:07 pm I wish I could have some Arena equivalent for xiangqi, preferably under linux.
Do you know any xiangqi GUIs like that?
There is a pending PR by gaintpd for Xiangqi support in cutechess github repo.
https://github.com/gaintpd/cutechess/tree/xiangqi
https://github.com/cutechess/cutechess/pull/565

There is an interesting (and lengthy!) discussion about all of the protocols you can choose from for Xiangqi engines: CECP, UCI, UCCI, UCI-Cyclone
https://github.com/ianfab/Fairy-Stockfish/issues/194
Thanks for info!
User avatar
maksimKorzh
Posts: 771
Joined: Sat Sep 08, 2018 5:37 pm
Location: Ukraine
Full name: Maksim Korzh

Re: Did anyone write a xiangqi chess engine?

Post by maksimKorzh »

hgm wrote: Fri Jan 29, 2021 11:13 am
maksimKorzh wrote: Fri Jan 29, 2021 12:57 amI'm having issues with installing my xiangqi engine into xboard.
Here's a line I took from registered engines:
"Wukong" -fcp "/home/maksim/Desktop_CMK/wukong-xiangqi/src/engine/uci.js" -fd "/home/maksim/Downloads/node-v14.15.3-linux-x64/bin" -fn "Wukong" -fUCI

My actual paths are:
Engine's UCI interface: "/home/maksim/Desktop_CMK/wukong-xiangqi/src/engine/uci.js"
Nodejs binary: "/home/maksim/Downloads/node-v14.15.3-linux-x64/bin"

But when I select them and try to run it prints the error path not found.
It prints "Wukong" as -fn (filename?) but it's wrong - it should be "node" and I can't change that.

How can I setup engine executed by nodejs into xboard?

P.S. Above was resulted after specifying "node" directory (it doesn't allow to pick up file, only directory!! Why?!)
as engine executable and this "/home/maksim/Desktop_CMK/wukong-xiangqi/src/engine/uci.js" as command line prameter.
I tried with and without double quotes around path but it doesn't help.
".../uci.js" is not a valid command, is it? I never have used nodejs under Linux, but I don't think that Linux would automatically invoke it (and certainly not if it wasn't in a standard place like /usr/bin) when you try to execute a .js file, like it would invoke the shell if you try to execute a text file with a shell script. (And then only when you had given it an executable mode.) Does what you give as -fcp work if you type it on the command line? What doesn't work from the command line (possibly after changing to what you specified as -fd) would also not work as -fcp argument.

I expect that you have to specify nodejs as engine binary, with uci.js as argument. Like

-fcp "nodejs uci.js"

where you could use pathnames to make it independent on the directory you are in. Linux-compliant engines usually don't care what directory they run in; they know where their support files (such as books) are to be found, and these would not be in the current directory anyway. I don't know whether nodejs cares from which directory you run it. I suppose the path to it would be in your search path, and then a simple "nodejs" command would work from anywhere; if not then you would have to specify the path name. Note that even when you change to its directory first, you could still not run it through "nodejs", but Linux would insist that you specify it as "./nodejs".

I suppose you did install UCI2WB as well as XBoard?
I've created shell file with command running "node uci.js", both has absolute paths.
I've pasted this shell file into /usr/bin
Now no matter what directory I'm currently at I can run just "wukong" and it would invoke the script and engines enters UCI mode.

then I set following in the engine list:
"Wukong" -fcp wukong -fUCI
also there a I have say:
"Fruit2,1" -fcp fruit -fUCI

But neither works.
Well I obviously don't have fruit installed system wide, but "wukong" now works as whatever linux command so I assume it should be working as a single engine executable which it literally is now.

However I'm still getting error:
polyglot -ec "wukong" -ed "." ... file not found

I didn't install UCI2WB, I don't know how to do it.
Seems like polyglot does the same but it still can't see path even though engine is now available system wide.

I also tried to specify engine directoy and engine command from GUI,
it gives the following error:
polyglot -ec "wukong" -ed "/usr/bin" ... file not found

good news: I found xiangqi pieces/textures for xboard
User avatar
maksimKorzh
Posts: 771
Joined: Sat Sep 08, 2018 5:37 pm
Location: Ukraine
Full name: Maksim Korzh

Re: Did anyone write a xiangqi chess engine?

Post by maksimKorzh »

I've finally managed to run my javascript xiangqi engine under xboard using linux version of uci2wb
and it even starts calculating but never makes a move for some reason.
User avatar
hgm
Posts: 27796
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Did anyone write a xiangqi chess engine?

Post by hgm »

I am not sure whether putting the command in a shell file does work. That you seem to be able to run it system wide from the command line suggest that it should. But there is something I don't understand: If I run a shell script, the commands in that script are supposed to take their input from the script, right? But after the commands "node uci.js" there is nothing left in that script, so the command runs into an end-of-file. How would the nodejs interpreter know that it has to go back reading commands from the keyboard? (Or from XBoard, when it was launched through XBoard?)

I don't see the need for using the shell script; it seems just to complicate matters. And what is now in that script isn't terribly complicated, right, just a single command on one line. Why don't you simply write that command (in quotes) behind the -fcp option?

If nodejs was properly installed, it should be available system wide from the command line. The binary would either be in a directory that is already in the system's search path (e.g. /usr/bin/), or the directory where it is should have been added to the search path during the install. Then you wouldn't have to specify a path name, or a directory, and a simple -fcp "node uci.js" would be sufficient when you already are in the directory that contains uci.js . But even if not, you could simply write the full path name of nodejs.

You still have several other problems, though.

The standard install for XBoard is configured to use Polyglot as adapter for UCI (when you specify -fUCI or tick the UCI checkbox). The error message you quote (I suppose they really said "polyglot -noini -ec wukong -ed .") suggest that you did not install Polyglot, however. In that case you should not be surprised that XBoard cannot find the file.

Now installing Polyglot won't help you anyway, because Polyglot is a Chess-only adapter, which cannot be used for Xiangqi; it would simply refuse all the moves as illegal. The standard XBoard install is configured to use UCI2WB as adapter when you specify -fUCCI or -fUSI, but then it would automatically use UCCI when you play Xiangqi.

So what you have to do is first configure XBoard to also use UCI2WB when you select UCI. For this you have to run XBoard once, with the command

xboard -adapterCommand {uci2wb debug "%fcp" "%fd"}

Then you have of course to install UCI2WB on your machine. If apt-get install doesn't work for that, you can getdownload the sources of that from my on-line repository (latest snapshot) at http://hgm.nubati.net/cgi-bin/gitweb.cgi , unzip it, and install it through issuing the commands

make
sudo make install

from the directory where you unzipped the source code. After that the 'uci2wb' command should be available system wide, and XBoard would know it should use it.