c-chess-cli

Discussion of chess software programming and technical issues.

Moderator: Ras

lucasart
Posts: 3243
Joined: Mon May 31, 2010 1:29 pm
Full name: lucasart

c-chess-cli: generating training data for NN eval

Post by lucasart »

Just added a sampling feature to generate training data (= position + search result), fast and scalably (concurrency supported). This can be used to to teach a neural network to evaluate chess positions.
https://github.com/lucasart/c-chess-cli/#sampling

Hopefully some people will be interested in designing and training their own NN eval, rather than copy/pasting NNUE into their engine.
Theory and practice sometimes clash. And when that happens, theory loses. Every single time.
User avatar
Roland Chastain
Posts: 705
Joined: Sat Jun 08, 2013 10:07 am
Location: France
Full name: Roland Chastain

Re: c-chess-cli

Post by Roland Chastain »

Very interesting project.

I have just made a first quick test. One engine doesn't find its opening book, and this results in the following problem:

Code: Select all

SlowChess Blitz Classic 2.1 <- ucinewgame
deadline set: SlowChess Blitz Classic 2.1 must respond by 55389187
SlowChess Blitz Classic 2.1 <- isready
SlowChess Blitz Classic 2.1 -> Error Error Loading Book openingBook/TestBook.scbreadyok
deadline passed: SlowChess Blitz Classic 2.1 responded at 55388281, 906ms before the deadline.
deadline passed: SlowChess Blitz Classic 2.1 responded at 55388381, 806ms before the deadline.
deadline passed: SlowChess Blitz Classic 2.1 responded at 55388481, 706ms before the deadline.
I wonder why "readyok" is stuck to the error message.

But the first problem (I believe) is that c-chess-cli doesn't seem to change current directory. Am I wrong?
Qui trop embrasse mal étreint.

Author of Eschecs, a simple UCI chess GUI written in Pascal.
lucasart
Posts: 3243
Joined: Mon May 31, 2010 1:29 pm
Full name: lucasart

Re: c-chess-cli

Post by lucasart »

Roland Chastain wrote: Fri Aug 21, 2020 9:39 am Very interesting project.

I have just made a first quick test. One engine doesn't find its opening book, and this results in the following problem:

Code: Select all

SlowChess Blitz Classic 2.1 <- ucinewgame
deadline set: SlowChess Blitz Classic 2.1 must respond by 55389187
SlowChess Blitz Classic 2.1 <- isready
SlowChess Blitz Classic 2.1 -> Error Error Loading Book openingBook/TestBook.scbreadyok
deadline passed: SlowChess Blitz Classic 2.1 responded at 55388281, 906ms before the deadline.
deadline passed: SlowChess Blitz Classic 2.1 responded at 55388381, 806ms before the deadline.
deadline passed: SlowChess Blitz Classic 2.1 responded at 55388481, 706ms before the deadline.
I wonder why "readyok" is stuck to the error message.

But the first problem (I believe) is that c-chess-cli doesn't seem to change current directory. Am I wrong?
Indeed, it doesn't change the current directory. So the path you give "openingBook/TestBook.scb" has to be either absolute, or relative to the current directory. I could make engine engine use their own directory as current directory, which is probably what users expect.

The fact that readyok is stuck to the error msg is not related to c-chess-cli, but rather SlowChessBlitz, which forgot to write a '\n' there.

The "deadline passed" is probably a poor choice of words. It's "passed" as in "pass/fail". Maybe "deadline ok" is better.
Theory and practice sometimes clash. And when that happens, theory loses. Every single time.
User avatar
Roland Chastain
Posts: 705
Joined: Sat Jun 08, 2013 10:07 am
Location: France
Full name: Roland Chastain

Re: c-chess-cli

Post by Roland Chastain »

lucasart wrote: Fri Aug 21, 2020 3:03 pm Indeed, it doesn't change the current directory. So the path you give "openingBook/TestBook.scb" has to be either absolute, or relative to the current directory. I could make engine engine use their own directory as current directory, which is probably what users expect.
Thank you for your answer. To be perfectly clear, I didn't give the path: it's the engine itself who searches automatically its book. I believe that many engines search books or other files like that, so IMHO it would be a good idea to do what you say (make engine use their own directory as current directory).
lucasart wrote: Fri Aug 21, 2020 3:03 pm The fact that readyok is stuck to the error msg is not related to c-chess-cli, but rather SlowChessBlitz, which forgot to write a '\n' there.
Yes, it was also my impression. I should report the bug to the author of SlowChess. Done.
lucasart wrote: Fri Aug 21, 2020 3:03 pm The "deadline passed" is probably a poor choice of words. It's "passed" as in "pass/fail". Maybe "deadline ok" is better.
No opinion about that: I don't know well english. :)
Qui trop embrasse mal étreint.

Author of Eschecs, a simple UCI chess GUI written in Pascal.
lucasart
Posts: 3243
Joined: Mon May 31, 2010 1:29 pm
Full name: lucasart

Re: c-chess-cli

Post by lucasart »

Roland Chastain wrote:
lucasart wrote: Fri Aug 21, 2020 3:03 pm The fact that readyok is stuck to the error msg is not related to c-chess-cli, but rather SlowChessBlitz, which forgot to write a '\n' there.
Yes, it was also my impression. I should report the bug to the author of SlowChess. Done.
There is one little trick to be aware of though. In order to capture the stderr of engines along with stdout, c-chess-cli puts them all in the same file using dup2() system call. This replicates the "2>&1" syntax in bash.

So it is possible that SlowChess wrote the error message in stderr without \n, and also wrote readyok in strdout. Still I think that would be wrong, and stderr messages should end with \n. But it would explain why this happens in c-chess-cli and not other tools that discard stderr.

