adding TT reduces NPS by allot

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

Dann Corbit
Posts: 12548
Joined: Wed Mar 08, 2006 8:57 pm
Location: Redmond, WA USA

Re: adding TT reduces NPS by allot

Post by Dann Corbit »

syzygy wrote: Thu Apr 18, 2024 11:23 pm
towforce wrote: Thu Apr 18, 2024 10:47 pm
syzygy wrote: Thu Apr 18, 2024 9:31 pmA programmer's first engine written from scratch in 2024 will be quite similar to a programmer's first engine written from scratch in 1994.
If I were writing a chess engine today, I would use one of the open source chess DLLs to take care of things like move generation. I'm guessing you wouldn't count that as "writing from scratch", but I would call it, "good development practice". :)
Good development practice is not writing a chess engine at all because there are plenty of engines already and you can just use one of those.

In principle I agree with you that not re-inventing the wheel is a good thing, but someone who starts writing a regular chess program will in most cases not do that for the end result (yet another chess engine) but for the (learning) experience. Why would one want to reduce that experience by copying someone else's code?

(Of course in reality there is nobody that could write a half-decent engine entirely from scratch without at least looking at some high-level code. So there will inevitably be some kind of borrowing, and that is fine. And if you want to borrow more than I would like to myself, then that is perfectly fine too (as long as copyrights are respected etc.). And once you have something that plays somewhat decent legal chess without crashing and want to add TBs, then by all means just copy the code from somewhere else.)
Nothing wrong with copying an algorithm, unless there is a patent.
But copying code (beyond fair use) is illegal unless the copyright of the original code allows it and the original license is obeyed.
In my opinion (and I am not a legal expert) a short code snippet with attribution in the code is fair use (and the release notes should also mention this use if the source code is not available to the public for the new engine).
Now, with a public domain program, there are no requirements and CPL is very similar.
There are fairly liberal license types such as BSD and Mozilla which just require attribution.
GPL requires that the new code be published
Ordinary copyright requires permission for anything beyond fair use.

I do realize that many people ignore these standards. But that is neither here nor there.
Taking ideas is not a vice, it is a virtue. We have another word for this. It is called learning.
But sharing ideas is an even greater virtue. We have another word for this. It is called teaching.
Ciekce
Posts: 127
Joined: Sun Oct 30, 2022 5:26 pm
Full name: Conor Anstey

Re: adding TT reduces NPS by allot

Post by Ciekce »

syzygy wrote: Thu Apr 18, 2024 9:26 pm Whether it is worth it will depend on the engine. For most engines (that were not derived from SF), it is most likely not worth it to probe in the qsearch. For an engine written from scratch, it will probably take 10+ years of active development to make probing in the qsearch worth it. In the meantime, just don't probe in the qsearch.
you actually cannot be serious I refuse to believe this is not satire

do you think that every modern engine is """derived""" from stockfish? do you want new devs to reinvent every search technique from first principles?
User avatar
hgm
Posts: 27837
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: adding TT reduces NPS by allot

Post by hgm »

Dann Corbit wrote: Fri Apr 19, 2024 12:22 amNothing wrong with copying an algorithm, unless there is a patent.
Legally there is nothing wrong with copying an unpatented algortithm. But it would be a stretch to call a new implementation of a tried an proven algorithm an 'original engine'. A rewrite (e.g. in another programming language) is just as much a derivative as slightly modified copy-paste job, which under the GPL would also be perfectly legal. In fact the latter can be more original.

Chess is just a silly game played to avoid boredom, and writing or using programs to play it is merely a hobby. There are many ways you can have fun with it, so that there basically is something for everyone. There are people that want to start at 3000+ Elo by copying as much of the algorithm of open-source engines as they can, and try to improve from there. There are others that like to start from TSCP, and muddle on on their own to reach 2400 Elo. That can be equally challenging, and provide as much fun. After all, fun is a very subjective emotion. The computer-chess community also includes people that cannot program at all. But these can have fun testing engines by playing those against each other, or creating opening books, and their contributions often are much appreciated.

