The algorithm, statistics and heuristics of a chess program are quite complicated.
Now I had an idea to do a live visualization of what is going on during a game to be able to analyze.
So with some easy GUI build language (like Delphi) I create a windows application that can display various things.
The situation is as follows:
An external program (called CuteChess) runs in an arbitrary number of threads a tournament of x games between two (or more) engines. stdout and stdin are used by CuteChess. I should not touch any of these.
So let’s say a match is going on between chessnix and stockfish.
I can maintain some struct(s) inside chessnix that should be displayed or analyzed.
What would be the easiest and or fastest way to achieve my homewritten GUI to receive data from chessnix?
Writing to a file is not doable. The data changes millions of times per second.
Is it possible to accumulate/average the data and send at intervals (i.e. 30 times/second) over an IPC socket? Whether the data changes millions of times per second, the GUI cannot realistically display nor be required to receive it that often.
Posix has mmap for sharing memory between processes and avoid the heavy IO syscalls, but I am not sure what/if a Windows equivalent of that would be.
I decent pattern I use is pubsub and message passing between your visualization and backend.
I have had recent success using Zenoh as the messaging framework and CBOR as the serialization format.
This allows you to use multiple languages and decouple the GUI performance from the backend performance, and CBOR is schema-less for conveinience, especially with dynamically typed languages.
For example, you could run the backend as a Zenoh peer and the GUI as a Zenoh peer. Backend could publish at various intervals.
Intervals would be wise yes. Good idea
mmap sounds doable.
An addiotinal complication is that there can we 10 chessnix exe’s in the air.
But maybe I will try this one with 1 exe first…
That sounds very good but also like lots of study before get something working. And I don’t want additional software to get things going.
The wasm thing is something I really want to look at in a later stage. Would be cool to get something working in a browser.
#include <sys/uio.h>
ssize_t process_vm_readv(pid_t pid,
const struct iovec *local_iov,
unsigned long liovcnt,
const struct iovec *remote_iov,
unsigned long riovcnt,
unsigned long flags);
ssize_t process_vm_writev(pid_t pid,
const struct iovec *local_iov,
unsigned long liovcnt,
const struct iovec *remote_iov,
unsigned long riovcnt,
unsigned long flags);
and the man says :
These system calls transfer data between the address space of the calling process
("the local process") and the process identified by pid ("the remote process").
The data moves directly between the address spaces of the two processes, without
passing through kernel space.
I think it would be quite brittle setup, but since it’s a chess engine i guess you are not allocating a ton on the heap, and you might have a way to determine statically where everything is, and with some comptime magic, or runtime instrospection you could potentially get a very low overhead solution, and design some way to sample the readings, and create some kind of rr like experience, where you can record, and replay after in the gui with a timeline or something ?
It would also be less invasive i guess so that could be a plus since it’s very adhoc
I guess you are mostly calculation based? so your engine probably ports quite easy to WASM, and Zig produces very compact wasm last I tried. It is not a lot of work to access shared memory and have some WebGL/Canvas2D renderer running, depending what you imagine will be displayed? And then maybe a WebSocket to talk to other engine wrappers that capture stdout, and retrieve competing patterns. Sounds fun anyway!