New engine: Peacekeeper

Discussion of chess software programming and technical issues.

Moderator: Ras

Sazgr
Posts: 66
Joined: Thu Dec 09, 2021 8:26 pm
Full name: Kyle Zhang

New engine: Peacekeeper

Post by Sazgr »

I have been making a chess engine, named Peacekeeper, for a while. Finally it have gotten to the point where it seems to work decently, with no obvious bugs :D . Right now, it beats TSCP most of the time (about 80%). Some people might have seen it on GitHub already, but it is on https://github.com/Sazgr/peacekeeper. Most likely, I will use this thread for any further questions.

Right now the engine uses PESTO's evaluation, which I am planning to replace not far in the future.
kranium
Posts: 2129
Joined: Thu May 29, 2008 10:43 am

Re: New engine: Peacekeeper

Post by kranium »

Sazgr wrote: Tue Oct 18, 2022 9:24 pm I have been making a chess engine, named Peacekeeper, for a while. Finally it have gotten to the point where it seems to work decently, with no obvious bugs :D . Right now, it beats TSCP most of the time (about 80%). Some people might have seen it on GitHub already, but it is on https://github.com/Sazgr/peacekeeper. Most likely, I will use this thread for any further questions.

Right now the engine uses PESTO's evaluation, which I am planning to replace not far in the future.
Very nice...great work!

"I tried to support MSVC intrinsics, but since I do not have it, there might be errors."
These work in your project for a Windows compile:

Code: Select all

#ifdef _MSC_VER
#include <intrin.h>
#endif

#include "typedefs.h"

inline int popcount(u64 bits) {
#ifdef __GNUC__
    return __builtin_popcountll(bits);
#elif _MSC_VER
    return static_cast<int>(__popcnt64(bits));
#endif
}

inline int get_lsb(u64 bits) {
#ifdef __GNUC__
    return __builtin_ctzll(bits);
#elif _MSC_VER
    unsigned long idx;
    _BitScanForward64(&idx, bits);
    return static_cast<int>(idx);
#endif
}

inline int get_msb(u64 bits) {
#ifdef __GNUC__
    return __builtin_clzll(bits) ^ 63;
#elif _MSC_VER
    unsigned long idx;
    _BitScanReverse64(&idx, bits);
    return static_cast<int>(idx);
#endif
}
You may want to consider going w/ -std=c++20 and using the new intrinsics included in <bit>:
std::popcount
std::countr_zero

https://en.cppreference.com/w/cpp/header/bit

Good luck with your project!
dangi12012
Posts: 1062
Joined: Tue Apr 28, 2020 10:03 pm
Full name: Daniel Infuehr

Re: New engine: Peacekeeper

Post by dangi12012 »

If you have #pragma once just declare as static in the header and delete this file:
https://github.com/Sazgr/peacekeeper/bl ... magics.cpp

This is also very small:
https://github.com/Sazgr/peacekeeper/bl ... typedefs.h

But its more of a personal preference. I strongly recommend having as little code noise as possible + KISS principle.
Worlds-fastest-Bitboard-Chess-Movegenerator
Daniel Inführ - Software Developer
Sazgr
Posts: 66
Joined: Thu Dec 09, 2021 8:26 pm
Full name: Kyle Zhang

Re: New engine: Peacekeeper

Post by Sazgr »

dangi12012 wrote: Wed Oct 19, 2022 9:56 pm If you have #pragma once just declare as static in the header and delete this file:
https://github.com/Sazgr/peacekeeper/bl ... magics.cpp

This is also very small:
https://github.com/Sazgr/peacekeeper/bl ... typedefs.h

But its more of a personal preference. I strongly recommend having as little code noise as possible + KISS principle.
Thank you!
I made the magics array static and did delete magics.cpp, however I feel the typedefs file might be expanded in the future.
tcusr
Posts: 325
Joined: Tue Aug 31, 2021 10:32 pm
Full name: tcusr

Re: New engine: Peacekeeper

Post by tcusr »

Sazgr wrote: Thu Oct 20, 2022 8:15 pm
dangi12012 wrote: Wed Oct 19, 2022 9:56 pm If you have #pragma once just declare as static in the header and delete this file:
https://github.com/Sazgr/peacekeeper/bl ... magics.cpp

This is also very small:
https://github.com/Sazgr/peacekeeper/bl ... typedefs.h

But its more of a personal preference. I strongly recommend having as little code noise as possible + KISS principle.
Thank you!
I made the magics array static and did delete magics.cpp, however I feel the typedefs file might be expanded in the future.
since C++17 you can use inline to declare global variables. this way "lookup_table" will only be initialized once.
i also agree to switch to C++20 so that your code will contain no platform/compiler specific code.

