Bitboard CHESS ENGINE in C: YouTube series by Code Monkey King

Discussion of anything and everything relating to chess playing software and machines.

Moderators: hgm, Rebel, chrisw

User avatar
mvanthoor
Posts: 1784
Joined: Wed Jul 03, 2019 4:42 pm
Location: Netherlands
Full name: Marcel Vanthoor

Re: Bitboard CHESS ENGINE in C: YouTube series by Code Monkey King

Post by mvanthoor »

maksimKorzh wrote: Thu Sep 24, 2020 5:08 pm It's not that easy. BBC searches 3-4 plies deeper in the opening and about twice deeper in the endgame)
So without at least evaluation pawns and some very basic king safety there are no much chances.
Well; it's clearly visible to me that BBC is tactically superior to TSCP, as it often snatches material using forcing moves. TSCP also sometimes captures pieces that it shouldn't, but its unable to see it. Both are caused by the fact that BBC is (much) faster than TSCP.
Author of Rustic, an engine written in Rust.
Releases | Code | Docs | Progress | CCRL
User avatar
maksimKorzh
Posts: 771
Joined: Sat Sep 08, 2018 5:37 pm
Location: Ukraine
Full name: Maksim Korzh

Re: Bitboard CHESS ENGINE in C: YouTube series by Code Monkey King

Post by maksimKorzh »

mvanthoor wrote: Thu Sep 24, 2020 7:19 pm
maksimKorzh wrote: Thu Sep 24, 2020 5:20 pm Marcel, you've made my day)))
OK, let's fix that in proper chess engine fashion:

Code: Select all

unmake(day)
There, back to normal again :) Back to testing my preliminary search function...

Oh, by the way: your statement that you need some sort of evaluation to beat TSCP is not true. PeSTO (Piece Square Tables Only), is a special version of Rofchade (by Roland), which reached about 2980 on CCRL without ANY evaluation apart from material counting and PSQT's... purely on speed and search functionality.
Are you kidding??? Than why my PST are so bad???
Can I please have a look at yours???
User avatar
maksimKorzh
Posts: 771
Joined: Sat Sep 08, 2018 5:37 pm
Location: Ukraine
Full name: Maksim Korzh

Re: Bitboard CHESS ENGINE in C: YouTube series by Code Monkey King

Post by maksimKorzh »

mvanthoor wrote: Thu Sep 24, 2020 7:24 pm
maksimKorzh wrote: Thu Sep 24, 2020 7:16 pm Tonight I'm running final tests and if everything works properly tomorrow the world would see BBC 1.0 release!
Congrats; are you actually going to call the engine "BBC" officially? I look forward to seeing it in rating lists and to play against it in the not too distant future. Preliminary estimation of +263 Elo over TSCP in hyperbullet... that'd put you somewhere around 1950 in the CCRL blitz list. Very respectable for a first version :) Mine is probably going to be weaker due to less functionality in version 1.
re: are you actually going to call the engine "BBC" officially?
- yes, I don't have much options for BBC's page exists on CPW since the start of development:
https://www.chessprogramming.org/BBC

re: all else
- hope so)
User avatar
mvanthoor
Posts: 1784
Joined: Wed Jul 03, 2019 4:42 pm
Location: Netherlands
Full name: Marcel Vanthoor

Re: Bitboard CHESS ENGINE in C: YouTube series by Code Monkey King

Post by mvanthoor »

maksimKorzh wrote: Thu Sep 24, 2020 7:44 pm Are you kidding??? Than why my PST are so bad???
Can I please have a look at yours???
Not kidding:
PeSTO on CCRL

Site: https://rofchade.nl/?p=307

I'm going to use some standard PSQT's for now, from this thread:
http://www.talkchess.com/forum3/viewtop ... =7&t=50840

