Progress On Bricabrac

Discussion of chess software programming and technical issues.

Moderators: hgm, chrisw, Rebel

Mike Sherwin
Posts: 925
Joined: Fri Aug 21, 2020 1:25 am
Location: Planet Earth, Sol system
Full name: Michael J Sherwin

Re: Progress On Bricabrac

Post by Mike Sherwin »

I was finally able to do a little work on Bricabrac today. A few months ago I lost a few hundred elo in my own ability to play chess. I blame the jab. I just simply don't see what I used to be able to see. And my speed chess ability is in the crapper. Today, I replaced Bric's eval from scratch with this simple one that is after the style of RomiChess.

Code: Select all

for (sq = A1; sq <= H8; sq++) {

    col = sq & 7;
    wrow = sq >> 3;
    brow = 7 - wrow;
    cenCol = col < 4 ? col : 7 - col;
    cenRow = wrow < 4 ? wrow : 7 - wrow;

    // white pawns
    if (sq > H1 && sq < A8) {
      if (wrow == 1) wpPST[sq] = 12;
      else wpPST[sq] = cenCol * cenCol + wrow * wrow;
      wpPST[sq] += ply * wrow / 32;
    }


    // black pawns
    if (sq < A8 && sq > H1) {
      if (brow == 1) bpPST[sq] = 12;
      else bpPST[sq] = cenCol * cenCol + brow * brow;
      bpPST[sq] += ply * brow / 32;
    }

    // knights
    moves = knightMoves[sq] & ~allPieces;

    // white knights
    captures = knightMoves[sq] & (bRooks | bQueens | king[BLACK]);
    wnPST[sq] = __popcnt64(moves) * 4 + __popcnt64(captures) * 16;
    wnPST[sq] += (cenRow + cenRow) * (cenCol + cenCol);

    // black knights
    captures = knightMoves[sq] & (wRooks | wQueens | king[WHITE]);
    bnPST[sq] = __popcnt64(moves) + __popcnt64(captures) * 16;
    bnPST[sq] += (cenRow + cenRow) * (cenCol + cenCol);

    // bishops
    blocks.bb = allPieces & b7e[sq];
    blocks.bb = ((blocks.l32 >> 8) | blocks.h32);
    moves = bss[sq][blocks.r1][0]
          & bss[sq][blocks.r2][1]
          & bss[sq][blocks.r3][2];

    // white bishops
    captures = moves & (bRooks | bQueens | king[BLACK]);
    moves ^= captures;
    wbPST[sq] = __popcnt64(moves) * 4 + __popcnt64(captures) * 16;
    wbPST[sq] += (cenRow * cenCol) + wrow;

    // black bishops
    captures = moves & (wRooks | wQueens | king[WHITE]);
    moves ^= captures;
    bbPST[sq] = __popcnt64(moves) * 4 + __popcnt64(captures) * 16;
    bbPST[sq] += (cenRow * cenCol) + brow;

    // rooks
    blocks.bb = allPieces & rob[sq];
    moves = qss[sq][(blocks.bb >> (sq & 56)) & 127][0]
      & qss[sq][blocks.r2][1]
      & qss[sq][blocks.r3][2]
      & qss[sq][blocks.r4][3]
      & qss[sq][blocks.r5][4]
      & qss[sq][blocks.r6][5]
      & qss[sq][blocks.r7][6]
      & rob[sq];

    // white rooks
    captures = moves & (bQueens | king[BLACK]);
    moves ^= captures;
    wrPST[sq] = __popcnt64(moves) * 2 + __popcnt64(captures) * 16;
    wrPST[sq] += cenRow + wrow == 6 * 20;

    // black rooks
    captures = moves & (wQueens | king[WHITE]);
    moves ^= captures;
    brPST[sq] = __popcnt64(moves) * 2 + __popcnt64(captures) * 16;
    brPST[sq] += cenRow + brow == 6 * 20;

    // queens
    blocks.bb = allPieces & rob[sq];
    moves = qss[sq][(blocks.bb >> (sq & 56)) & 127][0]
      & qss[sq][blocks.r2][1]
      & qss[sq][blocks.r3][2]
      & qss[sq][blocks.r4][3]
      & qss[sq][blocks.r5][4]
      & qss[sq][blocks.r6][5]
      & qss[sq][blocks.r7][6];

    // white queens
    captures = moves & king[BLACK];
    moves ^= captures;
    wqPST[sq] = __popcnt64(moves) + __popcnt64(captures) * 16;
//    wqPST[sq] += (cenRow * cenCol) + wrow;

    //black queens
    captures = moves & king[WHITE];
    moves ^= captures;
    bqPST[sq] = __popcnt64(moves) + __popcnt64(captures) * 16;
//    bqPST[sq] += (cenRow * cenCol) + brow;

    // white king
    sum = (2200 - mat[BLACK]) >> 6;
    wkPST[sq] = (cenCol + cenRow) * sum;

    // black king
    sum = (2200 - mat[WHITE]) >> 6;
    bkPST[sq] = (cenCol + cenRow) * sum;
  }

  // white pawn specifics
  wpPST[E2] -= (board[E1] == WC) * 20;
  wpPST[E4] += (board[E1] == WC) * 20;

  // black pawn specifics
  bpPST[E7] -= (board[E8] == BC) * 20;
  bpPST[E5] += (board[E8] == BC) * 20;

  // white king specifics
  wkPST[G1] += (board[E1] == WC) * 40;

  // black king specifics
  bkPST[G8] += (board[E8] == BC) * 40;
