Publius - public domain teaching engine

Discussion of chess software programming and technical issues.

Moderator: Ras

PK
Posts: 904
Joined: Mon Jan 15, 2007 11:23 am
Location: Warsza

Publius - public domain teaching engine

Post by PK »

I have tried my hand at creating a simple bitboard teaching engine. I expect to finish it in about 3 months, and only then make an official release, but since in the meantime it reached 2700+ on the CCRL scale, I can as well show it. It is available at: https://github.com/nescitus/publius

"Simple" and "teaching engine" are vague concepts, so explanation of constraints is in order:

- eval is done, if not necessarily tuned. It takes into account material, bishop pair, piece/square tables, mobility, passed, doubled and isolated pawns, intentionally primitive king safety and some detection of drawish endgames.
- quiescence search is probably done, unless I make delta pruning work
- search is under active developement and there will be more stuff added
- board update relies on four functions: AddPiece, DeletePiece, MovePiece and ChangePiece
- apart from the hash key, there are no incremental updates of evaluation stuff. If someone wants to slap NNUE on top of my code, there will be no need to delete them. If not, at least eval can be read in one piece.
- movegen is slow, there is no specialized popcount. Simple kindergarten bitboard stuff would be a welcome addition.
- I'm still not sure whether to generate discovered checks
- more comments will be added.

Why am I doing that? Because CPW-engne is old and because I want to learn about more modern search techniques. If search gets good enough, I might be tempted to fork it and do Rodent V, but don't read it as a promise.

Enjoy!
mar
Posts: 2652
Joined: Fri Nov 26, 2010 2:00 pm
Location: Czech Republic
Full name: Martin Sedlak

Re: Publius - public domain teaching engine

Post by mar »

nice and clean - great job Pawel!
also a great name :)
PK
Posts: 904
Joined: Mon Jan 15, 2007 11:23 am
Location: Warsza

Re: Publius - public domain teaching engine

Post by PK »

mar wrote: Mon Mar 17, 2025 5:29 pm nice and clean - great job Pawel!
also a great name :)
Thank you for confirming that this approach makes sense. I have a history of writing messy code (see Rodent) and need to change that. If you have some ideas to make this code even cleaner, I'm all ears.
User avatar
Roland Chastain
Posts: 675
Joined: Sat Jun 08, 2013 10:07 am
Location: France
Full name: Roland Chastain

Re: Publius - public domain teaching engine

Post by Roland Chastain »

Thank you for that new project Pawel!

There is a tabulation at end of line 12 of makefile that prevents it to work by me. :wink:

After correction, I can compile the program under Linux.
Qui trop embrasse mal étreint.
PK
Posts: 904
Joined: Mon Jan 15, 2007 11:23 am
Location: Warsza

Re: Publius - public domain teaching engine

Post by PK »

Took me a while and it will certainly require more comments, but kindergarten bitboards were added for a nice speedup:

without: Bench at depth 15 took 32391 milliseconds, searching 28402034 nodes at 876849 nodes per second.
with: Bench at depth 15 took 23922 milliseconds, searching 28402034 nodes at 1187276 nodes per second.
PK
Posts: 904
Joined: Mon Jan 15, 2007 11:23 am
Location: Warsza

Re: Publius - public domain teaching engine

Post by PK »

With singular extension added (and heavily commented) Publius should be 2800 on the CCRL scale, still with rather simple evaluation.
Bart Weststrate
Posts: 15
Joined: Fri Mar 18, 2016 3:34 pm

Re: Publius - public domain teaching engine

Post by Bart Weststrate »

PK wrote: Sat May 31, 2025 6:14 pm With singular extension added (and heavily commented) Publius should be 2800 on the CCRL scale, still with rather simple evaluation.
Looks nice. When building in VS 2022 it doesn't recognize the clamp function in eval. What to do?

Edit i changed it to this:

// Make sure eval doesn't exceed mate score
//score = clamp(score, -EvalLimit, EvalLimit);
if (score < -EvalLimit) score = -EvalLimit;
if (score > EvalLimit) score = EvalLimit;

I hope that behaves the same... :)
Bart Weststrate
Posts: 15
Joined: Fri Mar 18, 2016 3:34 pm