(One of the earlier enhancements I'll be implementing is a tapered evaluation, and I'll probably tinker with the PSQT's afterward to make the engine play in a style I like.)

With regard to PeSTO, according to the author it has a very advanced search. I'm assuming that the engine is also lightning fast, and that the PSQT's will compensate for having no other evaluation options, because they have been automatically tuned. (Texel tuning: very advanced topic when your engine reaches the 3000+ stages or thereabouts... I don't know too much about it either at this point.)

PeSTO is a private engine, so there is no source code, but it is free to download to play against or use in tournaments.
Author of Rustic, an engine written in Rust.
Releases | Code | Docs | Progress | CCRL
User avatar
Ronald
Posts: 160
Joined: Tue Jan 23, 2018 10:18 am
Location: Rotterdam
Full name: Ronald Friederich

Re: Bitboard CHESS ENGINE in C: YouTube series by Code Monkey King

Post by Ronald »

Some time ago Minic used the rofChade 1.0 PST values, I believe I also used those values in PeSTO.

The PST can be found here: http://talkchess.com/forum3/viewtopic.p ... 15#p772515
User avatar
maksimKorzh
Posts: 771
Joined: Sat Sep 08, 2018 5:37 pm
Location: Ukraine
Full name: Maksim Korzh

Re: Bitboard CHESS ENGINE in C: YouTube series by Code Monkey King

Post by maksimKorzh »

Ronald wrote: Thu Sep 24, 2020 9:45 pm Some time ago Minic used the rofChade 1.0 PST values, I believe I also used those values in PeSTO.

The PST can be found here: http://talkchess.com/forum3/viewtopic.p ... 15#p772515
Thank you Ronald.
I'm very tempted to know how on earth is that possible that equal on search depth engines playing with the same strength when one of them has a better evaluation.
I love your idea though, this evaluation minimalism is very tempting.

The only question - do you manipulate PST during search? And if not than how your PST are different from others?

Thanks in advance!
User avatar
maksimKorzh
Posts: 771
Joined: Sat Sep 08, 2018 5:37 pm
Location: Ukraine
Full name: Maksim Korzh

Re: Bitboard CHESS ENGINE in C: YouTube series by Code Monkey King

Post by maksimKorzh »

Ronald wrote: Thu Sep 24, 2020 9:45 pm Some time ago Minic used the rofChade 1.0 PST values, I believe I also used those values in PeSTO.

The PST can be found here: http://talkchess.com/forum3/viewtopic.p ... 15#p772515
Hi Ronald!

I'm trying to use your PeSTO values (from the post link you sent me):

Code: Select all

const eval pieceValue[2][6] =
{ 82, 337, 365, 477, 1025, 12000,
  94, 281, 297, 512,  936, 12000 };

const eval GAMEPHASEMINEG = 518;
const eval GAMEPHASEMAXMG = 6192;
const eval GAMEPHASERANGE = GAMEPHASEMAXMG - GAMEPHASEMINEG;

// factorMG and factorEG are calculated based on the sum of the MG values
   of all the pieces except pawns (pos->gamePhase)

// a sum above GAMEPHASEMAXMG is fully MG, a sum below GAMEPHASEMINEG is fully EG,
   the rest is interpolated:

	//const eval gamePhase = std::max(GAMEPHASEMINEG, std::min(GAMEPHASEMAXMG, pos->gamePhase));			
	//const double factorMG = (gamePhase - GAMEPHASEMINEG) / GAMEPHASERANGE;	
	//const double factorEG = 1 - factorMG;

const sptScore pieceSquareScore[2][6][64] =
// MG values
{
//pawn
      0,   0,   0,   0,   0,   0,  0,   0,
     98, 134,  61,  95,  68, 126, 34, -11,
     -6,   7,  26,  31,  65,  56, 25, -20,
    -14,  13,   6,  21,  23,  12, 17, -23,
    -27,  -2,  -5,  12,  17,   6, 10, -25,
    -26,  -4,  -4, -10,   3,   3, 33, -12,
    -35,  -1, -20, -23, -15,  24, 38, -22,
      0,   0,   0,   0,   0,   0,  0,   0,
 //knight
    -167, -89, -34, -49,  61, -97, -15, -107,
     -73, -41,  72,  36,  23,  62,   7,  -17,
     -47,  60,  37,  65,  84, 129,  73,   44,
      -9,  17,  19,  53,  37,  69,  18,   22,
     -13,   4,  16,  13,  28,  19,  21,   -8,
     -23,  -9,  12,  10,  19,  17,  25,  -16,
     -29, -53, -12,  -3,  -1,  18, -14,  -19,
    -105, -21, -58, -33, -17, -28, -19,  -23,
 //bishop
    -29,   4, -82, -37, -25, -42,   7,  -8,
    -26,  16, -18, -13,  30,  59,  18, -47,
    -16,  37,  43,  40,  35,  50,  37,  -2,
     -4,   5,  19,  50,  37,  37,   7,  -2,
     -6,  13,  13,  26,  34,  12,  10,   4,
      0,  15,  15,  15,  14,  27,  18,  10,
      4,  15,  16,   0,   7,  21,  33,   1,
    -33,  -3, -14, -21, -13, -12, -39, -21,
 //rook
     32,  42,  32,  51, 63,  9,  31,  43,
     27,  32,  58,  62, 80, 67,  26,  44,
     -5,  19,  26,  36, 17, 45,  61,  16,
    -24, -11,   7,  26, 24, 35,  -8, -20,
    -36, -26, -12,  -1,  9, -7,   6, -23,
    -45, -25, -16, -17,  3,  0,  -5, -33,
    -44, -16, -20,  -9, -1, 11,  -6, -71,
    -19, -13,   1,  17, 16,  7, -37, -26,
 //queen
    -28,   0,  29,  12,  59,  44,  43,  45,
    -24, -39,  -5,   1, -16,  57,  28,  54,
    -13, -17,   7,   8,  29,  56,  47,  57,
    -27, -27, -16, -16,  -1,  17,  -2,   1,
     -9, -26,  -9, -10,  -2,  -4,   3,  -3,
    -14,   2, -11,  -2,  -5,   2,  14,   5,
    -35,  -8,  11,   2,   8,  15,  -3,   1,
     -1, -18,  -9,  10, -15, -25, -31, -50,
 //king
    -65,  23,  16, -15, -56, -34,   2,  13,
     29,  -1, -20,  -7,  -8,  -4, -38, -29,
     -9,  24,   2, -16, -20,   6,  22, -22,
    -17, -20, -12, -27, -30, -25, -14, -36,
    -49,  -1, -27, -39, -46, -44, -33, -51,
    -14, -14, -22, -46, -44, -30, -15, -27,
      1,   7,  -8, -64, -43, -16,   9,   8,
    -15,  36,  12, -54,   8, -28,  24,  14,
    
    // EG values
 
 //pawn
      0,   0,   0,   0,   0,   0,   0,   0,
    178, 173, 158, 134, 147, 132, 165, 187,
     94, 100,  85,  67,  56,  53,  82,  84,
     32,  24,  13,   5,  -2,   4,  17,  17,
     13,   9,  -3,  -7,  -7,  -8,   3,  -1,
      4,   7,  -6,   1,   0,  -5,  -1,  -8,
     13,   8,   8,  10,  13,   0,   2,  -7,
      0,   0,   0,   0,   0,   0,   0,   0,
//knight
    -58, -38, -13, -28, -31, -27, -63, -99,
    -25,  -8, -25,  -2,  -9, -25, -24, -52,
    -24, -20,  10,   9,  -1,  -9, -19, -41,
    -17,   3,  22,  22,  22,  11,   8, -18,
    -18,  -6,  16,  25,  16,  17,   4, -18,
    -23,  -3,  -1,  15,  10,  -3, -20, -22,
    -42, -20, -10,  -5,  -2, -20, -23, -44,
    -29, -51, -23, -15, -22, -18, -50, -64,
//bishop
    -14, -21, -11,  -8, -7,  -9, -17, -24,
     -8,  -4,   7, -12, -3, -13,  -4, -14,
      2,  -8,   0,  -1, -2,   6,   0,   4,
     -3,   9,  12,   9, 14,  10,   3,   2,
     -6,   3,  13,  19,  7,  10,  -3,  -9,
    -12,  -3,   8,  10, 13,   3,  -7, -15,
    -14, -18,  -7,  -1,  4,  -9, -15, -27,
    -23,  -9, -23,  -5, -9, -16,  -5, -17,
//rook
    13, 10, 18, 15, 12,  12,   8,   5,
    11, 13, 13, 11, -3,   3,   8,   3,
     7,  7,  7,  5,  4,  -3,  -5,  -3,
     4,  3, 13,  1,  2,   1,  -1,   2,
     3,  5,  8,  4, -5,  -6,  -8, -11,
    -4,  0, -5, -1, -7, -12,  -8, -16,
    -6, -6,  0,  2, -9,  -9, -11,  -3,
    -9,  2,  3, -1, -5, -13,   4, -20,
//queen
     -9,  22,  22,  27,  27,  19,  10,  20,
    -17,  20,  32,  41,  58,  25,  30,   0,
    -20,   6,   9,  49,  47,  35,  19,   9,
      3,  22,  24,  45,  57,  40,  57,  36,
    -18,  28,  19,  47,  31,  34,  39,  23,
    -16, -27,  15,   6,   9,  17,  10,   5,
    -22, -23, -30, -16, -16, -23, -36, -32,
    -33, -28, -22, -43,  -5, -32, -20, -41,
//king
    -74, -35, -18, -18, -11,  15,   4, -17,
    -12,  17,  14,  17,  17,  38,  23,  11,
     10,  17,  23,  15,  20,  45,  44,  13,
     -8,  22,  24,  27,  26,  33,  26,   3,
    -18,  -4,  21,  24,  27,  23,   9, -11,
    -19,  -3,  11,  21,  23,  16,   7,  -9,
    -27, -11,   4,  13,  14,   4,  -5, -17,
    -53, -34, -21, -11, -28, -14, -24, -43
};
I have issues in understanding of how exactly to calculate game phase.
Could you please explain it either in C (no C++ please!) or in pseudo code?
User avatar
Ronald
Posts: 160
Joined: Tue Jan 23, 2018 10:18 am
Location: Rotterdam
Full name: Ronald Friederich

Re: Bitboard CHESS ENGINE in C: YouTube series by Code Monkey King

Post by Ronald »

For each piece 2 PST are defined, 1 for the opening phase (MG) and 1 for the endgame phase(EG), because the "value" of a square can differ a lot in MG and EG, fi keep King behing pawns in the beginning, develop the King in the endgame. Depending on the phase of the game you interpolate the the MG and EG values, thus depending on how far you are in MG/EG. This is so called "tapered evaluation".

The phase of the game can be calculated in multiple ways, but is usually derived from the pieces (not counting pawns) that are still on the board. A Queen has a higher "MG" weight than Rooks etc. In PeSTO the phase is calculated with the MG material value as weight for the pieces. The max. phase (full MG) is : 4 * Knights +... + = 4* 337 + ... = 6.766, the minimum (full EG) is 0.

PeSTO's interpolation is not between 6.766 and 0, but between MAXMG 6192 and MINEG = 518, So a phase higher than 6192 uses full MG value, a phase lower than 518 already uses full EG value.

All values are calculated with my first/primitive Texel tuning implementation.
User avatar
maksimKorzh
Posts: 771
Joined: Sat Sep 08, 2018 5:37 pm
Location: Ukraine
Full name: Maksim Korzh

Re: Bitboard CHESS ENGINE in C: YouTube series by Code Monkey King

Post by maksimKorzh »

Ronald wrote: Fri Sep 25, 2020 11:33 pm For each piece 2 PST are defined, 1 for the opening phase (MG) and 1 for the endgame phase(EG), because the "value" of a square can differ a lot in MG and EG, fi keep King behing pawns in the beginning, develop the King in the endgame. Depending on the phase of the game you interpolate the the MG and EG values, thus depending on how far you are in MG/EG. This is so called "tapered evaluation".

The phase of the game can be calculated in multiple ways, but is usually derived from the pieces (not counting pawns) that are still on the board. A Queen has a higher "MG" weight than Rooks etc. In PeSTO the phase is calculated with the MG material value as weight for the pieces. The max. phase (full MG) is : 4 * Knights +... + = 4* 337 + ... = 6.766, the minimum (full EG) is 0.

PeSTO's interpolation is not between 6.766 and 0, but between MAXMG 6192 and MINEG = 518, So a phase higher than 6192 uses full MG value, a phase lower than 518 already uses full EG value.

All values are calculated with my first/primitive Texel tuning implementation.
OMG! Ronald you can't even imagine how grateful I am!
I just can't find enough words to thank you!

I LOVE your explanation - even a noob like can clearly get it!
I'm so tempted to implements this in my engine and play a match versus old version!

So I have to remove all pawn evaluation and mobility from the version using PST only for pure results right?
Harald
Posts: 318
Joined: Thu Mar 09, 2006 1:07 am

Re: Bitboard CHESS ENGINE in C: YouTube series by Code Monkey King

Post by Harald »

I dAn't know if you wish to have an evaluation with piece values and PST only or not. I may have missed a part of this thread. However here is my explanation of the tampered evaluation.

For (nearly) all evaluation terms you need two versions of bonusses or penalties. One for the midgame (MG) and one for the endgame (EG). You do not need two versions if the values are the same.

The game phase depends on piece material without pawns but for both players. You can count the pieces (Q, R, B, N, q, r, b, n) and sum them up with weights. The weights may be simple integers like (4, 3, 2, 2, 4, 3, 2, 2) or your normal material values like (1000, 500, 350, 300, 1000, 500, 350, 300). The maximum value of the sum is (36) or (6600) respecively in the opening and (0) in the pawn endgame. From now on I use the 6600 value in my example. Therefore the game phase is (float) piece_material_sum / 6600 between 1.0 and 0.0. In the engine you may want to use an integer value between 1000 and 0.

int game_phase = 1000 * piece_material_sum / 6600; // 1000 in opening/midgame slowly going to 0 in pawn endgame

All evaluation terms are detected once and then summed up in two eval values.

...
value_mg += piece_square_table_mg[K][sq]; // white king midgame
value_eg += piece_square_table_eg[K][sq]; // white king endgame
...
value_mg += num_white_rooks_on_open_files * rook_on_open_file_bonus_mg;
value_eg += num_white_rooks_on_open_files * rook_on_open_file_bonus_eg;
...

And finally at the end of evaluation() there is an interpolation

value = (value_mg * game_phase + value_eg * (1000 - game_phase)) / 1000; // interpolation midgame..endgame and reverse the scaling.

Then comes the normal side and +- score code and the score is returned.