Then I played a number of 2 min + 6 sec inc games against Bric and lost every game. :(

Here is my best game.

[pgn][Event "Computer chess game"]
[Site "DESKTOP-HFVHK2B"]
[Date "2021.10.23"]
[Round "?"]
[White "mjshe"]
[Black "Bricabrac"]
[Result "0-1"]
[BlackElo "2200"]
[ECO "D07"]
[Opening "QGD"]
[Time "23:48:18"]
[Variation "Chigorin, 3.Nf3"]
[WhiteElo "2400"]
[TimeControl "120+6"]
[Termination "normal"]
[PlyCount "96"]
[WhiteType "human"]
[BlackType "program"]

1. d4 d5 {(d7d5 e2e3 c8d7 f1d3 e7e6 c1d2 g8f6 d1f3 b8c6) -0.35/9 29} 2. c4
Nc6 {(b8c6 e2e3 e7e5 d4e5 f8b4 c1d2 b4d2 d1d2) +0.06/8 23} 3. Nf3 e6 {(e7e6
e2e3 g8f6 f1d3 d5c4 d3c4 f8b4 e1f1) -0.01/8 19} 4. e3 Nf6 {(g8f6 c4c5 f6e4
f1b5 e8e7 b1d2 e7f6 d2e4) -0.16/8 16} 5. Nc3 Bb4 {(f8b4 f1d3 f6e4 c1d2 e4d2
e1d2 d5c4) -0.22/7 13} 6. Bd2 Bxc3 {(b4c3 d2c3 f6e4 d1d3 e4c3 d3c3 e8g8)
-0.26/7 11} 7. Bxc3 Ne4 {(f6e4 a1c1 e4c3 c1c3 c6b4 d1a4 b4c6) -0.46/7 10}
8. Qc2 Nxc3 {(e4c3 c2c3 g7g5 c4d5 e6d5 f1b5 d8f6) -0.32/7 9} 9. Qxc3 g5
{(g7g5 h2h3 d8f6 c4c5 e8g8 f1d3 g8g7) -0.53/7 8} 10. cxd5 exd5 {(e6d5 h2h3
c8f5 f1b5 f5d7 b5d3 e8g8) -0.55/7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.30/9 5} 44. Rd2 Bb1 {(f5b1 e1d3 b1a2 d3c5 a2c4 e2f2 e7d6 d2c2
d6c7) +0.35/9 5} 45. Nd3 Ba2 {(b1a2 d2b2 a2c4 b2d2 f6f5 f3f4 g5f4 e3f4
c4d3) +0.16/9 6} 46. Nc5 Bc4+ {(a2c4 e2f2 f6f5 e3e4 f5f4 e4e5 e7f7 e5e6
f7f6) +0.26/9 5} 47. Kf2 Ra1 {(a3a1 e3e4 a1f1 f2e3 f1e1 e3f2 e1f1 f2e3
d5e4) +0.30/9 5} 48. Rb2 Rf1# {(a1f1 e3e4) +M1/9 6} 0-1
[/pgn]
At least I did not loose on time!

I hope I can now start making progress again on Bricabrac.
tcusr
Posts: 325
Joined: Tue Aug 31, 2021 10:32 pm
Full name: Mateo

Re: Progress On Bricabrac

Post by tcusr »

hi mike, do you host your code somewhere?
User avatar
mvanthoor
Posts: 1784
Joined: Wed Jul 03, 2019 4:42 pm
Location: Netherlands
Full name: Marcel Vanthoor

Re: Progress On Bricabrac

Post by mvanthoor »

Mike Sherwin wrote: Sun Oct 24, 2021 8:43 am I was finally able to do a little work on Bricabrac today.
...
I hope I can now start making progress again on Bricabrac.
Congratulations on the progress :) I look forward to seeing the engine in one of the rating lists :)
Author of Rustic, an engine written in Rust.
Releases | Code | Docs | Progress | CCRL
Mike Sherwin
Posts: 925
Joined: Fri Aug 21, 2020 1:25 am
Location: Planet Earth, Sol system
Full name: Michael J Sherwin