Re: Publius - public domain teaching engine

Post by Bart Weststrate »

With this change the enigine "hangs" at depth 18. Is this expected or does "clamp" do something else....

Output startpos:

go depth 30
info depth 1 time 0 nodes 0 nps 0
info depth 1 time 0 nodes 2 nps 0 score cp 4 pv a2a4
info depth 1 time 0 nodes 4 nps 0 score cp 14 pv b2b4
info depth 1 time 0 nodes 6 nps 0 score cp 25 pv c2c4
info depth 1 time 0 nodes 8 nps 0 score cp 43 pv d2d4
info depth 1 time 0 nodes 10 nps 0 score cp 56 pv e2e4
info depth 2 time 0 nodes 25 nps 0
info depth 2 time 0 nodes 63 nps 0 score cp 5 pv e2e4 e7e5
info depth 3 time 0 nodes 127 nps 0
info depth 3 time 0 nodes 264 nps 0 score cp 30 pv e2e4 e7e5 g1f3
info depth 4 time 15 nodes 315 nps 21000
info depth 4 time 15 nodes 635 nps 42333 score cp 21 pv e2e4 e7e5 d2d4 d7d5 e4d5 d8d5
info depth 5 time 15 nodes 1108 nps 73866
info depth 5 time 15 nodes 2170 nps 144666 score cp 28 pv e2e4 e7e5 b1c3 g8f6 g1f3
info depth 5 time 31 nodes 2902 nps 93612 score cp 30 pv b1c3 d7d6 e2e4 e7e5 g1f3
info depth 6 time 31 nodes 3789 nps 122225
info depth 6 time 31 nodes 5568 nps 179612 score cp 12 pv b1c3 d7d5 e2e3 g8f6 g1f3 e7e6
info depth 6 time 62 nodes 9085 nps 146532 score cp 21 pv e2e4 d7d6 d2d4 g8f6 b1c3 e7e5
info depth 7 time 62 nodes 9507 nps 153338
info depth 7 time 78 nodes 12459 nps 159730 score cp 29 pv e2e4 d7d5 e4d5 g8f6 d2d4 f6d5 b1c3
info depth 8 time 78 nodes 13538 nps 173564
info depth 8 time 125 nodes 18587 nps 148696 score cp 23 pv e2e4 d7d5 e4d5 g8f6 d2d4 f6d5 c2c4 d5f6
info depth 9 time 156 nodes 25587 nps 164019
info depth 9 time 172 nodes 29178 nps 169639 score cp 33 pv e2e4
info depth 9 time 234 nodes 38230 nps 163376 score cp 31 pv e2e4 e7e6 d2d4 c7c5 c2c3 g8f6 e4e5 f6d5 g1f3 c5d4 c3d4
info depth 10 time 234 nodes 39845 nps 170277
info depth 10 time 359 nodes 62678 nps 174590 score cp 21 pv e2e4 e7e6 d2d4 d7d5 b1c3 d5e4 c3e4 b8c6 g1f3 g8f6
info depth 11 time 359 nodes 62868 nps 175119
info depth 11 time 562 nodes 96325 nps 171396 score cp 24 pv e2e4 e7e6 d2d4 c7c5 c2c3 g8f6 e4e5 f6d5 c3c4 d5b4 g1f3 c5d4 f3d4
info depth 12 time 609 nodes 103756 nps 170371
info depth 12 time 1687 nodes 293354 nps 173890 score cp 9 pv e2e4 e7e5 g1f3 g8f6 f3e5 d7d6 e5c4 f6e4 d2d3 e4f6 b1c3 b8c6
info depth 13 time 2125 nodes 370640 nps 174418
info depth 13 time 2437 nodes 420188 nps 172420 score cp 19 pv e2e4
info depth 13 time 3187 nodes 549943 nps 172558 score cp 14 pv e2e4 e7e5 b1c3 g8f6 g1f3 b8c6 d2d4 e5d4 f3d4 f8b4 d4c6 d7c6 f1d3
info depth 14 time 3312 nodes 569971 nps 172092
info depth 14 time 3625 nodes 628232 nps 173305 score cp 17 pv e2e4 e7e5 g1f3 b8c6 b1c3 g8f6 d2d4 e5d4 f3d4 f8b4 d4c6 d7c6 d1d8 e8d8 c1g5
info depth 15 time 3969 nodes 686041 nps 172849
info depth 15 time 7328 nodes 1258770 nps 171775 score cp 16 pv g1f3 g8f6 e2e3 e7e6 d2d4 d7d5 b1c3 b8c6 f1d3 f8e7 e1g1 e8g8 f3e5 c8d7 e5d7 d8d7
info depth 16 time 7578 nodes 1302540 nps 171884
info depth 16 time 8906 nodes 1537985 nps 172690 score cp 12 pv g1f3 g8f6 d2d4 d7d5 b1c3 e7e6 e2e3 b8c6 f1d3 f8b4 e1g1 e8g8 a2a3 b4c3 b2c3 f6e4
info depth 17 time 9453 nodes 1631044 nps 172542
info depth 17 time 12922 nodes 2240360 nps 173375 score cp 17 pv g1f3 g8f6 e2e3 e7e6 d2d4 d7d5 c2c4 c7c5 c4d5 e6d5 f1b5 c8d7 b1c3 d7b5 c3b5 c5d4 e1g1 d4e3 c1e3
info depth 18 time 15094 nodes 2608990 nps 172849
info depth 18 time 17547 nodes 3035512 nps 172993 score cp 15 pv g1f3 g8f6 e2e3 d7d5 d2d4 b8c6 b1c3 e7e6 f1d3 f8e7 e1g1 e8g8 a2a3 a7a5 c1d2 b7b6 f3e5 c6e5 d4e5
info depth 18 time 24890 nodes 4261883 nps 171228 score cp 27 pv e2e4