P.S.
i suggest you to use constexpr as much as possible, it will let compiler optimize better and you'll get a noticeable speed up.
Sazgr
Posts: 66
Joined: Thu Dec 09, 2021 8:26 pm
Full name: Kyle Zhang

Re: New engine: Peacekeeper

Post by Sazgr »

tcusr wrote: Thu Oct 20, 2022 10:14 pm
Sazgr wrote: Thu Oct 20, 2022 8:15 pm
dangi12012 wrote: Wed Oct 19, 2022 9:56 pm If you have #pragma once just declare as static in the header and delete this file:
https://github.com/Sazgr/peacekeeper/bl ... magics.cpp

This is also very small:
https://github.com/Sazgr/peacekeeper/bl ... typedefs.h

But its more of a personal preference. I strongly recommend having as little code noise as possible + KISS principle.
Thank you!
I made the magics array static and did delete magics.cpp, however I feel the typedefs file might be expanded in the future.
since C++17 you can use inline to declare global variables. this way "lookup_table" will only be initialized once.
i also agree to switch to C++20 so that your code will contain no platform/compiler specific code.

P.S.
i suggest you to use constexpr as much as possible, it will let compiler optimize better and you'll get a noticeable speed up.
Sorry if I am being really dumb, but could you give an example of where to add cosntexpr? Thank you :D
tcusr
Posts: 325
Joined: Tue Aug 31, 2021 10:32 pm
Full name: tcusr

Re: New engine: Peacekeeper

Post by tcusr »

Sazgr wrote: Fri Oct 21, 2022 7:26 pm
tcusr wrote: Thu Oct 20, 2022 10:14 pm
Sazgr wrote: Thu Oct 20, 2022 8:15 pm
dangi12012 wrote: Wed Oct 19, 2022 9:56 pm If you have #pragma once just declare as static in the header and delete this file:
https://github.com/Sazgr/peacekeeper/bl ... magics.cpp

This is also very small:
https://github.com/Sazgr/peacekeeper/bl ... typedefs.h

But its more of a personal preference. I strongly recommend having as little code noise as possible + KISS principle.
Thank you!
I made the magics array static and did delete magics.cpp, however I feel the typedefs file might be expanded in the future.
since C++17 you can use inline to declare global variables. this way "lookup_table" will only be initialized once.
i also agree to switch to C++20 so that your code will contain no platform/compiler specific code.

P.S.
i suggest you to use constexpr as much as possible, it will let compiler optimize better and you'll get a noticeable speed up.
Sorry if I am being really dumb, but could you give an example of where to add cosntexpr? Thank you :D
anywhere as long as the compiler doesn't complain.
this includes const variables/arrays or any functions where it makes sense (this excludes the Hashtable class because it modifies data allocated during runtime).
Robert Pope
Posts: 563
Joined: Sat Mar 25, 2006 8:27 pm
Location: USA
Full name: Robert Pope

Re: New engine: Peacekeeper

Post by Robert Pope »

This inspired me to test the PESTO eval in my engine. PESTO was more than twice as fast - really slick use of an array of PSTs compared to how I do it. However, I'm guessing my cut and paste has some bugs, since it performed 300 elo worse than my eval.

Did you implement a static eval command in Peacekeeper? It would be handy to have an independent version to check against.
Sazgr
Posts: 66
Joined: Thu Dec 09, 2021 8:26 pm
Full name: Kyle Zhang

Re: New engine: Peacekeeper

Post by Sazgr »

Robert Pope wrote: Tue Oct 25, 2022 11:58 pm This inspired me to test the PESTO eval in my engine. PESTO was more than twice as fast - really slick use of an array of PSTs compared to how I do it. However, I'm guessing my cut and paste has some bugs, since it performed 300 elo worse than my eval.

Did you implement a static eval command in Peacekeeper? It would be handy to have an independent version to check against.
I just modified my eval command to be more informative, the eval command should print the middlegame and endgame PST values, the phase and the weighted PST value now.

example:

Code: Select all

position startpos moves e2e4
eval
which outputs

Code: Select all

middlegame pst: -32
endgame pst: -20
phase: 24
weighted pst: -32
StackFish5
Posts: 18
Joined: Fri Dec 24, 2021 5:48 pm
Full name: Andrew Zhuo

Re: New engine: Peacekeeper

Post by StackFish5 »

Congratulations on the new chess engine! Quite impressive.