c-chess-cli

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
lucasart
Posts: 3232
Joined: Mon May 31, 2010 1:29 pm
Full name: lucasart

Re: c-chess-cli

Post by lucasart »

Joerg Oster wrote: Tue May 19, 2020 10:08 pm I tried fixed depth, tournament tc and Fischer bonus time.
Fixed tournament tc: forgot to add the base time, after movestogo wraps aroung zero. what a dumbass...

Fixed Fischer clock as well. Rule says increment must be added before the move. Most chess UI do it wrong, adding the increment after the move, potentially after having flagged the engine. As a result, engine programmers conservatively assume that the GUI has this bug, and base their time management assumptions on it.

https://old.fide.com/fide/handbook.html ... ew=article
increment: 6.1. An amount of time (from 2 to 60 seconds) added from the start before each move for the player. This can be in either delay or cumulative mode
Theory and practice sometimes clash. And when that happens, theory loses. Every single time.
Joerg Oster
Posts: 937
Joined: Fri Mar 10, 2006 4:29 pm
Location: Germany

Re: c-chess-cli

Post by Joerg Oster »

lucasart wrote: Wed May 20, 2020 2:42 pm
Joerg Oster wrote: Tue May 19, 2020 10:08 pm I tried fixed depth, tournament tc and Fischer bonus time.
Fixed tournament tc: forgot to add the base time, after movestogo wraps aroung zero. what a dumbass...

Fixed Fischer clock as well. Rule says increment must be added before the move. Most chess UI do it wrong, adding the increment after the move, potentially after having flagged the engine. As a result, engine programmers conservatively assume that the GUI has this bug, and base their time management assumptions on it.

https://old.fide.com/fide/handbook.html ... ew=article
increment: 6.1. An amount of time (from 2 to 60 seconds) added from the start before each move for the player. This can be in either delay or cumulative mode
Great!
I also noticed you are sending a "isready" after "ucinewgame" which seems to be mandatory.
Most UIs don't.

Looking forward to the things to come.
Jörg Oster
Ras
Posts: 2487
Joined: Tue Aug 30, 2016 8:19 pm
Full name: Rasmus Althoff

Re: c-chess-cli

Post by Ras »

I'd suggest to add the following line at the top of each source text file (.c and .h):

Code: Select all

/* SPDX-License-Identifier: GPL-3.0-or-later */
That makes it easy e.g. for Linux distros to automatically determine package licences.

CppCheck flags out a lot of portability issues because "Passing NULL after the last typed argument to a variadic function leads to undefined behaviour." That's a problem with all these str_xxx defines.
Rasmus Althoff
https://www.ct800.net
User avatar
lucasart
Posts: 3232
Joined: Mon May 31, 2010 1:29 pm
Full name: lucasart

Re: c-chess-cli

Post by lucasart »

Ras wrote: Wed May 20, 2020 4:04 pm CppCheck flags out a lot of portability issues because "Passing NULL after the last typed argument to a variadic function leads to undefined behaviour." That's a problem with all these str_xxx defines.
I want to write, for example, str_delete(&s1, ..., &sn), for arbitrary n >= 1. The "..." argument in C was designed for things like printf(), which have a format string. It's by parsing the format string, that the function discovers how many arguments there are, and of what type. Here there is no format string, we know the argument type (str_t *) but we don't know how many there are. The va_list itself doesn't know its own length. So the only way I found was to add a null pointer at the end.

How would you solve this problem ? (without C++11, just C99)

The C standard seems to suggest doing str_delete(n, &s1, ..., &sn). But it just sucks that the calling code has to supply the n, plus this could easily lead to unobvious errors, as code gets edited (you add/remove strings in the list, and forget to update n).
Theory and practice sometimes clash. And when that happens, theory loses. Every single time.
Ras
Posts: 2487
Joined: Tue Aug 30, 2016 8:19 pm
Full name: Rasmus Althoff

Re: c-chess-cli

Post by Ras »

lucasart wrote: Thu May 21, 2020 1:03 amSo the only way I found was to add a null pointer at the end.
I think the portability problem is that NULL is not necessarily defined as pointer in ((void *) 0) style, though it is under POSIX - but not guaranteed as per the C standard (that may be an integer 0 as well). If the arguments are passed on the stack, and the caller pushes an integer (e.g. 32 bit) while the callee expects a pointer (e.g. 64 bit), that might go wrong. With ordinary functions, this isn't an issue because of argument casting, but that requires typed function prototypes - variadic functions are pretty much an edge case.

An easy solution would be to replace NULL with (const char *) NULL in this context.
Rasmus Althoff
https://www.ct800.net
User avatar
lucasart
Posts: 3232
Joined: Mon May 31, 2010 1:29 pm
Full name: lucasart

Re: c-chess-cli

Post by lucasart »

Joerg Oster wrote: Tue May 19, 2020 10:08 pm A summary of the result at the end would be nice. :D
Done. Total WLD and score% shown after each game.
Theory and practice sometimes clash. And when that happens, theory loses. Every single time.
User avatar
lucasart
Posts: 3232
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: 640
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.
User avatar
lucasart
Posts: 3232
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: 640
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.