I also fixed the current directory, deducing it from the command. Users with special needs may want to enter it as input parameter for each engine, but at least normal users will be satisfied with the default behavior.
Theory and practice sometimes clash. And when that happens, theory loses. Every single time.
User avatar
Roland Chastain
Posts: 705
Joined: Sat Jun 08, 2013 10:07 am
Location: France
Full name: Roland Chastain

Re: c-chess-cli

Post by Roland Chastain »

lucasart wrote: Sat Aug 22, 2020 7:30 am There is one little trick to be aware of though. In order to capture the stderr of engines along with stdout, c-chess-cli puts them all in the same file using dup2() system call. This replicates the "2>&1" syntax in bash.

So it is possible that SlowChess wrote the error message in stderr without \n, and also wrote readyok in strdout. Still I think that would be wrong, and stderr messages should end with \n. But it would explain why this happens in c-chess-cli and not other tools that discard stderr.
Indeed.
lucasart wrote: Sat Aug 22, 2020 7:30 am I also fixed the current directory, deducing it from the command. Users with special needs may want to enter it as input parameter for each engine, but at least normal users will be satisfied with the default behavior.
Perfect, thank you. I will test it.
Qui trop embrasse mal étreint.

Author of Eschecs, a simple UCI chess GUI written in Pascal.
lucasart
Posts: 3243
Joined: Mon May 31, 2010 1:29 pm
Full name: lucasart

Re: c-chess-cli

Post by lucasart »

Roland Chastain wrote: Sat Aug 22, 2020 9:17 am
lucasart wrote: Sat Aug 22, 2020 7:30 am I also fixed the current directory, deducing it from the command. Users with special needs may want to enter it as input parameter for each engine, but at least normal users will be satisfied with the default behavior.
Perfect, thank you. I will test it.
Actually, this will break something that worked before...

What if the user enters a string value containing spaces (using proper syntax to escape spaces in the shell), like so: "python ./engine.py" ?

The new logic of reading the current working directory, as everything before the last "/", results in cwd = "python .", which is not a valid directory...

A simple (but wrong) solution would be to read the first token, separated by " ", and apply the logic of the last "/" to that. Unfortunately, spaces are allowed in file names (and in directory names too, since directories are files as well).

Road to hell is paved with good intentions :lol:
Theory and practice sometimes clash. And when that happens, theory loses. Every single time.
User avatar
Roland Chastain
Posts: 705
Joined: Sat Jun 08, 2013 10:07 am
Location: France
Full name: Roland Chastain

Re: c-chess-cli

Post by Roland Chastain »

lucasart wrote: Sun Aug 23, 2020 3:31 am Actually, this will break something that worked before...

What if the user enters a string value containing spaces (using proper syntax to escape spaces in the shell), like so: "python ./engine.py" ?

The new logic of reading the current working directory, as everything before the last "/", results in cwd = "python .", which is not a valid directory...
Indeed. I did not think about that. Maybe you could make an option for directory? This is what other software do.

Good luck in finding a solution! :wink:
Qui trop embrasse mal étreint.

Author of Eschecs, a simple UCI chess GUI written in Pascal.
lucasart
Posts: 3243
Joined: Mon May 31, 2010 1:29 pm
Full name: lucasart

Re: c-chess-cli

Post by lucasart »

Roland Chastain wrote: Sun Aug 23, 2020 6:05 pm
lucasart wrote: Sun Aug 23, 2020 3:31 am Actually, this will break something that worked before...

What if the user enters a string value containing spaces (using proper syntax to escape spaces in the shell), like so: "python ./engine.py" ?

The new logic of reading the current working directory, as everything before the last "/", results in cwd = "python .", which is not a valid directory...
Indeed. I did not think about that. Maybe you could make an option for directory? This is what other software do.

Good luck in finding a solution! :wink:
I had to reinvent the shell a little:
  • First the a:b syntax reserves the ":" character, which is legal in file names, or command line arguments, so that's no good. Now a and b can contain ":" provided it is escaped "\:".
  • Second, a and b may contain spaces, and to make matters worse, the space character is ambiguous. It can be part of a file name, or actually command line arguments. Again, the solution is to use escape sequence "\ ".
  • Third, c-chess-cli now understands command line arguments for a and b (separated by unescaped spaces).
  • And, of course, I kept the logic of deducing the current working directory from the filename (eg. "../Engines/stockfish" => run "./stockfish" in "../Engines").
This solves every case I can think of, except perhaps this corner case: eg. "/usr/bin/python /home/lucas/Python\ scripts\engine.py". Here, the engine is actually "/usr/bin/python", since it is the executable file that we run and do UCI communication with. Of course, users will naively hope for the cwd to be set to "/home/lucas/Python\ scripts", but that won't happen. The logic is to deduce it from the first token being the file we execute, which is "usr/bin/python", leading to cwd = "usr/bin" here. The solution to this problem is to make the script executable, and use a shebang to run it directly a "/home/lucas/Python\ scripts\engine.py" without having to specify the python interpreter.
Theory and practice sometimes clash. And when that happens, theory loses. Every single time.
OliverBr
Posts: 865
Joined: Tue Dec 18, 2007 9:38 pm
Location: Munich, Germany
Full name: Dr. Oliver Brausch

Re: c-chess-cli

Post by OliverBr »

@lucasart,
thank you!

It would nice to support xboard protocol, too.

What about the handling when an ending crashes? cutechess-cli abort the tourney which can be very annoying, on the other hand you must fix bug, which is got.
Which format is pgn? I like "pgnout min" in cutechess, but is misses the "Time Control" tag.
OliThink GitHub: https://github.com/olithink
Nice arcticle about OlIThink: https://www.chessengeria.eu/post/olithink-oldie-goldie
Chess Engine OliThink Homepage: http://brausch.org/home/chess