I wrote my first chess program (Usurpator I around 1978) without having seen any high-level code of another engine; the only guidance I used was a diagram in a book from my AI course that depicted an alpha-beta pruned tree, in which I recognized the 'single refutation is sufficient' principle that every chess player intuitively applies when calculating variations. Of course one can argue on whether Usurpator I was a 'decent engine'. But considering that it had to run in 2KB RAM (code + data!), and was written by poking the hex machine code into memory, I don't think it was too bad.
User avatar
towforce
Posts: 11610
Joined: Thu Mar 09, 2006 12:57 am
Location: Birmingham UK

Re: adding TT reduces NPS by allot

Post by towforce »

Dann Corbit wrote: Fri Apr 19, 2024 12:22 am
syzygy wrote: Thu Apr 18, 2024 11:23 pm
towforce wrote: Thu Apr 18, 2024 10:47 pm
syzygy wrote: Thu Apr 18, 2024 9:31 pmA programmer's first engine written from scratch in 2024 will be quite similar to a programmer's first engine written from scratch in 1994.
If I were writing a chess engine today, I would use one of the open source chess DLLs to take care of things like move generation. I'm guessing you wouldn't count that as "writing from scratch", but I would call it, "good development practice". :)
Good development practice is not writing a chess engine at all because there are plenty of engines already and you can just use one of those.

In principle I agree with you that not re-inventing the wheel is a good thing, but someone who starts writing a regular chess program will in most cases not do that for the end result (yet another chess engine) but for the (learning) experience. Why would one want to reduce that experience by copying someone else's code?

(Of course in reality there is nobody that could write a half-decent engine entirely from scratch without at least looking at some high-level code. So there will inevitably be some kind of borrowing, and that is fine. And if you want to borrow more than I would like to myself, then that is perfectly fine too (as long as copyrights are respected etc.). And once you have something that plays somewhat decent legal chess without crashing and want to add TBs, then by all means just copy the code from somewhere else.)
Nothing wrong with copying an algorithm, unless there is a patent...

Quick clarification: I was talking about using an open source software library in my own code (DLL = Dynamic Link Library) - something that most software developers do every day - not copying code from another engine (if I was going to do that, I personally would make a fork of an open source engine). Chess libraries do exist that do the pesky stuff like move generation, leaving one free to focus on fun stuff like writing an eval.

However - please continue the discussion - it's interesting and insightful!
Writing is the antidote to confusion.
It's not "how smart you are", it's "how are you smart".
Your brain doesn't work the way you want, so train it!
Viz
Posts: 61
Joined: Tue Apr 09, 2024 6:24 am
Full name: Michael Chaly

Re: adding TT reduces NPS by allot

Post by Viz »

Ciekce wrote: Fri Apr 19, 2024 1:13 am
syzygy wrote: Thu Apr 18, 2024 9:26 pm Whether it is worth it will depend on the engine. For most engines (that were not derived from SF), it is most likely not worth it to probe in the qsearch. For an engine written from scratch, it will probably take 10+ years of active development to make probing in the qsearch worth it. In the meantime, just don't probe in the qsearch.
you actually cannot be serious I refuse to believe this is not satire

do you think that every modern engine is """derived""" from stockfish? do you want new devs to reinvent every search technique from first principles?
Usual talkchess hot take that you can't just take relevant knowledge and code things from scratch that with enough testing will produce you a really strong engine.
Despite there being examples showing the opposite.
chrisw
Posts: 4345
Joined: Tue Apr 03, 2012 4:28 pm

Re: adding TT reduces NPS by allot

Post by chrisw »

If a Martian arrived on earth, armed with the same standards and logic used to justify the ICGA conclusion that Rybka was derived from Fruit, he would find that all engines are derived from Stockfish.

He’ld also find, especially if lacking timestamps, that all engines are derived from any engine you care to mention.

