New engine: Stash

Discussion of anything and everything relating to chess playing software and machines.

Moderators: hgm, Rebel, chrisw

mhouppin
Posts: 115
Joined: Wed Feb 12, 2020 5:00 pm
Full name: Morgan Houppin

Re: New engine: Stash

Post by mhouppin »

mvanthoor wrote: Sat Feb 15, 2020 5:16 pm Congratulations on your first release :)

I am thrilled to read that you are starting from scratch without using another engine as a reference. It's a lot of work, but that way, you can establish a baseline ELO, and see the strength gains your engine makes with each new function you implement. (In the beginning, those gains will be positively huge; possibly >100 ELO for implementing a search optimization or an extra evaluation parameter. Search Madchess.net for more info. Erik Madsen chronicled the development of Madchess 2 and 3 after establishing the baseline.)

I've looked at your code. Congratulations about that as well. It's one of the most readable implementations I've seen in a long time. It avoids the pitfall of having lots of if/switch/for/while blocks wrapped into one-another. If you remove the numbers that appear throughout (replace them by constants) and add a lot of comments, this could be a great reference engine.

It compiles cleanly under Windows (MSYS2 / MinGW64). A suggestion: change the build script so it compiles statically. Now you need to have libwinpthread-1.dll in the same folder as stash-bot.exe. This is just a matter of taste obviously, but in the case of chess engines, my preference is to have a single executable that works without any dependencies.

===

As an aside: Some months ago, I _finally_ started writing my own chess engine, using the Rust programming language. (My one constraint with regard to writing a chess engine is to NOT use C or C++, because everybody and their dog has a C/C++ chess engine. C/C++ are fast, but they're also ancient with lots of pitfalls.)

Your engine seems to use board iteration to find the pieces, and then iterates over the squares in each direction the piece can move. My engine is using magic bitboards, and I've just reached the stage where I start to implement the move generator. (I reserve the engine name to for myself, because I haven't decided yet :p)

I can't wait to finish by engine to a playable baseline and then pit it against this version of Stash, because they're both original, not derived from any other engines, in the beginning stages of development, they use different programming languages, and different board representations.

Good luck to you :)

(Some output of the partially complete move generator of my engine...)

Code: Select all

    Finished dev [unoptimized + debuginfo] target(s) in 0.54s
     Running `target\debug\xyz.exe`

Engine: xyz
Author: mvanthoor

8   . . . r . . . .
7   . . b k . . . .
6   . . . I N . . .
5   . . . . . . . i
4   . i I . . n . .
3   . . . i . . . I
2   N n . . . . . .
1   K R . B . . . .

    A B C D E F G H

Kd7d6 (capture)
Kd7e6 (capture)
Kd7c6 (normal)
Kd7e7 (normal)
Kd7c8 (normal)
Kd7e8 (normal)
Nb2d1 (capture)
Nb2c4 (capture)
Nb2a4 (normal)
Nf4h3 (capture)
Nf4e6 (capture)
Nf4e2 (normal)
Nf4g2 (normal)
Nf4d5 (normal)
Nf4g6 (normal)
Done.
Hi there !

As you pointed out, my code was not that commented, so I started clarifying a bit things on the search function ^^ I also added static compilation to the build.sh script. I have been looking at how to use magic bitboards on a chess engine, but it will ask a lot of refactorization, so I'm planning to work on that in parallel of the algorithm optimization.

Also Guenther, the CPU consuming was due to an incorrect implementation of the wait for the engine to launch, so it should be fixed now :)
The multithreading implementation is very doubtful for now, so letting the Threads parameter as is is preferable.
User avatar
Guenther
Posts: 4605
Joined: Wed Oct 01, 2008 6:33 am
Location: Regensburg, Germany
Full name: Guenther Simon

Re: New engine: Stash

Post by Guenther »

mhouppin wrote: Sat Feb 15, 2020 8:56 pm ...

Also Guenther, the CPU consuming was due to an incorrect implementation of the wait for the engine to launch, so it should be fixed now :)
The multithreading implementation is very doubtful for now, so letting the Threads parameter as is is preferable.
I have replaced my compilations with version 8.14 (haven't tested though, if the problem is gone).
https://rwbc-chess.de

trollwatch:
Chessqueen + chessica + AlexChess + Eduard + Sylwy
User avatar
Roland Chastain
Posts: 640
Joined: Sat Jun 08, 2013 10:07 am
Location: France
Full name: Roland Chastain

Re: New engine: Stash

Post by Roland Chastain »

mhouppin wrote: Sat Feb 15, 2020 8:56 pmI also added static compilation to the build.sh script.
FYI, I have just downloaded a fresh copy of your project, and tried the build.sh script. It failes with this error:
/usr/bin/ld : ne peut trouver -lpthread
/usr/bin/ld : ne peut trouver -lm
/usr/bin/ld : ne peut trouver -lc
But if I type simply "make", the compilation is successful.
Qui trop embrasse mal étreint.
mhouppin
Posts: 115
Joined: Wed Feb 12, 2020 5:00 pm
Full name: Morgan Houppin

Re: New engine: Stash

Post by mhouppin »

Roland Chastain wrote: Sun Feb 16, 2020 11:21 am
mhouppin wrote: Sat Feb 15, 2020 8:56 pmI also added static compilation to the build.sh script.
FYI, I have just downloaded a fresh copy of your project, and tried the build.sh script. It failes with this error:
/usr/bin/ld : ne peut trouver -lpthread
/usr/bin/ld : ne peut trouver -lm
/usr/bin/ld : ne peut trouver -lc
But if I type simply "make", the compilation is successful.
There was probably an occasional issue with the static compilation on Unix/Linux, so I decided splitting the build script in two: the windows_build.sh now compiles the program statically, whereas the unix_build.sh compiles it with runtime linkage (as usual for Unix/Linux). Hoping that will fix the problem ! :)
User avatar
emadsen
Posts: 434
Joined: Thu Apr 26, 2012 1:51 am
Location: Oak Park, IL, USA
Full name: Erik Madsen

Re: New engine: Stash

Post by emadsen »

Congrats Morgan. Welcome to our community and our addictive hobby.

As Marcel said in an earlier post, I chronicled the development of my chess engine on my blog, including measuring the ELO strength improvement of each feature. Mine is not the strongest engine but hopefully the code snippets and ELO measurements published on my blog help explain the ideas behind each feature and what to expect in terms of strength improvement. Of course chess engine features interact in a non-linear manner, so you may measure a different improvement for the same feature, especially if you implement features in a different order than I did.

Refer to the table of ELO gains in this post for MadChess 2.0, my mailbox chess engine (released), and this most recent post for MadChess 3.0 Beta, my bitboard chess engine (not yet released).

Glancing at your code, I'd say an important feature you should implement is a hashtable / cache (with lookups via the Zobrist key of a position) that stores the score and best move of a position. Once that's implemented, you can refactor your search method to avoid generating moves if the score or best move retrieved from the hashtable causes a beta cutoff. This will speedup your engine and improve its playing strength (because it will search deeper in the same amount of time compared to the engine without a hashtable and with full move generation at every node).

Good luck!
My C# chess engine: https://www.madchess.net
mhouppin
Posts: 115
Joined: Wed Feb 12, 2020 5:00 pm
Full name: Morgan Houppin

Re: New engine: Stash

Post by mhouppin »

Hi there, Stash 9.0 is finally out !

I managed to implement bitboard generation (mainly derived from Stockfish code), added a 3-fold repetition detection using Zobrist Keys (I will implement the transposition table later, I'm currently working on adding a quiescence search function), and (finally !) implemented the MultiPV handling. The speed boost goes from 50 to 250% depending on systems, and the engine rating should have raised from ~50 Elo.

As I have written a lot of code these last days, if you find any bugs, please report them, I will patch them as soon as I get notified.

Good afternoon to everyone :)
User avatar
Roland Chastain
Posts: 640
Joined: Sat Jun 08, 2013 10:07 am
Location: France
Full name: Roland Chastain

Re: New engine: Stash

Post by Roland Chastain »

mhouppin wrote: Mon Feb 24, 2020 3:08 pm Hi there, Stash 9.0 is finally out !

I managed to implement bitboard generation (mainly derived from Stockfish code), added a 3-fold repetition detection using Zobrist Keys (I will implement the transposition table later, I'm currently working on adding a quiescence search function), and (finally !) implemented the MultiPV handling. The speed boost goes from 50 to 250% depending on systems, and the engine rating should have raised from ~50 Elo.

As I have written a lot of code these last days, if you find any bugs, please report them, I will patch them as soon as I get notified.

Good afternoon to everyone :)
Congratulations. I will try it. Don't forget to sleep sometimes! :)
Qui trop embrasse mal étreint.
Damir
Posts: 2801
Joined: Mon Feb 11, 2008 3:53 pm
Location: Denmark
Full name: Damir Desevac

Re: New engine: Stash

Post by Damir »

Any Windows compiles available ? :)
User avatar
mvanthoor
Posts: 1784
Joined: Wed Jul 03, 2019 4:42 pm
Location: Netherlands
Full name: Marcel Vanthoor

Re: New engine: Stash

Post by mvanthoor »

You switched the engine from square/piece iteration to magic bitobards in less than 10 days? :shock:

Only 50 ELO for implementing bitboards seems wrong. If I remember correctly, Minic by xr_a_y gained something like 200 ELO because of the speed boost of bitboards over square/piece-iteration.

You must have been writing a lot of code, or did you port the code directly from Stockfish and adapted it to fit the existing engine?

Do you have a base ELO established somewhere (your own tournament, for example), or is the engine in any rating list?
Last edited by mvanthoor on Mon Feb 24, 2020 5:04 pm, edited 1 time in total.
Author of Rustic, an engine written in Rust.
Releases | Code | Docs | Progress | CCRL
User avatar
Roland Chastain
Posts: 640
Joined: Sat Jun 08, 2013 10:07 am
Location: France
Full name: Roland Chastain

Re: New engine: Stash

Post by Roland Chastain »

Damir wrote: Mon Feb 24, 2020 4:19 pm Any Windows compiles available ? :)
I have just tried to compile under Windows. I have a problem with the random function.

Code: Select all

In file included from sources\bitboard\bitboard_init.c:16:0:
include/random.h: In function 'qrandom':
include/random.h:22:21: warning: implicit declaration of function 'random'; did you mean 'qrandom'? [-Wimplicit-function-declaration]
  return (((uint64_t)random() << 43)
                     ^~~~~~
                     qrandom
sources\bitboard\bitboard_init.c: In function 'magic_init':
sources\bitboard\bitboard_init.c:91:3: warning: implicit declaration of function 'srandom'; did you mean 'qrandom'? [-Wimplicit-function-declaration]
   srandom(17);
   ^~~~~~~
   qrandom

Code: Select all

bitboard_init.o:bitboard_init.c:(.text+0x8): undefined reference to `random'
bitboard_init.o:bitboard_init.c:(.text+0xf): undefined reference to `random'
bitboard_init.o:bitboard_init.c:(.text+0x23): undefined reference to `random'
bitboard_init.o:bitboard_init.c:(.text+0x53d): undefined reference to `srandom'
Qui trop embrasse mal étreint.