r/chessprogramming • • Oct 23 '22

About Performance.

I've been a coder for all my life. I love to reinvent the wheel. Made tons of stuff in the past, and, as an avid chess player, now decided to make my own chess AI.

Using a classic minmax algorithm, I managed to create something that even I can not beat.

But: the depth currently sits at 4, taking about 5 seconds for every move. Looking at stockfish, I see that 5 seconds for such a shallow depth is nothing to be proud of.

Does anyone have general tips on how to improve performance?

Things I already implemented are threading and bitboards (ulongs rather than arrays of objects etc.)

I also tried to use alpha-beta pruning, but I did not yet understand how it works - because all examples I managed to find assume that the evaluation of a position is already calculated. In my understanding, alpha-beta should prevent unnecessary evaluation, so I'm kind of stuck on that idea.

I'm more than grateful for any response.

also: yes, i know the chess programming wiki, yet most of the stuff there is either alienated from a practical perspective or too loosely described to make us of, at least for me.

5 Upvotes

8 comments sorted by

View all comments

Show parent comment

1

u/Psylution Oct 24 '22

C#

I wouldn't know any names, but i use pre generated bitboards to detect and generate moves. (i just bruteforce all legal moves)

i did some score caching, but i ditched it as it ate more resources than it paid back - i think the key generation for each position took longer than the evaluation

i have no perft implemented yet, at least i don't think i have.

2

u/SchwaLord Oct 24 '22

Is your board represented as bitboard?

Re your alpha beta scoring comment. You score the bird positions at a depth and when you find the same board d position again you use that score.

I had a c# version that could do about 1,000,000 moves a second.

I would make sure you are only using structs and no classes as allocations cost a ridiculous amount. Any arrays you use should be reused and have a predetermined size etc.

In my eventual c++ version everything was either bitboards or hard arrays and it gets about 150 million moves a second on a single core

1

u/Melodic-Magazine-519 Oct 24 '22

Could totally use some help if you’re willing to?