Re: Progress On Bricabrac

Post by Mike Sherwin »

tcusr wrote: Mon Oct 25, 2021 8:12 pm hi mike, do you host your code somewhere?
cpp file
https://www.mediafire.com/file/5b00xvnx ... c.cpp/file

MSVS 2019 full folder including the exe
https://www.mediafire.com/file/02gda4iu ... ac.7z/file
Mike Sherwin
Posts: 925
Joined: Fri Aug 21, 2020 1:25 am
Location: Planet Earth, Sol system
Full name: Michael J Sherwin

Re: Progress On Bricabrac

Post by Mike Sherwin »

mvanthoor wrote: Mon Oct 25, 2021 9:19 pm
Mike Sherwin wrote: Sun Oct 24, 2021 8:43 am I was finally able to do a little work on Bricabrac today.
...
I hope I can now start making progress again on Bricabrac.
Congratulations on the progress :) I look forward to seeing the engine in one of the rating lists :)
Thanks! I seem to have found a little gem of an engine, Sam, that only has static PST's except the kings PSTs are adjusted by game phase. And it is performing at TSCP 1.81 + 252 elo. And it's PST's are created algorithmically like I did above. Except mine is TSCP 1.81 - 330 elo. :lol: Now I have to find out why Sam's PSTs are as good or better than PESTO?
? ?

Code: Select all

// A small chess program by Jonathan Kreuzer
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>

