AlexGisi / prometheus-chess

A UCI-compatible C++ chess engine.
0 stars 0 forks source link

can't initialize : invalid binary #1

Open tissatussa opened 4 months ago

tissatussa commented 4 months ago

i just found your chess engine at https://chessengines.blogspot.com/2024/07/new-version-chess-engine-prometheus-02.html .. then i found your GitHub page : it mentions 0.1, not 0.2 .. but after compiling your current main source, the binary shows 0.2 (by the uci command) .. i guessed the authors of chessengines.blogspot.com had copied that source package, but at closer inspection many files are different !?

i also compiled the 0.2 package from chessengines.blogspot.com, but both 0.2 binaries can not be initialized in CuteChess :

prometheus-can-not-init

however, execution in terminal goes well .. here's my test, just like CuteChess does it :

uci
id name prometheus 0.2
id author Alex Gisi
option name Hash type spin default 64 min 1 max 4096
uciok
ucinewgame
position startpos
isready
readyok
go wtime 70000 btime 70000 winc 10000 binc 10000
time:2308 start:1721942946740 stop:1721942959048 depth:64 timeset:1
info score cp 30 depth 1 nodes 21 time 0 pv d2d4
info score cp 0 depth 2 nodes 89 time 1 pv d2d4 d7d5
info score cp 25 depth 3 nodes 694 time 1 pv d2d4 d7d5 c1e3
info score cp 0 depth 4 nodes 2677 time 6 pv d2d4 d7d5 c1e3 c8e6
info score cp 25 depth 5 nodes 9933 time 23 pv e2e4 e7e5 d2d4 d7d5 c1e3
info score cp 0 depth 6 nodes 57969 time 69 pv e2e4 e7e5 d2d4 d7d5 c1e3 c8e6
info score cp 20 depth 7 nodes 131281 time 111 pv e2e4 e7e5 b1c3 b8c6 g1f3 f8c5 f1d3
info score cp 5 depth 8 nodes 911363 time 580 pv d2d4 d7d5 c1f4 c8e6 e2e3 b8c6 f1b5 g8f6
info score cp 20 depth 9 nodes 2416434 time 1428 pv d2d4 d7d5 c1f4 c8e6 e2e3 b8c6 b1c3 g8f6 f1d3
info score cp 5 depth 10 nodes 17173328 time 9666 pv b1c3 d7d5 d2d4 g8f6 c1f4 c8g4 g1f3 b8c6 e2e3 g4f3
bestmove b1c3

Btw. you should remove the line "time:.. start:.. stop:.. depth:.. timeset:.." because such output is not according to the UCI protocol : display such line with prefix "info string" to suit UCI. I removed the line and compiled again, but it didn't help.

compiling the asset source package 0.1 went well .. the resulting binary indeed shows "0.1" and it runs fine in CuteChess GUI. I used the newest cmake version 3.29.2

i tried to find the cause of the init-error by running the CuteChess GUI in a debugger (i use both lldb and gdb on Linux) but i get no clue.

lldb-17 shows this when the initialization fails :

Process 343552 stopped and restarted: thread 15 received signal: SIGCHLD
Terminating process of engine Prometheus v0.2(0)

gdb shows no valuable info when the initialization fails.

another thing : to compile the current main package, i had to solve this error :

