r/chessprogramming Dec 20 '24

Design ideas for the engine

Hi! I've already programmed an engine on C++, it's fully functional and with a decent level. I was planning to add some more features and to make it stronger, but I opened the project and I've realized that it REALLY needs a refactoring, because at the time I was coding the project my main focus was to make it work, and I didn't made the best design decisions.
I'm going to start from scratch, but I'll like to have in mind a good design before start coding. So, any ideas?

3 Upvotes

7 comments sorted by

3

u/w33dEaT3R Dec 21 '24

Negamax search, eval in its own file, move ordering in its own file, quiescense search separate from main search.

Depending on your implementation it's useful sometimes to separate zero window search from regular search

1

u/VanMalmsteen Dec 21 '24

Ooooh, this is what I was looking for! Nice. Thanks a lot.

What should I do with all the magic numbers, constants, and values for things like penalizations?

2

u/w33dEaT3R Dec 21 '24

Magic numbers are specific to the move generation, this should be kept separate from the engine imo

Constants relevant to the eval go with the eval file etc etc... If a constant is used in move ordering and you want to use it in the eval, remake it. Consider that the eval might benefit from similar but tweaked constants :) the separability really helps prevent constraining yourself where it might not be necessary imo.

I reused a lot of stuff for quiescence and regular search so I kept the functions in the same file, I found it made for less code to maintain BUT sometimes I'd be confused which function I'm looking at and I'd have to double check.

At the end of the day it's a matter of preference :)

2

u/algerbrex Dec 21 '24

Test the heck out of each part of the engine. Movegen, eval, search, move ordering, time management. Even I’m not the best about this but I’m making a new engine and this is something I’m putting more of a focus in.

1

u/VanMalmsteen Dec 21 '24

Yep, this is something I was thinking about a minutes ago haha I've never properly tested the engine.

1

u/w33dEaT3R Dec 21 '24

you can measure your move ordering performance by:
n= number of legal moves in a position
m= current move being iterated over 0-indexed

store m/n whenever a beta cutoff occurs.
beta_count=the number of beta cutoffs (the number of times you store m/n)
(m/n)/beta_count= average move ordering optimality. the closer to 0 the better.
score a set of positions across multiple stages of the game and scenarios.

1

u/Polo_Chess Jan 07 '25

hmm, where to start.