const int HASH_SIZE = 400000;
const int INVALID=32, IV=32, EMPTY=0, WHITE=8, BLACK=16, WH=8, BL=16, PAWN=0, KNIG=1, BISH=2, ROOK=3, QUEE=4, KING=5;
const int TIME = 300000;
const int B_QS = 4, B_KS = 8, W_QS = 1, W_KS = 2;
const int N_dirs[8] = {-21, -19, -12, -8, 8, 12, 19, 21};
const int K_dirs[8] = {1, 9, 10, 11, -1, -9, -10, -11};
const int Q_dirs[8] = {1, -1, 9, -9, -10, 10, -11, 11};
const int R_dirs[4] = {1, -1,  -10, 10};
const int B_dirs[4] = {9, -9, -11, 11};
const int P_dirs[8] = {-10, -20, -9, -11, 10, 20, 9, 11};
int inline SRC   ( int Move ) {return (Move&127);}
int inline DST   ( int Move ) {return ((Move>>7)&127);}
int inline PROMO ( int Move ) {return ((Move>>14)&3);}
int inline VALUE ( int Move ) {return ((Move>>16)&16383);}
int inline SWITCH ( int Color ){return Color^(WHITE|BLACK);}
int inline File ( int Sq ) {return (Sq-20)%10;}
int inline Rank ( int Sq ) {return (Sq-10)/10;}
int inline SQ ( int file, int rank) {return 21+file+rank*10;}
int EvalSq [ 26 * 128 ];
int SetCastle[120];
const unsigned char StartBoard[120] = { IV, IV, IV, IV, IV, IV, IV, IV, IV, IV, IV, IV, IV, IV, IV, IV, IV, IV, IV, IV,
        IV, ROOK|BL, KNIG|BL, BISH|BL, QUEE|BL, KING|BL, BISH|BL, KNIG|BL, ROOK|BL, IV,
        IV, PAWN|BL, PAWN|BL, PAWN|BL, PAWN|BL, PAWN|BL, PAWN|BL, PAWN|BL, PAWN|BL, IV,
        IV, 0, 0, 0, 0, 0, 0, 0, 0, IV, IV, 0, 0, 0, 0, 0, 0, 0, 0, IV, IV, 0, 0, 0, 0, 0, 0, 0, 0, IV, IV, 0, 0, 0, 0, 0, 0, 0, 0, IV,
        IV, PAWN|WH, PAWN|WH, PAWN|WH, PAWN|WH, PAWN|WH, PAWN|WH, PAWN|WH, PAWN|WH, IV,
        IV, ROOK|WH, KNIG|WH, BISH|WH, QUEE|WH, KING|WH, BISH|WH, KNIG|WH, ROOK|WH, IV, IV, IV, IV, IV, IV, IV, IV, IV, IV, IV, IV, IV, IV, IV, IV, IV, IV, IV, IV, IV };
const int PieceValues[8]    = { 100, 328, 330, 522, 952, 5000 };
const int MPieceValues[8]   = {  00, 328, 330, 522, 952,   00 };
const int KingEval[10] = { 0, 8, 12, 5, 0, 0, 5, 14, 9, 0};
const int CentEval[10] = { 0,-6, -3, -1, 0, 0, -1, -3, -6, 0};
const int Cent[10]         = { 0, 1, 2, 2, 3, 3, 2, 1, 1, 0};
void SendThinking ( int move, int Depth, int Eval, __int64 Nodes, int bFinished );