No new output here.......

Edit: after typing some enters in te console window it comes alive:

info depth 18 time 63234 nodes 4261883 nps 67398 score cp 27 pv e2e4
info depth 18 time 78875 nodes 6909794 nps 87604 score cp 21 pv e2e4 e7e5 g1f3 g8f6 f3e5 d7d6 e5f3 f6e4 f1d3 d6d5 e1g1 f8e7 f1e1 e8g8 b1c3 e4f6 f3e5 b8c6
info depth 19 time 80719 nodes 7227989 nps 89545
info depth 19 time 90922 nodes 8921996 nps 98128 score cp 31 pv e2e4

So the engine is alive but shows no output... Also nps is lower.

Is this all expected behaviour or is there something wrong? :)
Joost Buijs
Posts: 1631
Joined: Thu Jul 16, 2009 10:47 am
Location: Almere, The Netherlands

Re: Publius - public domain teaching engine

Post by Joost Buijs »

Bart Weststrate wrote: Sun Jun 08, 2025 10:02 am
Looks nice. When building in VS 2022 it doesn't recognize the clamp function in eval. What to do?

Edit i changed it to this:

// Make sure eval doesn't exceed mate score
//score = clamp(score, -EvalLimit, EvalLimit);
if (score < -EvalLimit) score = -EvalLimit;
if (score > EvalLimit) score = EvalLimit;

I hope that behaves the same... :)
std::clamp() is a C++20 function, when you set MSVC in the project properties to C++20 it will recognize std::clamp().
Make sure to include <algorithm>, that's where it is defined.
Bart Weststrate
Posts: 15
Joined: Fri Mar 18, 2016 3:34 pm

Re: Publius - public domain teaching engine

Post by Bart Weststrate »

Joost Buijs wrote: Sun Jun 08, 2025 12:47 pm
Bart Weststrate wrote: Sun Jun 08, 2025 10:02 am
Looks nice. When building in VS 2022 it doesn't recognize the clamp function in eval. What to do?

Edit i changed it to this:

// Make sure eval doesn't exceed mate score
//score = clamp(score, -EvalLimit, EvalLimit);
if (score < -EvalLimit) score = -EvalLimit;
if (score > EvalLimit) score = EvalLimit;

I hope that behaves the same... :)
std::clamp() is a C++20 function, when you set MSVC in the project properties to C++20 it will recognize std::clamp().
Make sure to include <algorithm>, that's where it is defined.
Thans Joost, old Warrior :) So it's in a package (or option) that isn't installed (yet). I will dive into that.
Can you tell if my replacing code does the same?