c-chess-cli

Discussion of chess software programming and technical issues.

Moderators: bob, hgm, Harvey Williamson

Forum rules
This textbox is used to restore diagrams posted with the [d] tag before the upgrade.
User avatar
lucasart
Posts: 3096
Joined: Mon May 31, 2010 11:29 am
Full name: lucasart
Contact:

Re: c-chess-cli

Post by lucasart » Wed May 20, 2020 12:42 pm

Joerg Oster wrote:
Tue May 19, 2020 8: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: 722
Joined: Fri Mar 10, 2006 3:29 pm
Location: Germany

Re: c-chess-cli

Post by Joerg Oster » Wed May 20, 2020 12:53 pm

lucasart wrote:
Wed May 20, 2020 12:42 pm
Joerg Oster wrote:
Tue May 19, 2020 8: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: 1372
Joined: Tue Aug 30, 2016 6:19 pm
Full name: Rasmus Althoff
Contact:

Re: c-chess-cli

Post by Ras » Wed May 20, 2020 2:04 pm

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: 3096
Joined: Mon May 31, 2010 11:29 am
Full name: lucasart
Contact:

Re: c-chess-cli

Post by lucasart » Wed May 20, 2020 11:03 pm

Ras wrote:
Wed May 20, 2020 2: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: 1372
Joined: Tue Aug 30, 2016 6:19 pm
Full name: Rasmus Althoff
Contact:

Re: c-chess-cli

Post by Ras » Wed May 20, 2020 11:19 pm

lucasart wrote:
Wed May 20, 2020 11:03 pm
So 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: 3096
Joined: Mon May 31, 2010 11:29 am
Full name: lucasart
Contact:

Re: c-chess-cli

Post by lucasart » Fri May 22, 2020 3:39 am

Joerg Oster wrote:
Tue May 19, 2020 8: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.

Post Reply