struct SBoard 
        {
        unsigned char m_Sqs[120];
        int stm, Eval, EPsq, Castling, WKsq, BKsq, WMat, BMat, nMoves, nLastCapOrPawn;

        void Init()     {
                int sq, pc;
                for (sq = 0; sq < 120; sq++) m_Sqs[sq] = StartBoard [ sq ];
                Eval = 0; nMoves = 0;
                Castling = 0;
                stm = WHITE;
                WKsq = 95; BKsq = 25;
                BMat = WMat = 2*PieceValues[BISH]+2*PieceValues[KNIG]+2*PieceValues[ROOK]+PieceValues[QUEE];
                for (sq = 0; sq < 120; sq++) SetCastle[sq] = 0;
                SetCastle[21] = B_QS; SetCastle[28] = B_KS; SetCastle[25] = B_QS|B_KS; SetCastle[91] = W_QS; SetCastle[98] = W_KS; SetCastle[95] = W_QS|W_KS;
                // Evaluation is incremental and uses the piece square table in EvalSq arrays.
                for (pc = 0; pc < 8; pc++)
                        for (sq = 0; sq < 120; sq++) {
                                EvalSq[ ((pc|WHITE)<<7)+sq ] = PieceValues[pc];
                                EvalSq[ ((pc|BLACK)<<7)+sq ] = -PieceValues[pc];
                                if (pc == PAWN) 
                                        {EvalSq[ ((pc|WHITE)<<7)+sq ] += (9-Rank(sq)) * Cent[File(sq)];
                                         EvalSq[ ((pc|BLACK)<<7)+sq ] -=   Rank(sq)   * Cent[File(sq)];}
                                else if (pc == KING) {}
                                else{if (pc!=ROOK && Rank(sq)==8) EvalSq[ ((pc|WHITE)<<7)+sq ] -= 8;
                                         if (pc!=ROOK && Rank(sq)==1) EvalSq[ ((pc|BLACK)<<7)+sq ] += 8;
                                         EvalSq[ ((pc|WHITE)<<7)+sq ] += CentEval[ File(sq) ];
                                         EvalSq[ ((pc|BLACK)<<7)+sq ] -= CentEval[ File(sq) ];
                                        }
                        EvalSq[ (0<<7)+sq ] = (Rank(sq)-9)*2 + KingEval[File(sq)]; // King Values depend on stage
                        EvalSq[ (1<<7)+sq ] = (Rank(sq))*2 - KingEval[File(sq)];
                        EvalSq[ (2<<7)+sq ] = 2*CentEval[ File(sq) ];
                        EvalSq[ (3<<7)+sq ] = -2*CentEval[ File(sq) ];
                        }
                }
Mike Sherwin
Posts: 925
Joined: Fri Aug 21, 2020 1:25 am
Location: Planet Earth, Sol system
Full name: Michael J Sherwin

Re: Progress On Bricabrac

Post by Mike Sherwin »

Bric got all the perft test, at the CPW, position 2 to position 5 correct to the maximum depths given. :D
User avatar
mvanthoor
Posts: 1784
Joined: Wed Jul 03, 2019 4:42 pm
Location: Netherlands
Full name: Marcel Vanthoor

Re: Progress On Bricabrac

Post by mvanthoor »

Mike Sherwin wrote: Wed Nov 03, 2021 3:29 pm Bric got all the perft test, at the CPW, position 2 to position 5 correct to the maximum depths given. :D
Congratulations :) Maybe I should write an update as well, after about 5 months...
Author of Rustic, an engine written in Rust.
Releases | Code | Docs | Progress | CCRL
Mike Sherwin
Posts: 925
Joined: Fri Aug 21, 2020 1:25 am
Location: Planet Earth, Sol system
Full name: Michael J Sherwin

Re: Progress On Bricabrac

Post by Mike Sherwin »

After my last post I've been under the weather. About two weeks ago I came down with shingles. That was a painful two weeks. Still is but at least I was able to start on the hash tables today. For starters it is only 1 million entries and the only thing added so far is beta cutoffs. No move ordering yet is done. Anyway in the original position to finish 15 ply before the HT it took 26.54 seconds. After the HT was added it took only 14.52 seconds. Also I'm experimenting with 128 bits of signature. Still it managed 10,167,093 n/s on a R9 3950x @ 4.2 GHz on a single thread. A short day but a productive day! :D
Mike Sherwin
Posts: 925
Joined: Fri Aug 21, 2020 1:25 am
Location: Planet Earth, Sol system
Full name: Michael J Sherwin

Re: Progress On Bricabrac

Post by Mike Sherwin »

Of course using PeSTO Bric was able to defeat TSCP easily even when Bric had many bugs. Today however Bric finally won a match against TSCP with all original code.

Bricabrac - Tscp181 : 52.5/100 49-44-7 (111011101111001010011001101100=01101111010=1110011010=1110=1010010010001101=1=0001100001101001000=10) 53% +21

It won because of search improvements. The evaluation is lucky to be 1400 elo.
Mike Sherwin
Posts: 925
Joined: Fri Aug 21, 2020 1:25 am
Location: Planet Earth, Sol system
Full name: Michael J Sherwin

Re: Progress On Bricabrac

Post by Mike Sherwin »

I was able to do a little bit of work yesterday. My immediate goal since PeSTO pst was replaced by algorithmically created pst was to surpass PeSTO. I'm almost there!

BricPESTO1 - Tscp181 : 59.0/100 49-31-20 (101=011=10011000=011=0001=01=110=111=1111100011101011==110=1==111001100100==0==111100011=01=110111=1) 59% +63

Bricabrac - Tscp181 : 57.5/100 47-32-21 (11=110100=10101011=1=1===011000=11=11000101110101=00101=01001111100=0=11101=00=0111=1=0==110101=11=1) 58% +56

Just to be clear, all Bric is doing now for an eval is algorithmically filling the pst before each search. While PeSTO is static and does not change.