Or, all engines are derived from all other engines, give or take a bit of originality from somewhere.
User avatar
hgm
Posts: 27837
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: adding TT reduces NPS by allot

Post by hgm »

Except for AlphaZero, perhaps.
syzygy
Posts: 5569
Joined: Tue Feb 28, 2012 11:56 pm

Re: adding TT reduces NPS by allot

Post by syzygy »

Dann Corbit wrote: Fri Apr 19, 2024 12:22 am
syzygy wrote: Thu Apr 18, 2024 11:23 pm
towforce wrote: Thu Apr 18, 2024 10:47 pm
syzygy wrote: Thu Apr 18, 2024 9:31 pmA programmer's first engine written from scratch in 2024 will be quite similar to a programmer's first engine written from scratch in 1994.
If I were writing a chess engine today, I would use one of the open source chess DLLs to take care of things like move generation. I'm guessing you wouldn't count that as "writing from scratch", but I would call it, "good development practice". :)
Good development practice is not writing a chess engine at all because there are plenty of engines already and you can just use one of those.

In principle I agree with you that not re-inventing the wheel is a good thing, but someone who starts writing a regular chess program will in most cases not do that for the end result (yet another chess engine) but for the (learning) experience. Why would one want to reduce that experience by copying someone else's code?

(Of course in reality there is nobody that could write a half-decent engine entirely from scratch without at least looking at some high-level code. So there will inevitably be some kind of borrowing, and that is fine. And if you want to borrow more than I would like to myself, then that is perfectly fine too (as long as copyrights are respected etc.). And once you have something that plays somewhat decent legal chess without crashing and want to add TBs, then by all means just copy the code from somewhere else.)
Nothing wrong with copying an algorithm, unless there is a patent.
But copying code (beyond fair use) is illegal unless the copyright of the original code allows it and the original license is obeyed.
I mentioned copyright.
syzygy
Posts: 5569
Joined: Tue Feb 28, 2012 11:56 pm

Re: adding TT reduces NPS by allot

Post by syzygy »

Ciekce wrote: Fri Apr 19, 2024 1:13 am
syzygy wrote: Thu Apr 18, 2024 9:26 pm Whether it is worth it will depend on the engine. For most engines (that were not derived from SF), it is most likely not worth it to probe in the qsearch. For an engine written from scratch, it will probably take 10+ years of active development to make probing in the qsearch worth it. In the meantime, just don't probe in the qsearch.
you actually cannot be serious I refuse to believe this is not satire

do you think that every modern engine is """derived""" from stockfish? do you want new devs to reinvent every search technique from first principles?
Do you still not understand that this thread is about an engine written freshly from scratch?
syzygy
Posts: 5569
Joined: Tue Feb 28, 2012 11:56 pm

Re: adding TT reduces NPS by allot

Post by syzygy »

Viz wrote: Fri Apr 19, 2024 9:16 am
Ciekce wrote: Fri Apr 19, 2024 1:13 am
syzygy wrote: Thu Apr 18, 2024 9:26 pm Whether it is worth it will depend on the engine. For most engines (that were not derived from SF), it is most likely not worth it to probe in the qsearch. For an engine written from scratch, it will probably take 10+ years of active development to make probing in the qsearch worth it. In the meantime, just don't probe in the qsearch.
you actually cannot be serious I refuse to believe this is not satire

do you think that every modern engine is """derived""" from stockfish? do you want new devs to reinvent every search technique from first principles?
Usual talkchess hot take that you can't just take relevant knowledge and code things from scratch that with enough testing will produce you a really strong engine.
Despite there being examples showing the opposite.
This is not about a "really strong" or even a strong engine. Someone is writing his very first chess program, implemented a TT, and saw his nps plummet. Not probing in the qsearch will avoid most of the nps drop, and the engine will almost certainly play stronger (which can simply be tested). Sure, after some years of further development it might be a win to probe the TT in the qsearch again, but that is not a reason to stick to that now. Engine development is an iterative process.