I was able to reproduce it too. Just as I switch on the debugger, I read this. You're responsible for fixing two major bugs in bit genielithander wrote: ↑Mon Mar 22, 2021 2:51 pmFor me it just quits after depth 9. I use the procompiled release build from github on a Ryzen 3600. Strange.Code: Select all
PS D:\Projekte\Chess\Other Engines> .\Bit-Genie_100ssse3.exe Bit Genie by Aryan Parekh Hash table initialized with 2 Mb ( 125000 entries ) uci id name Bit-Genie 1.0.0 id author Aryan Parekh option name Hash type spin default 2 min 2 max 3000 option name Clear Hash type button uciok position startpos moves e2e4 g8f6 b1c3 d7d5 e4d5 f6d5 f1c4 c7c6 g1f3 d8a5 e1g1 c8e6 c4b3 b8d7 f3d4 d5c3 d2c3 e6b3 c2b3 e7e5 d4f5 g7g6 f5d6 f8d6 d1d6 a5c5 d6d2 f7f5 d2h6 f5f4 c1d2 e8c8 a1d1 d7f6 h6h3 c8c7 b3b4 c5e7 f1e1 d8d7 e1e2 h8d8 h3h4 f6d5 h4h6 f4f3 g2f3 d5f4 d2f4 d7d1 g1g2 e7f7 e2e5 c7c8 e5c5 d8f8 h6h3 f7d7 h3h6 f8e8 f4e3 b7b6 c5c4 d7d5 b2b3 e8e7 h6f8 c8d7 f8b8 b6b5 c4c5 d5d6 b8a7 d7e6 a7a8 e6f7 a8c6 d6c6 c5c6 d1a1 c6a6 a1b1 g2g3 e7e6 a6a7 e6e7 a7a5 b1g1 g3f4 e7b7 a5a8 f7e6 a8e8 e6f7 e8h8 f7f6 e3d4 f6e6 h8e8 e6f7 e8h8 f7e6 h8d8 b7f7 f4e4 g1e1 d4e3 f7a7 d8d2 a7a8 e4d4 a8d8 d4c5 d8d2 e3d2 e1e2 d2e3 e2a2 c5b5 a2a1 b5c4 a1h1 b4b5 h1h2 b5b6 h2h4 c4b5 go info depth 1 seldepth 2 nodes 53 score cp -59 time 0 pv h4h1 info depth 2 seldepth 3 nodes 265 score cp -88 time 1 pv h4h3 f3f4 info depth 3 seldepth 4 nodes 1069 score cp -59 time 3 pv h4h5 b5a4 h5h1 info depth 4 seldepth 6 nodes 1944 score cp -88 time 5 pv h4h5 b5a4 h5h3 f3f4 info depth 5 seldepth 7 nodes 12212 score cp -69 time 8 pv h4h5 b5a4 h5h3 b6b7 h3f3 info depth 6 seldepth 9 nodes 52217 score cp -154 time 16 pv e6d7 b6b7 d7c7 b5a6 h4h1 c3c4 info depth 7 seldepth 9 nodes 173587 score cp -116 time 36 pv h4h5 b5c6 h5a5 b6b7 a5a6 e3b6 a6a2 info depth 8 seldepth 11 nodes 356784 score cp -356 time 84 pv h4h5 b5a6 h5d5 b6b7 d5d6 e3b6 d6b6 a6b6 info depth 9 seldepth 13 nodes 2359826 score cp -337 time 301 pv h4h5 b5a6 h5d5 b6b7 d5d6 e3b6 d6b6 a6b6 h7h5 PS D:\Projekte\Chess\Other Engines>
Edit:
Well I cloned the git, compiled a debug build.
...in position.cpp
The assert triggers because the expression "pieces.bitboards[King] & friend_bb()" from line 299 evaluates to zero.Code: Select all
#if defined (_MSC_VER) inline Square get_lsb(uint64_t b) { assert(b); unsigned long idx; _BitScanForward64(&idx, b); return to_sq(idx); }
The release build will just call _BitScanForward64 and pass the uninitialized variable index on to to_sq(idx). Famous C++ undefined behavior. This is why I don't personally like using C++ btw!
Code: Select all
Bit-Genie.exe!get_lsb(unsigned __int64 b) Zeile 44 C++ Bit-Genie.exe!Position::move_is_legal(Move move) Zeile 299 C++ Bit-Genie.exe!`MovePicker::next'::`2'::<lambda_1>::operator()(Move m) Zeile 128 C++ Bit-Genie.exe!MovePicker::next(Move & move) Zeile 136 C++ Bit-Genie.exe!`anonymous namespace'::pvs(Position & position, Search & search, TTable & tt, int depth, int alpha, int beta) Zeile 139 C++ Bit-Genie.exe!`anonymous namespace'::pvs(Position & position, Search & search, TTable & tt, int depth, int alpha, int beta) Zeile 147 C++ Bit-Genie.exe!`anonymous namespace'::pvs(Position & position, Search & search, TTable & tt, int depth, int alpha, int beta) Zeile 147 C++ Bit-Genie.exe!`anonymous namespace'::pvs(Position & position, Search & search, TTable & tt, int depth, int alpha, int beta) Zeile 147 C++ Bit-Genie.exe!`anonymous namespace'::pvs(Position & position, Search & search, TTable & tt, int depth, int alpha, int beta) Zeile 147 C++ Bit-Genie.exe!`anonymous namespace'::pvs(Position & position, Search & search, TTable & tt, int depth, int alpha, int beta) Zeile 150 C++ Bit-Genie.exe!`anonymous namespace'::pvs(Position & position, Search & search, TTable & tt, int depth, int alpha, int beta) Zeile 147 C++ Bit-Genie.exe!`anonymous namespace'::pvs(Position & position, Search & search, TTable & tt, int depth, int alpha, int beta) Zeile 150 C++ Bit-Genie.exe!`anonymous namespace'::pvs(Position & position, Search & search, TTable & tt, int depth, int alpha, int beta) Zeile 147 C++ Bit-Genie.exe!`anonymous namespace'::pvs(Position & position, Search & search, TTable & tt, int depth, int alpha, int beta) Zeile 147 C++ Bit-Genie.exe!search_position(Position & position, Search & search, TTable & tt) Zeile 296 C++ Bit-Genie.exe!uci_input_loop(int argc, char * * argv) Zeile 129 C++ Bit-Genie.exe!main(int argc, char * * argv) Zeile 27 C++ [Externer Code]
New open-source engine, Bit-Genie
Moderator: Ras
-
aryan1508
- Posts: 31
- Joined: Sat Mar 20, 2021 3:44 pm
- Full name: Aryan Parekh
Re: New open-source engine, Bit-Genie
-
Guenther
- Posts: 4718
- Joined: Wed Oct 01, 2008 6:33 am
- Location: Regensburg, Germany
- Full name: Guenther Simon
Re: New open-source engine, Bit-Genie
Great detective work Thomas. I should have mentioned that I used the ssse3 build or a native one for my no-popcount old hardware,lithander wrote: ↑Mon Mar 22, 2021 2:51 pmFor me it just quits after depth 9. I use the procompiled release build from github on a Ryzen 3600. Strange.Code: Select all
PS D:\Projekte\Chess\Other Engines> .\Bit-Genie_100ssse3.exe Bit Genie by Aryan Parekh Hash table initialized with 2 Mb ( 125000 entries ) uci id name Bit-Genie 1.0.0 id author Aryan Parekh option name Hash type spin default 2 min 2 max 3000 option name Clear Hash type button uciok position startpos moves e2e4 g8f6 b1c3 d7d5 e4d5 f6d5 f1c4 c7c6 g1f3 d8a5 e1g1 c8e6 c4b3 b8d7 f3d4 d5c3 d2c3 e6b3 c2b3 e7e5 d4f5 g7g6 f5d6 f8d6 d1d6 a5c5 d6d2 f7f5 d2h6 f5f4 c1d2 e8c8 a1d1 d7f6 h6h3 c8c7 b3b4 c5e7 f1e1 d8d7 e1e2 h8d8 h3h4 f6d5 h4h6 f4f3 g2f3 d5f4 d2f4 d7d1 g1g2 e7f7 e2e5 c7c8 e5c5 d8f8 h6h3 f7d7 h3h6 f8e8 f4e3 b7b6 c5c4 d7d5 b2b3 e8e7 h6f8 c8d7 f8b8 b6b5 c4c5 d5d6 b8a7 d7e6 a7a8 e6f7 a8c6 d6c6 c5c6 d1a1 c6a6 a1b1 g2g3 e7e6 a6a7 e6e7 a7a5 b1g1 g3f4 e7b7 a5a8 f7e6 a8e8 e6f7 e8h8 f7f6 e3d4 f6e6 h8e8 e6f7 e8h8 f7e6 h8d8 b7f7 f4e4 g1e1 d4e3 f7a7 d8d2 a7a8 e4d4 a8d8 d4c5 d8d2 e3d2 e1e2 d2e3 e2a2 c5b5 a2a1 b5c4 a1h1 b4b5 h1h2 b5b6 h2h4 c4b5 go info depth 1 seldepth 2 nodes 53 score cp -59 time 0 pv h4h1 info depth 2 seldepth 3 nodes 265 score cp -88 time 1 pv h4h3 f3f4 info depth 3 seldepth 4 nodes 1069 score cp -59 time 3 pv h4h5 b5a4 h5h1 info depth 4 seldepth 6 nodes 1944 score cp -88 time 5 pv h4h5 b5a4 h5h3 f3f4 info depth 5 seldepth 7 nodes 12212 score cp -69 time 8 pv h4h5 b5a4 h5h3 b6b7 h3f3 info depth 6 seldepth 9 nodes 52217 score cp -154 time 16 pv e6d7 b6b7 d7c7 b5a6 h4h1 c3c4 info depth 7 seldepth 9 nodes 173587 score cp -116 time 36 pv h4h5 b5c6 h5a5 b6b7 a5a6 e3b6 a6a2 info depth 8 seldepth 11 nodes 356784 score cp -356 time 84 pv h4h5 b5a6 h5d5 b6b7 d5d6 e3b6 d6b6 a6b6 info depth 9 seldepth 13 nodes 2359826 score cp -337 time 301 pv h4h5 b5a6 h5d5 b6b7 d5d6 e3b6 d6b6 a6b6 h7h5 PS D:\Projekte\Chess\Other Engines>
Edit:
Well I cloned the git, compiled a debug build.
...in position.cpp
The assert triggers because the expression "pieces.bitboards[King] & friend_bb()" from line 299 evaluates to zero.Code: Select all
#if defined (_MSC_VER) inline Square get_lsb(uint64_t b) { assert(b); unsigned long idx; _BitScanForward64(&idx, b); return to_sq(idx); }
The release build will just call _BitScanForward64 and pass the uninitialized variable index on to to_sq(idx). Famous C++ undefined behavior. This is why I don't personally like using C++ btw! :P
Code: Select all
Bit-Genie.exe!get_lsb(unsigned __int64 b) Zeile 44 C++ Bit-Genie.exe!Position::move_is_legal(Move move) Zeile 299 C++ Bit-Genie.exe!`MovePicker::next'::`2'::<lambda_1>::operator()(Move m) Zeile 128 C++ Bit-Genie.exe!MovePicker::next(Move & move) Zeile 136 C++ Bit-Genie.exe!`anonymous namespace'::pvs(Position & position, Search & search, TTable & tt, int depth, int alpha, int beta) Zeile 139 C++ Bit-Genie.exe!`anonymous namespace'::pvs(Position & position, Search & search, TTable & tt, int depth, int alpha, int beta) Zeile 147 C++ Bit-Genie.exe!`anonymous namespace'::pvs(Position & position, Search & search, TTable & tt, int depth, int alpha, int beta) Zeile 147 C++ Bit-Genie.exe!`anonymous namespace'::pvs(Position & position, Search & search, TTable & tt, int depth, int alpha, int beta) Zeile 147 C++ Bit-Genie.exe!`anonymous namespace'::pvs(Position & position, Search & search, TTable & tt, int depth, int alpha, int beta) Zeile 147 C++ Bit-Genie.exe!`anonymous namespace'::pvs(Position & position, Search & search, TTable & tt, int depth, int alpha, int beta) Zeile 150 C++ Bit-Genie.exe!`anonymous namespace'::pvs(Position & position, Search & search, TTable & tt, int depth, int alpha, int beta) Zeile 147 C++ Bit-Genie.exe!`anonymous namespace'::pvs(Position & position, Search & search, TTable & tt, int depth, int alpha, int beta) Zeile 150 C++ Bit-Genie.exe!`anonymous namespace'::pvs(Position & position, Search & search, TTable & tt, int depth, int alpha, int beta) Zeile 147 C++ Bit-Genie.exe!`anonymous namespace'::pvs(Position & position, Search & search, TTable & tt, int depth, int alpha, int beta) Zeile 147 C++ Bit-Genie.exe!search_position(Position & position, Search & search, TTable & tt) Zeile 296 C++ Bit-Genie.exe!uci_input_loop(int argc, char * * argv) Zeile 129 C++ Bit-Genie.exe!main(int argc, char * * argv) Zeile 27 C++ [Externer Code]
so that's the reason why no error was triggered I guess.
-
mar
- Posts: 2680
- Joined: Fri Nov 26, 2010 2:00 pm
- Location: Czech Republic
- Full name: Martin Sedlak
Re: New open-source engine, Bit-Genie
what has the bsf instruction anything to do with UB in C++?! it'd behave exactly the same way in C or elsewhere.lithander wrote: ↑Mon Mar 22, 2021 2:51 pm The assert triggers because the expression "pieces.bitboards[King] & friend_bb()" from line 299 evaluates to zero.
The release build will just call _BitScanForward64 and pass the uninitialized variable index on to to_sq(idx). Famous C++ undefined behavior. This is why I don't personally like using C++ btw!![]()
the hardware says undefined if source is zero, so it probably just keeps what was in dest register previously.
you should fix your program rather than crapping on C/C++
-
lithander
- Posts: 925
- Joined: Sun Dec 27, 2020 2:40 am
- Location: Bremen, Germany
- Full name: Thomas Jahn
Re: New open-source engine, Bit-Genie
What the fuck are you talking about?mar wrote: ↑Mon Mar 22, 2021 3:17 pmwhat has the bsf instruction anything to do with UB in C++?! it'd behave exactly the same way in C or elsewhere.lithander wrote: ↑Mon Mar 22, 2021 2:51 pm The assert triggers because the expression "pieces.bitboards[King] & friend_bb()" from line 299 evaluates to zero.
The release build will just call _BitScanForward64 and pass the uninitialized variable index on to to_sq(idx). Famous C++ undefined behavior. This is why I don't personally like using C++ btw!![]()
the hardware says undefined if source is zero, so it probably just keeps what was in dest register previously.
you should fix your program rather than crapping on C/C++
-
mar
- Posts: 2680
- Joined: Fri Nov 26, 2010 2:00 pm
- Location: Czech Republic
- Full name: Martin Sedlak
-
mvanthoor
- Posts: 1784
- Joined: Wed Jul 03, 2019 4:42 pm
- Location: Netherlands
- Full name: Marcel Vanthoor
Re: New open-source engine, Bit-Genie
mar wrote: ↑Mon Mar 22, 2021 3:17 pm what has the bsf instruction anything to do with UB in C++?! it'd behave exactly the same way in C or elsewhere.
the hardware says undefined if source is zero, so it probably just keeps what was in dest register previously.
you should fix your program rather than crapping on C/C++
Woow... slow down. I'm not a mod here, but I think you two are misunderstanding one another.
mar: you're correct, in this case C++ does exactly what it's supposed to do (nothing / keep the previous value), so that is indeed not undefined behavior.
lithander: you're correct too: it's easy to get an undefined / uninitialized variable when using C/C++, and sometimes, this can be caused by undefined behavior.
I think that this is what lithander means: he doesn't like working with C/C++ because it's very easy to get undefined or uninitialized variables (sometimes caused by undefined behavior) which will then break the program. Many other languages (including C#, and Rust, for that matter) are much more strict in enforcing that you _always_ have a defined value in a variable.
Which of course, can still be incorrect because some sort of logic error in your... but that's _your_ problem, if you put "5" in it, where you meant it to be "8".
-
lithander
- Posts: 925
- Joined: Sun Dec 27, 2020 2:40 am
- Location: Bremen, Germany
- Full name: Thomas Jahn
Re: New open-source engine, Bit-Genie
Marcel nailed it. Sorry for swearing.
And when I say that I personally don't like working in C/C++ because the language makes it far too easy to accidentally create a program that has unpredictable runtime behavior which means that it may perform differently every time the program is run or based on the hardware it is run on (as we've seen today) that is not "crapping" on the language.
I found this pretty offensive especially considering that it's not my program/code that had a bug here and thus I "should" not have to do anything beyond what I already did, in an attempt to help a fellow programmer.you should fix your program rather than crapping on C/C++
And when I say that I personally don't like working in C/C++ because the language makes it far too easy to accidentally create a program that has unpredictable runtime behavior which means that it may perform differently every time the program is run or based on the hardware it is run on (as we've seen today) that is not "crapping" on the language.
-
lithander
- Posts: 925
- Joined: Sun Dec 27, 2020 2:40 am
- Location: Bremen, Germany
- Full name: Thomas Jahn
Re: New open-source engine, Bit-Genie
To clarify: That the 'idx' variable remains uninitialized in the above code is not caused by undefined behavior. But using an uninitialized variable results in undefined behavior. Other languages would initialize 'idx' with zero implicitly or the compiler would force you to initialize the variable. In C/C++ it's value could be anything. With 'idx' set to 0 the program would still be buggy but it would perform the same faulty way each time you run it and regardless of the hardware you run it on. That the same position crashes the engine on my computer but not on Guenthers is something that just doesn't happen so easily in other languages.
-
Ras
- Posts: 2756
- Joined: Tue Aug 30, 2016 8:19 pm
- Full name: Rasmus Althoff
Re: New open-source engine, Bit-Genie
There is a possibility for a subtle race condition that preferably hits in if you load all your logical cores with actual searchers, such as eight games in parallel on a quadcore with hyperthreading.Gabor Szots wrote: ↑Mon Mar 22, 2021 10:43 amThanks Andreas. Maybe that's the reason why I have so many time forfeits in my tournaments.
That requires two design ingredients:
- The search thread first prints the final bestmove and then sets up some "not in search" flag.
- The input thread discards anything other than isready/stop/quit during search.
But yeah, using a dedicated input thread that sleeps unless there is input is really common, I'm doing that, too. However, I don't discard input, but buffer it for later.
Rasmus Althoff
https://www.ct800.net
https://www.ct800.net
-
aryan1508
- Posts: 31
- Joined: Sat Mar 20, 2021 3:44 pm
- Full name: Aryan Parekh
Re: New open-source engine, Bit-Genie
I found the bug. It was in the function that checks if a move was pseudo-legal or not. Have fixed that + the time management issues. I hope its alright now, thank you @lithander!