/home/roelof/Apps/Cmake/cmake-3.29.2-linux-x86_64/bin/src/board/board.cpp:891:5: error: no declaration matches ‘u64 Board::perft(int)’
  891 | u64 Board::perft(int depth) {
      |     ^~~~~
In file included from /home/roelof/Apps/Cmake/cmake-3.29.2-linux-x86_64/bin/src/board/board.cpp:11:
/home/roelof/Apps/Cmake/cmake-3.29.2-linux-x86_64/bin/src/board/board.h:112:14: note: candidate is: ‘uint64_t Board::perft(int)’
  112 |     uint64_t perft(int depth);
      |              ^~~~~
/home/roelof/Apps/Cmake/cmake-3.29.2-linux-x86_64/bin/src/board/board.h:15:7: note: ‘class Board’ defined here
   15 | class Board {
      |       ^~~~~

the repair was easy : u64 Board::perft(int) in src/board/board.cpp (line 891) is defined differently in src/board/board.h. I also had a few warnings, but they're not important (however, i repaired the concerning code and it didn't solve the init error).

last thing : your asset binary seems an Apple one .. you should mention that somehow.

[ i'm on Xubuntu 22.04 ]

tissatussa commented 4 months ago

trying to repair some old C code of a chess engine called Hoplite, i consult ChatGPT, which is often a great help to me while coding. It states compilation can be 'extended' by adding debug info like this :

DFLAGS = -g -DDEBUG

ChatGPT : when the -g flag is added, it includes debugging information in the binary. This information helps tools like 'gdb' provide detailed insights into your program's execution, such as variable values and stack traces. The debugging information significantly increases the binary size because it contains additional metadata.

probably you already know this, but anyhow. can we solve the problem this way ?

AlexGisi commented 4 months ago

If you compile with -DCMAKE_BUILD_TYPE=Release -DCMAKE_BUILD_TYPE=Debug, it should enable debugging... Everything works fine on the terminal through linux and with the macos version of cutechess. I could try cutechess on linux soon though. Let me know if you find anything

tissatussa commented 4 months ago

i compiled your newest source with the 2 commands of the README, and all went well : no warnings and errors. A valid binary of 97.8 Kb was created, which runs fine in terminal but .. not in CuteChess GUI.

i tried the GUI of CuteChess 1.3.1 (newest, although i think they're almost launching 1.4.0) which i use for all engines, and also the older (but stable) v1.2.0, both have the same problem : they can't initialise Prometheus.

here's the output of my lldb debugger (i also tested with gdb but it gives no meaningful output) :

$ lldb-17 /home/roelof/Apps/cutechess-1.3.1/cutechess-gui
(lldb) target create "/home/roelof/Apps/cutechess-1.3.1/cutechess-gui"
Current executable set to '/home/roelof/Apps/cutechess-1.3.1/cutechess-gui' (x86_64).
(lldb) run
Process 310967 launched: '/home/roelof/Apps/cutechess-1.3.1/cutechess-gui' (x86_64)
qt.qpa.xcb: QXcbConnection: XCB error: 3 (BadWindow), sequence: 4786, resource id: 11429164, major code: 40 (TranslateCoords), minor code: 0
Process 310967 stopped and restarted: thread 15 received signal: SIGCHLD
Terminating process of engine Prometheus v0.2(1)

when i compile with -DCMAKE_BUILD_TYPE=Release, does it really include debug info ? Why don't the debuggers give more info ? Shouldn't the argument be something like -DCMAKE_BUILD_TYPE=Debug ? I'm stuck, most compiled engines have no such problem. I'm on Xubuntu 22.04, i think you should test on Linux to reproduce the issue .. i have no Apple nor Windows PC to test on.

tissatussa commented 4 months ago

i have more info, maybe it helps. the CuteChess config file (~/.config/cutechess/engines.json) contains this section for your engine :

{
     "command" : "./prometheus-v0.2-compiled-HP",
     "name" : "Prometheus v0.2",
     "options" : [
          {
               "alias" : "",
               "default" : 64,
               "max" : 4096,
               "min" : 1,
               "name" : "Hash",
               "type" : "spin",
               "value" : 64
          }
     ],
     "protocol" : "uci",
     "stderrFile" : "/home/roelof/Apps/ChessEngines/Prometheus/myerror.txt",
     "timeoutScaleFactor" : 1,
     "workingDirectory" : "/home/roelof/Apps/ChessEngines/Prometheus"
},

normally the entry 'stderrFile' is empty, but here i set a file to log errors and indeed some error was logged :

terminate called after throwing an instance of 'std::invalid_argument'
  what():  stoul

that's all CuteChess GUI gave.

normally i have no troubles with engines in CuteChess GUI, so this is strange to me .. i will now try CuteChess on the commandline (which i never do) and post the result here - i'll be back soon.

tissatussa commented 4 months ago

the test in CuteChess-cli went well !? this was my command :

./cutechess-cli -engine name="Prometheus v0.2" cmd=./prometheus-v0.2-compiled-HP dir=./ timemargin=1000 tc=80/180+3 proto='uci' -engine name="4KU v4.0" cmd=./4ku_v4.0-PR291_compiled_HP dir=./ timemargin=1000 tc=80/180+3 proto='uci' -resultformat default -wait 5000 -debug -rounds 2 -games 4
AlexGisi commented 4 months ago

You're right, it should be -DCMAKE_BUILD_TYPE=Debug, sorry. I will have to try cutechess on linux for myself.

tissatussa commented 3 months ago

hi, did you make any progress solving this Issue ? Working on a new version ?