Mauritz8 / Vividmind

A UCI-compatible chess engine written from scratch in C++
1 stars 0 forks source link

Make move generation faster #17

Closed Mauritz8 closed 1 year ago

Mauritz8 commented 1 year ago

Instead of checking every possible square to see if it's a legal move, only check the squares that could be legal. So for example with knight moves, only check the 8 possible squares instead of the 63 other squares. This will speed up move generation immensly.

Mauritz8 commented 1 year ago

It currently takes 33 seconds for the engine to search the starting position to a depth of 2 (400 positions). For each of these positions it takes roughly 80 000 microseconds to generate all legal moves.

Mauritz8 commented 1 year ago

As it is implemented now it does approximately 32×64×32×64 = 4 194 304 loop iterations, but if I implement it in the way I intend to that number should be reduced to about 32×8×32×8 = 65 536 iterations. That is an unfathomable decrease, and is just 1,56% of the iterations that is currently done. So the engine should be able to search the starting position to a depth of 2 in just 33 * 1,56% = 0,5 seconds. So instead of taking 33 seconds it should just take 0,5 seconds!

Mauritz8 commented 1 year ago

Now I have implemented it and the results were surpisingly close to what I expected, it takes 0.6 seconds to now to search the starting position to a depth of 2. I still want to store the pieces in the board class so they don't have to be searched for every time, it won't make much of a difference when there's many pieces on the board but the fewer pieces the more impact it will have.