Drago is back

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
stegemma
Posts: 859
Joined: Mon Aug 10, 2009 10:05 pm
Location: Italy
Full name: Stefano Gemma

Drago is back

Post by stegemma »

After a lot of work with Satana/Sabrina in C++, I finally get back to assembly; I've announced this some time ago but now it's time to restart where I've stopped with assembly. Raffaela and Freccia were the first porting of Drago to Windows, in assembly. Satana/Sabrina was the attempt to work in C++ and gave me the opportunity to have a solid interface with WinBoard, a Tourney mode and a genetical learning environment but the engine itself is not satisfying. Sabrina is portable and this is a plus but now my goal must be performance, not portability. That's why the new engine is in assembly, with the C++ interface of Satana, some idea from Sabrina/Freccia and the passion felt in Drago original development.

This new engine will be private, until it will becomes a strong player.

Drago is back.
Author of Drago, Raffaela, Freccia, Satana, Sabrina.
http://www.linformatica.com
User avatar
stegemma
Posts: 859
Joined: Mon Aug 10, 2009 10:05 pm
Location: Italy
Full name: Stefano Gemma

Re: Drago is back

Post by stegemma »

Here is a comparison between C++ and assembly:

Code: Select all

setboard r1bqk2r/pppp1ppp/2n2n2/2b1p3/2B1P3/2N2N2/PPPP1PPP/R1BQK2R w KQkq - 6 5
\
#
r.bqk..r
pppp.ppp
..n..n..
..b.p...
..B.P...
..N..N..
PPPP.PPP
R.BQK..R

# white value: 0.00 FEN: r1bqk2r/pppp1ppp/2n2n2/2b1p3/2B1P3/2N2N2/PPPP1PPP/R1BQK2R w KQkq -
#
perft 5
Nodes: 51781599, Time: 1014 ms, Nodes/s: 51016353
\drago 5
#54759575: 0.747s 73207987 moves/sec
#51781599: 0.748s 69134311 leaves/sec
perft 6
Nodes: 1785363392, Time: 35279 ms, Nodes/s: 50605538
\drago 6
#1893105082: 25.881s 73143693 moves/sec
#1785363392: 25.882s 68978224 leaves/sec
The C++ version completes the perft 6 of this position in about 35 seconds, while the assembly version needs only about 25 seconds... and it needs to be optimized further!
Author of Drago, Raffaela, Freccia, Satana, Sabrina.
http://www.linformatica.com
User avatar
stegemma
Posts: 859
Joined: Mon Aug 10, 2009 10:05 pm
Location: Italy
Full name: Stefano Gemma

Re: Drago is back

Post by stegemma »

After some more optimization, now the move generator of Drago has become the faster that I had ever write:

Code: Select all

setboard r1bqk2r/pppp1ppp/2n2n2/2b1p3/2B1P3/2N2N2/PPPP1PPP/R1BQK2R w KQkq - 6 5
perft 5
# 1     36
# 2     1256
# 3     43408
# 4     1492118
# 5     51781599
Nodes: 51781599, Time: 610 ms, Nodes/s: 84748934
perft 6
# 1     36
# 2     1256
# 3     43408
# 4     1492118
# 5     51781599
# 6     1785363392
Nodes: 1785363392, Time: 21023 ms, Nodes/s: 84920252
Here the term "nodes per second" must be read "leaves per second".

Of course it is fast compared with my other engines. I don't use standard bitboards or magic bitboard but my own algorithms.

It has alfagemma algorithm too with iterative deepening but no position evaluation yet. I hope to be ready for the IGT 2018 with a very competitive engine.
Author of Drago, Raffaela, Freccia, Satana, Sabrina.
http://www.linformatica.com
Joost Buijs
Posts: 1563
Joined: Thu Jul 16, 2009 10:47 am
Location: Almere, The Netherlands

Re: Drago is back

Post by Joost Buijs »

There is no need to use assembly anymore, the compilers are so heavily optimized nowadays that it is very hard to improve upon the generated code.

My move generator is written in C++ (using magics) and does a very good job too, the timing is with full incremental update of material score including phase and Zobrist hashes.

Move generation doesn't take a lot of time, most time consuming functions are evaluation, see and probing the transposition table.

Code: Select all


fen r1bqk2r/pppp1ppp/2n2n2/2b1p3/2B1P3/2N2N2/PPPP1PPP/R1BQK2R w KQkq - 6 5

 r . b q k . . r
 * * * * . * * *
 . . n . . n . .
 . . b . * . . .
 . . B . + . . .
 . . N . . N . .
 + + + + . + + +
 R . B Q K . . R

perft 6

.f3e5 77316538
.c4f7 4148382
.a2a3 56935750
.b2b3 52365186
.d2d3 64167151
.g2g3 49093557
.h2h3 54328201
.a2a4 56841562
.b2b4 53067738
.d2d4 77302844
.g2g4 48415096
.h2h4 54092504
.e1g1 44097041
.c3b1 44384250
.c3e2 44562761
.c3a4 46720973
.c3b5 45156297
.c3d5 45117542
.f3g1 51374485
.f3d4 65198951
.f3h4 56795528
.f3g5 60604742
.d1e2 56334375
.c4f1 37466703
.c4e2 37513815
.c4b3 38322590
.c4d3 39467472
.c4b5 42145040
.c4d5 37507266
.c4a6 42491031
.c4e6 53373773
.a1b1 49188393
.h1f1 43942515
.h1g1 46428962
.e1f1 54329679
.e1e2 54764699

Nodes = 1785363392
Time  = 10.829
Nps   = 164870610
User avatar
stegemma
Posts: 859
Joined: Mon Aug 10, 2009 10:05 pm
Location: Italy
Full name: Stefano Gemma

Re: Drago is back

Post by stegemma »

if you use a faster algorithm you get a faster program. Magic bitboards are faster than my own move generation, so your C++ implementation is faster than my assembly implementation (2x faster) and a lot faster than my C++ implementation (4x faster!), that is similar (but not strictly equal) to the assembly version.

I could use magics or standard/rotated bitboards in C++ and I'll get a faster program than the current assembly version. Still I've doubled the speed of my program with almost the same algorithm that I've used in C++, just rewriting all in assembly. Maybe I'm better programmer in assembly than with C++.

I've write a program that converts assembly code to C++ code, just to make the program portable between Win/Mac/Linux. It is not finished yet but it will give an hint on how the C++ compiler can optimize better than hand made assembly.

I'm programming chess engine just for fun and I use C++ in business applications... so programming the chess engine in C++ wasn't interesting anymore, that's why I'd come back to assembly.

My engines are the worst of the world... I can't do worst than this, even in assembly! :)
Author of Drago, Raffaela, Freccia, Satana, Sabrina.
http://www.linformatica.com
User avatar
stegemma
Posts: 859
Joined: Mon Aug 10, 2009 10:05 pm
Location: Italy
Full name: Stefano Gemma

Re: Drago is back

Post by stegemma »

Joost Buijs wrote: Mon Sep 10, 2018 4:21 pm [...]
My move generator is written in C++ (using magics) and does a very good job too, the timing is with full incremental update of material score including phase and Zobrist hashes.
[...]
I have a dubt: do you execute moves at the last ply or just count the legal moves? My engine executes any move and then test for legality, even at the last ply (only a few moves were pre-filtered for legality, at the generation stage). This is because I have embedded perft in alfagemma (my recursive alphabeta) and I don't use two separated procedures.
Author of Drago, Raffaela, Freccia, Satana, Sabrina.
http://www.linformatica.com