How to speed up my engine

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
sje
Posts: 4675
Joined: Mon Mar 13, 2006 7:43 pm

Re: Move generation for check evasion

Post by sje »

lauriet wrote:Thats a good point. At the moment I have a legal move generator, which checks each generated move to see if the king is still in check.......this appears to be dumb, so I will work on changing this AND then your suggestion will help from there on in.
One benefit of a fast evasion generator is its use at interior search nodes where special move ordering may be obtained at the generation stage. E.g., capturing a single attacker, moving the king, interposing vs a single ray attacker, and finally en passant capture. Using that generation sequence could mean skipping all other move ordering for that node.

But even for a perft() only program which needs no move ordering, a specialized evasion generator pays off with a significant time savings.

At regular nodes, it can be handy to keep track of pinned men. My program Symbolic keeps two bitboards for this: a pinned bitboard (all pinned men; some might move along the pin direction) and a frozen bitboard (the pinned men which can't move at all). It takes time to do this, but the payback is much easier legal-move-only generation including evasion generation.

So when the Symbolic's move generator spits out a vector of moves, the rest of the program knows for certain that all the moves are legal and no further testing is needed. And that makes coding easier for everything downstream from the move generator.
User avatar
sje
Posts: 4675
Joined: Mon Mar 13, 2006 7:43 pm

Re: Move generation for check evasion

Post by sje »

Just for laughs, here's a link to the move generation C source excerpt for my program Oscar: https://dl.dropboxusercontent.com/u/316 ... rMoveGen.c

The routine at the bottom of the file is called to generate all legal moves. It does this by determining in-check status and then calling either the evasion generator or the non-evasion generator. The program is written for 32 bit architectures and uses 32 bit piece bit vectors instead of bitboards.

Some of the source indents are messed up because of Mac OS/X Xcode idiocies.
lauriet
Posts: 199
Joined: Sun Nov 03, 2013 9:32 am

Re: How to speed up my engine

Post by lauriet »

Henk wrote:Why do you want a faster engine ? There are already fast engines enough.
I really want a better engine (of my own making) and from what i have read search pays off better than evaluation, so a faster engine searches deeper.

Laurie.
lauriet
Posts: 199
Joined: Sun Nov 03, 2013 9:32 am

Re: How to speed up my engine

Post by lauriet »

Henk wrote:Why do you want a faster engine ? There are already fast engines enough.
I really want a better engine (of my own making) and from what i have read search pays off better than evaluation, so a faster engine searches deeper.

Laurie.
Henk
Posts: 7218
Joined: Mon May 27, 2013 10:31 am

Re: How to speed up my engine

Post by Henk »

lauriet wrote:
Henk wrote:Why do you want a faster engine ? There are already fast engines enough.
I really want a better engine (of my own making) and from what i have read search pays off better than evaluation, so a faster engine searches deeper.

Laurie.
It's only better if it skips more redundant nodes. And we only have alpha beta search/PVS and transposition table to make that possible. [Of course you can also use statistical lies to make it skip more nodes]
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: How to speed up my engine

Post by bob »

jdart wrote:That is way too many nodes.

Arasan's node count per ply (see last column), using this position
r1b1k2r/ppqn1ppp/2pbpn2/4N3/2BP4/2N5/PPP2PPP/R1BQR1K1 w kq -

1 0.00 Ng4 +0.62 119
1 0.01 Bf4 +0.76 170
1 0.01 Bf4 +0.76 409
2 0.01 Nxf7 +0.69 613
2 0.01 Nxf7 +0.69 2190
3 0.01 Nxd7 +0.79 3363
3 0.01 Nxd7 +0.79 4452
4 0.01 Nxf7! +0.98 4962
4 0.02 Nxf7 +1.04 5322
5 0.02 Nxf7 +0.92 6043
6 0.02 -- +0.74 7170
6 0.02 Bf4 +0.36 10264
6 0.02 Bf4 +0.36 10813

This is even using a wide window for the first few plies, so I can detect "easy moves." You should get be able to get much smaller numbers than you have (and if you do you will get to higher depths much faster).

I do all the forward pruning stuff that is standard now. But even if you just have null move you should be doing better I think. Static null pruning (https://chessprogramming.wikispaces.com ... ty+Pruning) is also very effective.

--Jon
I think it important to note that EBF (Effective Branching Factor) really should be an iteration by iteration measurement. This is not the same as the time taken for the first 5 plies divided into the time taken by the 6th ply. That will under-state the EBF. Correct is time (or nodes) for ONLY the 5 ply search divided into the time (or nodes) for the 6 ply search.
lauriet
Posts: 199
Joined: Sun Nov 03, 2013 9:32 am

Re: How to speed up my engine

Post by lauriet »

Hi Everyone.

First of all, thank you for all your input/help/suggestions/code review/opinions/insights.

FYI: My engine is now searching 2->3 ply deeper.

I had a legal move generator which checked every generated move for "in check" .......did I get out of check. This obviously took its toll. I have changed this to allow King captures and then pick this up on the next ply as a really bad move.

I have also made my LMR more aggressive by reducing "equal moves" that is moves that get a zero score via the PST.

I'm now getting 10->11 ply which I am happy with for my first engine on pretty modest hardware. Since I have no transposition table I think this is the next thing to incorporate.


Thanks again and "watch this space"


Regards
Laurie.
lauriet
Posts: 199
Joined: Sun Nov 03, 2013 9:32 am

Re: How to speed up my engine

Post by lauriet »

"First of all, swear that your program has no bugs Very Happy Otherwise most optimizations won't make any sense"


After spending quit a lot of time recently going over my code, I have 3 tips for other chess programmers.

1: make sure there are no bugs :oops:

After you are happy with step one.....

2: check to see if there are any bugs :oops: :oops:

Finally having completed step 1 and 2....

3: be aware there may be bugs and you should look for these :oops: :oops: :oops:


Regards to all.
Laurie
lauriet
Posts: 199
Joined: Sun Nov 03, 2013 9:32 am

Re: How to speed up my engine

Post by lauriet »

"First of all, swear that your program has no bugs Very Happy Otherwise most optimizations won't make any sense"


After spending quit a lot of time recently going over my code, I have 3 tips for other chess programmers.

1: make sure there are no bugs :oops:

After you are happy with step one.....

2: check to see if there are any bugs :oops: :oops:

Finally having completed step 1 and 2....

3: be aware there may be bugs and you should look for these :oops: :oops: :oops:


Regards to all.
Laurie
Sven
Posts: 4052
Joined: Thu May 15, 2008 9:57 pm
Location: Berlin, Germany
Full name: Sven Schüle

Re: How to speed up my engine

Post by Sven »

Sounds like you are now close to step 4 :wink: