Piece/square table challenge

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

Tom Likens
Posts: 303
Joined: Sat Apr 28, 2012 6:18 pm
Location: Austin, TX

Re: Piece/square table challenge

Post by Tom Likens »

Or you could use this:

Code: Select all

#include <stdio.h>
#include <stdlib.h>

#define FLIP_TB&#40;sq&#41; (&#40;sq&#41;^0x38&#41; // Flip top-to-bottom &#40;A8==A1, A7==A2 etc.)

#define NUMBER_OF_TBLS  12

// Contains the tables to flip.
#include "psqt.h"

int main&#40;void&#41; 
&#123;
    const int *ppsqt&#91;NUMBER_OF_TBLS&#93; = &#123;
        pstPawnMg,   pstPawnEg,   pstKnightMg, pstKnightEg,
        pstBishopMg, pstBishopEg, pstRookMg,   pstRookEg,
        pstQueenMg,  pstQueenEg,  pstKingMg,   pstKingEg
    &#125;;
    const char * const piece&#91;&#93; = &#123;
        "PawnMg",   "PawnEg",   "KnightMg", "KnightEg",
        "BishopMg", "BishopEg", "RookMg",   "RookEg",
        "QueenMg",  "QueenEg",  "KingMg",   "KingEg"
    &#125;;
    static int psqt&#91;NUMBER_OF_TBLS&#93;&#91;64&#93;;

    for &#40;int i=0; i < NUMBER_OF_TBLS; i++) &#123;
        printf&#40;"\nconst int pst%s&#91;64&#93; = \n&#123;", piece&#91;i&#93;);
        for &#40;int sq=0; sq < 64; sq++) &#123;
            psqt&#91;i&#93;&#91;sq&#93; = ppsqt&#91;i&#93;&#91; FLIP_TB&#40;sq&#41; &#93;;
            if (!&#40;sq % 8&#41;) printf&#40;"\n  ");
            printf&#40;"%3d", psqt&#91;i&#93;&#91;sq&#93;);
            if &#40;sq < 63&#41; printf&#40;", ");
        &#125;
        printf&#40;"\n&#125;;");
    &#125;
    printf&#40;"\n");

    return 0;
&#125;
The file "psqt.h" contains the tables you want to flip, top-to-bottom. When I ran it on Lucas' original entry it produced this:

Code: Select all

const int pstPawnMg&#91;64&#93; = 
&#123;
    0,   0,   0,   0,   0,   0,   0,   0, 
    0,   0,   0,   0,   0,   0,   0,   0, 
    0,   0,   0,   9,   9,   0,   0,   0, 
    0,   0,   0,  18,  18,   0,   0,   0, 
    0,   0,   0,   9,   9,   0,   0,   0, 
    0,   0,   0,   0,   0,   0,   0,   0, 
    0,   0,   0,   0,   0,   0,   0,   0, 
    0,   0,   0,   0,   0,   0,   0,   0
&#125;;
const int pstPawnEg&#91;64&#93; = 
&#123;
    0,   0,   0,   0,   0,   0,   0,   0, 
    0,   0,   0,   0,   0,   0,   0,   0, 
    0,   0,   0,   0,   0,   0,   0,   0, 
    0,   0,   0,   0,   0,   0,   0,   0, 
    0,   0,   0,   0,   0,   0,   0,   0, 
    0,   0,   0,   0,   0,   0,   0,   0, 
    0,   0,   0,   0,   0,   0,   0,   0, 
    0,   0,   0,   0,   0,   0,   0,   0
&#125;;
const int pstKnightMg&#91;64&#93; = 
&#123;
  -60, -40, -30, -20, -20, -30, -40, -60, 
  -40, -20, -10,   0,   0, -10, -20, -40, 
  -30, -10,   0,  10,  10,   0, -10, -30, 
  -20,   0,  10,  20,  20,  10,   0, -20, 
  -20,   0,  10,  20,  20,  10,   0, -20, 
  -30, -10,   0,  10,  10,   0, -10, -30, 
  -40, -20, -10,   0,   0, -10, -20, -40, 
  -60, -40, -30, -20, -20, -30, -40, -60
&#125;;
const int pstKnightEg&#91;64&#93; = 
&#123;
  -18, -12,  -9,  -6,  -6,  -9, -12, -18, 
  -12,  -6,  -3,   0,   0,  -3,  -6, -12, 
   -9,  -3,   0,   3,   3,   0,  -3,  -9, 
   -6,   0,   3,   6,   6,   3,   0,  -6, 
   -6,   0,   3,   6,   6,   3,   0,  -6, 
   -9,  -3,   0,   3,   3,   0,  -3,  -9, 
  -12,  -6,  -3,   0,   0,  -3,  -6, -12, 
  -18, -12,  -9,  -6,  -6,  -9, -12, -18
&#125;;
const int pstBishopMg&#91;64&#93; = 
&#123;
  -18, -18, -16, -14, -14, -16, -18, -18, 
   -8,   0,  -2,   0,   0,  -2,   0,  -8, 
   -6,  -2,   4,   2,   2,   4,  -2,  -6, 
   -4,   0,   2,   8,   8,   2,   0,  -4, 
   -4,   0,   2,   8,   8,   2,   0,  -4, 
   -6,  -2,   4,   2,   2,   4,  -2,  -6, 
   -8,   0,  -2,   0,   0,  -2,   0,  -8, 
   -8,  -8,  -6,  -4,  -4,  -6,  -8,  -8
&#125;;
const int pstBishopEg&#91;64&#93; = 
&#123;
  -18, -12,  -9,  -6,  -6,  -9, -12, -18, 
  -12,  -6,  -3,   0,   0,  -3,  -6, -12, 
   -9,  -3,   0,   3,   3,   0,  -3,  -9, 
   -6,   0,   3,   6,   6,   3,   0,  -6, 
   -6,   0,   3,   6,   6,   3,   0,  -6, 
   -9,  -3,   0,   3,   3,   0,  -3,  -9, 
  -12,  -6,  -3,   0,   0,  -3,  -6, -12, 
  -18, -12,  -9,  -6,  -6,  -9, -12, -18
&#125;;
const int pstRookMg&#91;64&#93; = 
&#123;
   -9,  -3,   0,   3,   3,   0,  -3,  -9, 
   -9,  -3,   0,   3,   3,   0,  -3,  -9, 
   -9,  -3,   0,   3,   3,   0,  -3,  -9, 
   -9,  -3,   0,   3,   3,   0,  -3,  -9, 
   -9,  -3,   0,   3,   3,   0,  -3,  -9, 
   -9,  -3,   0,   3,   3,   0,  -3,  -9, 
   -1,   5,   8,  11,  11,   8,   5,  -1, 
   -9,  -3,   0,   3,   3,   0,  -3,  -9
&#125;;
const int pstRookEg&#91;64&#93; = 
&#123;
    0,   0,   0,   0,   0,   0,   0,   0, 
    0,   0,   0,   0,   0,   0,   0,   0, 
    0,   0,   0,   0,   0,   0,   0,   0, 
    0,   0,   0,   0,   0,   0,   0,   0, 
    0,   0,   0,   0,   0,   0,   0,   0, 
    0,   0,   0,   0,   0,   0,   0,   0, 
    8,   8,   8,   8,   8,   8,   8,   8, 
    0,   0,   0,   0,   0,   0,   0,   0
&#125;;
const int pstQueenMg&#91;64&#93; = 
&#123;
   -5,  -5,  -5,  -5,  -5,  -5,  -5,  -5, 
    0,   0,   0,   0,   0,   0,   0,   0, 
    0,   0,   0,   0,   0,   0,   0,   0, 
    0,   0,   0,   0,   0,   0,   0,   0, 
    0,   0,   0,   0,   0,   0,   0,   0, 
    0,   0,   0,   0,   0,   0,   0,   0, 
    0,   0,   0,   0,   0,   0,   0,   0, 
    0,   0,   0,   0,   0,   0,   0,   0
&#125;;
const int pstQueenEg&#91;64&#93; = 
&#123;
  -24, -16, -12,  -8,  -8, -12, -16, -24, 
  -16,  -8,  -4,   0,   0,  -4,  -8, -16, 
  -12,  -4,   0,   4,   4,   0,  -4, -12, 
   -8,   0,   4,   8,   8,   4,   0,  -8, 
   -8,   0,   4,   8,   8,   4,   0,  -8, 
  -12,  -4,   0,   4,   4,   0,  -4, -12, 
  -16,  -8,  -4,   0,   0,  -4,  -8, -16, 
  -24, -16, -12,  -8,  -8, -12, -16, -24
&#125;;
const int pstKingMg&#91;64&#93; = 
&#123;
   37,  47,  27,   7,   7,  27,  47,  37, 
   30,  40,  20,   0,   0,  20,  40,  30, 
   16,  26,   6, -14, -14,   6,  26,  16, 
    9,  19,  -1, -21, -21,  -1,  19,   9, 
    2,  12,  -8, -28, -28,  -8,  12,   2, 
   -5,   5, -15, -35, -35, -15,   5,  -5, 
  -12,  -2, -22, -42, -42, -22,  -2, -12, 
  -19,  -9, -29, -49, -49, -29,  -9, -19
&#125;;
const int pstKingEg&#91;64&#93; = 
&#123;
  -84, -56, -42, -28, -28, -42, -56, -84, 
  -56, -28, -14,   0,   0, -14, -28, -56, 
  -42, -14,   0,  14,  14,   0, -14, -42, 
  -28,   0,  14,  28,  28,  14,   0, -28, 
  -28,   0,  14,  28,  28,  14,   0, -28, 
  -42, -14,   0,  14,  14,   0, -14, -42, 
  -56, -28, -14,   0,   0, -14, -28, -56, 
  -84, -56, -42, -28, -28, -42, -56, -84
&#125;;
User avatar
velmarin
Posts: 1600
Joined: Mon Feb 21, 2011 9:48 am

Re: Piece/square table challenge

Post by velmarin »

Lyudmil Tsvetkov wrote:
Hi Jose.

Did you try my set?
What values did you use for the king table, as I filled only the 5 other tables? Also, that was supposed to match Stockfish piece values, 2.5 times bigger than normal. I can not imagine it could do bad, as it is closest in philosophy to Adam's set, which did best. On the other hand, sets that had just centralisation, did relatively bad.

Not that I care, but this is spreading rumour and misconceptions.

If psqt should be the basis of your engine, then start with something similar to Adam's or mine.
Values transformed by Adam:
http://www.talkchess.com/forum/viewtopi ... 271#552271
Note pawns on seventh rank

Code: Select all

#if 0
const int pstPawnMg&#91;64&#93; =
&#123;
	0,   0,   0,   0,   0,   0,   0,   0,
	-5,  -2,   4,   5,   5,   4,  -2,  -5,
	-4,  -2,   5,   7,   7,   5,  -2,  -4,
	-2,  -1,   9,  13,  13,   9,  -1,  -2,
	2,   4,  13,  21,  21,  13,   4,   2,
	10,  21,  25,  29,  29,  25,  21,  10,
	1,   2,   5,   9,   9,   5,   2,   1,             // Pawns 7 Rank
	0,   0,   0,   0,   0,   0,   0,   0
&#125;;

const int pstPawnEg&#91;64&#93; =
&#123;
	0,   0,   0,   0,   0,   0,   0,   0,
	-3,  -1,   2,   3,   3,   2,  -1,  -3,
	-2,  -1,   3,   4,   4,   3,  -1,  -2,
	-1,   0,   4,   7,   7,   4,   0,  -1,
	1,   2,   7,  11,  11,   7,   2,   1,
	5,  11,  13,  14,  14,  13,  11,   5,
	0,   1,   3,   5,   5,   3,   1,   0,    // Pawns 7 Rank
	0,   0,   0,   0,   0,   0,   0,   0
&#125;;

const int pstKnightMg&#91;64&#93; =
&#123;
	-31, -23, -20, -16, -16, -20, -23, -31,
	-23, -16, -12,  -8,  -8, -12, -16, -23,
	-8,  -4,   0,   8,   8,   0,  -4,  -8,
	-4,   8,  12,  16,  16,  12,   8,  -4,
	8,  16,  20,  23,  23,  20,  16,   8,
	23,  27,  31,  35,  35,  31,  27,  23,
	4,   8,  12,  16,  16,  12,   8,   4,
	4,   4,   4,   4,   4,   4,   4,   4,
&#125;;

const int pstKnightEg&#91;64&#93; =
&#123;
	-39, -27, -23, -20, -20, -23, -27, -39,
	-27, -20, -12,  -8,  -8, -12, -20, -27,
	-8,  -4,   0,   8,   8,   0,  -4,  -8,
	-4,   8,  12,  16,  16,  12,   8,  -4,
	8,  16,  20,  23,  23,  20,  16,   8,
	12,  23,  27,  31,  31,  27,  23,  12,
	-2,   2,   4,   8,   8,   4,   2,  -2,
	-16,  -8,  -4,  -4,  -4,  -4,  -8, -16,
&#125;;

const int pstBishopMg&#91;64&#93; =  
&#123;
	-31, -23, -20, -16, -16, -20, -23, -31,
	-23, -16, -12,  -8,  -8, -12, -16, -23,
	-8,  -4,   0,   8,   8,   0,  -4,  -8,
	-4,   8,  12,  16,  16,  12,   8,  -4,
	8,  16,  20,  23,  23,  20,  16,   8,
	23,  27,  31,  35,  35,  31,  27,  23,
	4,   8,  12,  16,  16,  12,   8,   4,
	4,   4,   4,   4,   4,   4,   4,   4,
&#125;;

const int pstBishopEg&#91;64&#93; =  
&#123;
	-39, -27, -23, -20, -20, -23, -27, -39,
	-27, -20, -12,  -8,  -8, -12, -20, -27,
	-8,  -4,   0,   8,   8,   0,  -4,  -8,
	-4,   8,  12,  16,  16,  12,   8,  -4,
	8,  16,  20,  23,  23,  20,  16,   8,
	12,  23,  27,  31,  31,  27,  23,  12,
	-2,   2,   4,   8,   8,   4,   2,  -2,
	-16,  -8,  -4,  -4,  -4,  -4,  -8, -16,
&#125;;

const int pstRookMg&#91;64&#93; =
&#123;
	-10,  -8,  -6,  -4,  -4,  -6,  -8, -10,
	-8,  -6,  -4,  -2,  -2,  -4,  -6,  -8,
	-4,  -2,   0,   4,   4,   0,  -2,  -4,
	-2,   2,   4,   8,   8,   4,   2,  -2,
	2,   4,   8,  12,  12,   8,   4,   2,
	4,   8,   12, 16,  16,  12,   8,   4,
	20,  21,   23, 23,  23,  23,  21,  20,
	18,  18,   20, 20,  20,  20,  18,  18,
&#125;;

const int pstRookEg&#91;64&#93; =
&#123;
	-10,  -8,  -6,  -4,  -4,  -6,  -8, -10,
	-8,  -6,  -4,  -2,  -2,  -4,  -6,  -8,
	-4,  -2,   0,   4,   4,   0,  -2,  -4,
	-2,   2,   4,   8,   8,   4,   2,  -2,
	2,   4,   8,  12,  12,   8,   4,   2,
	4,   8,  12,  16,  16,  12,   8,   4,
	20,  21,  23,  23,  23,  23,  21,  20,
	18,  18,  20,  20,  20,  20,  18,  18,
&#125;;

const int pstQueenMg&#91;64&#93; =
&#123;
	-23, -20, -16, -12, -12, -16, -20, -23,
	-18, -14, -12,  -8,  -8, -12, -14, -18,
	-16,  -8,   0,   8,   8,   0,  -8, -16,
	-8,   0,  12,  16,  16,  12,   0,  -8,
	4,  12,  16,  23,  23,  16,  12,   4,
	16,  23,  27,  31,  31,  27,  23,  16,
	4,  12,  16,  23,  23,  16,  12,   4,
	2,   8,  12,  12,  12,  12,   8,   2,
&#125;;

const int pstQueenEg&#91;64&#93; =
&#123;
	-23, -20, -16, -12, -12, -16, -20, -23,
	-18, -14, -12,  -8,  -8, -12, -14, -18,
	-16,  -8,   0,   8,   8,   0,  -8, -16,
	-8,   0,  12,  16,  16,  12,   0,  -8,
	4,  12,  16,  23,  23,  16,  12,   4,
	16,  23,  27,  31,  31,  27,  23,  16,
	4,  12,  16,  23,  23,  16,  12,   4,
	2,   8,  12,  12,  12,  12,   8,   2,
&#125;;

const int pstKingMg&#91;64&#93; = 
&#123; 
	40,  50,  30,  10,  10,  30,  50,  40,
	30,  40,  20,   0,   0,  20,  40,  30,
	10,  20,   0, -20, -20,   0,  20,  10,
	0,  10, -10, -30, -30, -10,  10,   0,
	-10,   0, -20, -40, -40, -20,   0, -10,
	-20, -10, -30, -50, -50, -30, -10, -20,
	-30, -20, -40, -60, -60, -40, -20, -30,
	-40, -30, -50, -70, -70, -50, -30, -40 ,
&#125;; 

const int pstKingEg&#91;64&#93; = 
&#123; 
	-34, -30, -28, -27, -27, -28, -30, -34,
	-17, -13, -11, -10, -10, -11, -13, -17,
	-2,   2,   4,   5,   5,   4,   2,  -2,
	11,  15,  17,  18,  18,  17,  15,  11,
	22,  26,  28,  29,  29,  28,  26,  22,
	31,  34,  37,  38,  38,  37,  34,  31,
	38,  41,  44,  45,  45,  44,  41,  38,
	42,  46,  48,  50,  50,  48,  46,  42,
&#125;;
#endif
Harald
Posts: 318
Joined: Thu Mar 09, 2006 1:07 am

Re: Piece/square table challenge

Post by Harald »

Hi

Did you (anybody) ever think of two kinds of piece square tables, one for
move ordering and one for evaluation?
The one for move ordering may includes some asymmetry and is a little bit speculative,
and the one for evaluation is more restricted because the other evaluation
terms do the rest.
And if you did what was the result?

Harald
Lyudmil Tsvetkov
Posts: 6052
Joined: Tue Jun 12, 2012 12:41 pm

Re: Piece/square table challenge

Post by Lyudmil Tsvetkov »

velmarin wrote:
Lyudmil Tsvetkov wrote:
Hi Jose.

Did you try my set?
What values did you use for the king table, as I filled only the 5 other tables? Also, that was supposed to match Stockfish piece values, 2.5 times bigger than normal. I can not imagine it could do bad, as it is closest in philosophy to Adam's set, which did best. On the other hand, sets that had just centralisation, did relatively bad.

Not that I care, but this is spreading rumour and misconceptions.

If psqt should be the basis of your engine, then start with something similar to Adam's or mine.
Values transformed by Adam:
http://www.talkchess.com/forum/viewtopi ... 271#552271
Note pawns on seventh rank

Code: Select all

#if 0
const int pstPawnMg&#91;64&#93; =
&#123;
	0,   0,   0,   0,   0,   0,   0,   0,
	-5,  -2,   4,   5,   5,   4,  -2,  -5,
	-4,  -2,   5,   7,   7,   5,  -2,  -4,
	-2,  -1,   9,  13,  13,   9,  -1,  -2,
	2,   4,  13,  21,  21,  13,   4,   2,
	10,  21,  25,  29,  29,  25,  21,  10,
	1,   2,   5,   9,   9,   5,   2,   1,             // Pawns 7 Rank
	0,   0,   0,   0,   0,   0,   0,   0
&#125;;

const int pstPawnEg&#91;64&#93; =
&#123;
	0,   0,   0,   0,   0,   0,   0,   0,
	-3,  -1,   2,   3,   3,   2,  -1,  -3,
	-2,  -1,   3,   4,   4,   3,  -1,  -2,
	-1,   0,   4,   7,   7,   4,   0,  -1,
	1,   2,   7,  11,  11,   7,   2,   1,
	5,  11,  13,  14,  14,  13,  11,   5,
	0,   1,   3,   5,   5,   3,   1,   0,    // Pawns 7 Rank
	0,   0,   0,   0,   0,   0,   0,   0
&#125;;

const int pstKnightMg&#91;64&#93; =
&#123;
	-31, -23, -20, -16, -16, -20, -23, -31,
	-23, -16, -12,  -8,  -8, -12, -16, -23,
	-8,  -4,   0,   8,   8,   0,  -4,  -8,
	-4,   8,  12,  16,  16,  12,   8,  -4,
	8,  16,  20,  23,  23,  20,  16,   8,
	23,  27,  31,  35,  35,  31,  27,  23,
	4,   8,  12,  16,  16,  12,   8,   4,
	4,   4,   4,   4,   4,   4,   4,   4,
&#125;;

const int pstKnightEg&#91;64&#93; =
&#123;
	-39, -27, -23, -20, -20, -23, -27, -39,
	-27, -20, -12,  -8,  -8, -12, -20, -27,
	-8,  -4,   0,   8,   8,   0,  -4,  -8,
	-4,   8,  12,  16,  16,  12,   8,  -4,
	8,  16,  20,  23,  23,  20,  16,   8,
	12,  23,  27,  31,  31,  27,  23,  12,
	-2,   2,   4,   8,   8,   4,   2,  -2,
	-16,  -8,  -4,  -4,  -4,  -4,  -8, -16,
&#125;;

const int pstBishopMg&#91;64&#93; =  
&#123;
	-31, -23, -20, -16, -16, -20, -23, -31,
	-23, -16, -12,  -8,  -8, -12, -16, -23,
	-8,  -4,   0,   8,   8,   0,  -4,  -8,
	-4,   8,  12,  16,  16,  12,   8,  -4,
	8,  16,  20,  23,  23,  20,  16,   8,
	23,  27,  31,  35,  35,  31,  27,  23,
	4,   8,  12,  16,  16,  12,   8,   4,
	4,   4,   4,   4,   4,   4,   4,   4,
&#125;;

const int pstBishopEg&#91;64&#93; =  
&#123;
	-39, -27, -23, -20, -20, -23, -27, -39,
	-27, -20, -12,  -8,  -8, -12, -20, -27,
	-8,  -4,   0,   8,   8,   0,  -4,  -8,
	-4,   8,  12,  16,  16,  12,   8,  -4,
	8,  16,  20,  23,  23,  20,  16,   8,
	12,  23,  27,  31,  31,  27,  23,  12,
	-2,   2,   4,   8,   8,   4,   2,  -2,
	-16,  -8,  -4,  -4,  -4,  -4,  -8, -16,
&#125;;

const int pstRookMg&#91;64&#93; =
&#123;
	-10,  -8,  -6,  -4,  -4,  -6,  -8, -10,
	-8,  -6,  -4,  -2,  -2,  -4,  -6,  -8,
	-4,  -2,   0,   4,   4,   0,  -2,  -4,
	-2,   2,   4,   8,   8,   4,   2,  -2,
	2,   4,   8,  12,  12,   8,   4,   2,
	4,   8,   12, 16,  16,  12,   8,   4,
	20,  21,   23, 23,  23,  23,  21,  20,
	18,  18,   20, 20,  20,  20,  18,  18,
&#125;;

const int pstRookEg&#91;64&#93; =
&#123;
	-10,  -8,  -6,  -4,  -4,  -6,  -8, -10,
	-8,  -6,  -4,  -2,  -2,  -4,  -6,  -8,
	-4,  -2,   0,   4,   4,   0,  -2,  -4,
	-2,   2,   4,   8,   8,   4,   2,  -2,
	2,   4,   8,  12,  12,   8,   4,   2,
	4,   8,  12,  16,  16,  12,   8,   4,
	20,  21,  23,  23,  23,  23,  21,  20,
	18,  18,  20,  20,  20,  20,  18,  18,
&#125;;

const int pstQueenMg&#91;64&#93; =
&#123;
	-23, -20, -16, -12, -12, -16, -20, -23,
	-18, -14, -12,  -8,  -8, -12, -14, -18,
	-16,  -8,   0,   8,   8,   0,  -8, -16,
	-8,   0,  12,  16,  16,  12,   0,  -8,
	4,  12,  16,  23,  23,  16,  12,   4,
	16,  23,  27,  31,  31,  27,  23,  16,
	4,  12,  16,  23,  23,  16,  12,   4,
	2,   8,  12,  12,  12,  12,   8,   2,
&#125;;

const int pstQueenEg&#91;64&#93; =
&#123;
	-23, -20, -16, -12, -12, -16, -20, -23,
	-18, -14, -12,  -8,  -8, -12, -14, -18,
	-16,  -8,   0,   8,   8,   0,  -8, -16,
	-8,   0,  12,  16,  16,  12,   0,  -8,
	4,  12,  16,  23,  23,  16,  12,   4,
	16,  23,  27,  31,  31,  27,  23,  16,
	4,  12,  16,  23,  23,  16,  12,   4,
	2,   8,  12,  12,  12,  12,   8,   2,
&#125;;

const int pstKingMg&#91;64&#93; = 
&#123; 
	40,  50,  30,  10,  10,  30,  50,  40,
	30,  40,  20,   0,   0,  20,  40,  30,
	10,  20,   0, -20, -20,   0,  20,  10,
	0,  10, -10, -30, -30, -10,  10,   0,
	-10,   0, -20, -40, -40, -20,   0, -10,
	-20, -10, -30, -50, -50, -30, -10, -20,
	-30, -20, -40, -60, -60, -40, -20, -30,
	-40, -30, -50, -70, -70, -50, -30, -40 ,
&#125;; 

const int pstKingEg&#91;64&#93; = 
&#123; 
	-34, -30, -28, -27, -27, -28, -30, -34,
	-17, -13, -11, -10, -10, -11, -13, -17,
	-2,   2,   4,   5,   5,   4,   2,  -2,
	11,  15,  17,  18,  18,  17,  15,  11,
	22,  26,  28,  29,  29,  28,  26,  22,
	31,  34,  37,  38,  38,  37,  34,  31,
	38,  41,  44,  45,  45,  44,  41,  38,
	42,  46,  48,  50,  50,  48,  46,  42,
&#125;;
#endif
Thanks again to Adam.

So how did my values perform?

Those values were supposed to work in an engine that knows about passers, knows about king attacks, knows about storming pawns. Of course, you could do it either way, have psqt with only centralisation and add space separately, but I thought space present in the basic psqt was the most natural way to do it. You can do it either way, nothing wrong with it.

If you decide however that you include only psqt, then you can add many more details to make such tables optimal, for example:

- score sapce on the king side 30% higher, that could account for storming pawns, but also knights attacking the shelter
- score knights within the rectangle of squares c8-c4-h4-h8 30% higher, as those knights, excluding the knight on c4, all attack squares of the short-castled king: Nc5 and Nd4 attack e6, Nh4 attacks g6, etc.
- score 40% higher bishops on the diagonals where they attack the short-castled king: a2-g8, b1-h7, a3-f8, b2-h8, c1-h6, h4-d8, h3-c8
- score rooks on the e,f,g and h files 30% higher, as they attack there the enemy king shelter
- score queen on the king side 50% higher, as this is a very important location from where it attacks the enemy king, but also score higher queen on one of the diagonals where the bishops attack the shelter
- of course, and you are very right here, if there is no passers knowledge, score pawns on the 7th double pawns on the 6th, and pawns on the 8th double pawns on the 7th (would this engine know how to queen?)

I suppose, if all those elements are added, those table will beat everything, but you still need some other elements like mobility for the engine to play a good game. I suppose a perfect psqt, including centralisation, space, king attacks, storming pawns knowledge, passers knowledge would be able to reach the 2600-2700 elo level, if the engine also has a relatively good mobility.
Uri Blass
Posts: 10297
Joined: Thu Mar 09, 2006 12:37 am
Location: Tel-Aviv Israel

Re: Piece/square table challenge

Post by Uri Blass »

lucasart wrote:
Now here is an example where I would never break rank-wise symmetry: pawn endgame symmetry. The whole idea of increasing PST with rank is basically to compensate for a deficient passed/candidate/space evaluation. Best to leave a zero PST and re-tune the aforementionned eval features instead.
You can say the same about every piece square table so you do not need piece square tables because the all idea of every piece square table is to compensate for a deficient mobility/trapped piece code.

If you are not against PST in general then I do not see a reason to ask for rank-wise symmetry.
Uri Blass
Posts: 10297
Joined: Thu Mar 09, 2006 12:37 am
Location: Tel-Aviv Israel

Re: Piece/square table challenge

Post by Uri Blass »

Lyudmil Tsvetkov wrote:
velmarin wrote:
Lyudmil Tsvetkov wrote:
Hi Jose.

Did you try my set?
What values did you use for the king table, as I filled only the 5 other tables? Also, that was supposed to match Stockfish piece values, 2.5 times bigger than normal. I can not imagine it could do bad, as it is closest in philosophy to Adam's set, which did best. On the other hand, sets that had just centralisation, did relatively bad.

Not that I care, but this is spreading rumour and misconceptions.

If psqt should be the basis of your engine, then start with something similar to Adam's or mine.
Values transformed by Adam:
http://www.talkchess.com/forum/viewtopi ... 271#552271
Note pawns on seventh rank

Code: Select all

#if 0
const int pstPawnMg&#91;64&#93; =
&#123;
	0,   0,   0,   0,   0,   0,   0,   0,
	-5,  -2,   4,   5,   5,   4,  -2,  -5,
	-4,  -2,   5,   7,   7,   5,  -2,  -4,
	-2,  -1,   9,  13,  13,   9,  -1,  -2,
	2,   4,  13,  21,  21,  13,   4,   2,
	10,  21,  25,  29,  29,  25,  21,  10,
	1,   2,   5,   9,   9,   5,   2,   1,             // Pawns 7 Rank
	0,   0,   0,   0,   0,   0,   0,   0
&#125;;

const int pstPawnEg&#91;64&#93; =
&#123;
	0,   0,   0,   0,   0,   0,   0,   0,
	-3,  -1,   2,   3,   3,   2,  -1,  -3,
	-2,  -1,   3,   4,   4,   3,  -1,  -2,
	-1,   0,   4,   7,   7,   4,   0,  -1,
	1,   2,   7,  11,  11,   7,   2,   1,
	5,  11,  13,  14,  14,  13,  11,   5,
	0,   1,   3,   5,   5,   3,   1,   0,    // Pawns 7 Rank
	0,   0,   0,   0,   0,   0,   0,   0
&#125;;

const int pstKnightMg&#91;64&#93; =
&#123;
	-31, -23, -20, -16, -16, -20, -23, -31,
	-23, -16, -12,  -8,  -8, -12, -16, -23,
	-8,  -4,   0,   8,   8,   0,  -4,  -8,
	-4,   8,  12,  16,  16,  12,   8,  -4,
	8,  16,  20,  23,  23,  20,  16,   8,
	23,  27,  31,  35,  35,  31,  27,  23,
	4,   8,  12,  16,  16,  12,   8,   4,
	4,   4,   4,   4,   4,   4,   4,   4,
&#125;;

const int pstKnightEg&#91;64&#93; =
&#123;
	-39, -27, -23, -20, -20, -23, -27, -39,
	-27, -20, -12,  -8,  -8, -12, -20, -27,
	-8,  -4,   0,   8,   8,   0,  -4,  -8,
	-4,   8,  12,  16,  16,  12,   8,  -4,
	8,  16,  20,  23,  23,  20,  16,   8,
	12,  23,  27,  31,  31,  27,  23,  12,
	-2,   2,   4,   8,   8,   4,   2,  -2,
	-16,  -8,  -4,  -4,  -4,  -4,  -8, -16,
&#125;;

const int pstBishopMg&#91;64&#93; =  
&#123;
	-31, -23, -20, -16, -16, -20, -23, -31,
	-23, -16, -12,  -8,  -8, -12, -16, -23,
	-8,  -4,   0,   8,   8,   0,  -4,  -8,
	-4,   8,  12,  16,  16,  12,   8,  -4,
	8,  16,  20,  23,  23,  20,  16,   8,
	23,  27,  31,  35,  35,  31,  27,  23,
	4,   8,  12,  16,  16,  12,   8,   4,
	4,   4,   4,   4,   4,   4,   4,   4,
&#125;;

const int pstBishopEg&#91;64&#93; =  
&#123;
	-39, -27, -23, -20, -20, -23, -27, -39,
	-27, -20, -12,  -8,  -8, -12, -20, -27,
	-8,  -4,   0,   8,   8,   0,  -4,  -8,
	-4,   8,  12,  16,  16,  12,   8,  -4,
	8,  16,  20,  23,  23,  20,  16,   8,
	12,  23,  27,  31,  31,  27,  23,  12,
	-2,   2,   4,   8,   8,   4,   2,  -2,
	-16,  -8,  -4,  -4,  -4,  -4,  -8, -16,
&#125;;

const int pstRookMg&#91;64&#93; =
&#123;
	-10,  -8,  -6,  -4,  -4,  -6,  -8, -10,
	-8,  -6,  -4,  -2,  -2,  -4,  -6,  -8,
	-4,  -2,   0,   4,   4,   0,  -2,  -4,
	-2,   2,   4,   8,   8,   4,   2,  -2,
	2,   4,   8,  12,  12,   8,   4,   2,
	4,   8,   12, 16,  16,  12,   8,   4,
	20,  21,   23, 23,  23,  23,  21,  20,
	18,  18,   20, 20,  20,  20,  18,  18,
&#125;;

const int pstRookEg&#91;64&#93; =
&#123;
	-10,  -8,  -6,  -4,  -4,  -6,  -8, -10,
	-8,  -6,  -4,  -2,  -2,  -4,  -6,  -8,
	-4,  -2,   0,   4,   4,   0,  -2,  -4,
	-2,   2,   4,   8,   8,   4,   2,  -2,
	2,   4,   8,  12,  12,   8,   4,   2,
	4,   8,  12,  16,  16,  12,   8,   4,
	20,  21,  23,  23,  23,  23,  21,  20,
	18,  18,  20,  20,  20,  20,  18,  18,
&#125;;

const int pstQueenMg&#91;64&#93; =
&#123;
	-23, -20, -16, -12, -12, -16, -20, -23,
	-18, -14, -12,  -8,  -8, -12, -14, -18,
	-16,  -8,   0,   8,   8,   0,  -8, -16,
	-8,   0,  12,  16,  16,  12,   0,  -8,
	4,  12,  16,  23,  23,  16,  12,   4,
	16,  23,  27,  31,  31,  27,  23,  16,
	4,  12,  16,  23,  23,  16,  12,   4,
	2,   8,  12,  12,  12,  12,   8,   2,
&#125;;

const int pstQueenEg&#91;64&#93; =
&#123;
	-23, -20, -16, -12, -12, -16, -20, -23,
	-18, -14, -12,  -8,  -8, -12, -14, -18,
	-16,  -8,   0,   8,   8,   0,  -8, -16,
	-8,   0,  12,  16,  16,  12,   0,  -8,
	4,  12,  16,  23,  23,  16,  12,   4,
	16,  23,  27,  31,  31,  27,  23,  16,
	4,  12,  16,  23,  23,  16,  12,   4,
	2,   8,  12,  12,  12,  12,   8,   2,
&#125;;

const int pstKingMg&#91;64&#93; = 
&#123; 
	40,  50,  30,  10,  10,  30,  50,  40,
	30,  40,  20,   0,   0,  20,  40,  30,
	10,  20,   0, -20, -20,   0,  20,  10,
	0,  10, -10, -30, -30, -10,  10,   0,
	-10,   0, -20, -40, -40, -20,   0, -10,
	-20, -10, -30, -50, -50, -30, -10, -20,
	-30, -20, -40, -60, -60, -40, -20, -30,
	-40, -30, -50, -70, -70, -50, -30, -40 ,
&#125;; 

const int pstKingEg&#91;64&#93; = 
&#123; 
	-34, -30, -28, -27, -27, -28, -30, -34,
	-17, -13, -11, -10, -10, -11, -13, -17,
	-2,   2,   4,   5,   5,   4,   2,  -2,
	11,  15,  17,  18,  18,  17,  15,  11,
	22,  26,  28,  29,  29,  28,  26,  22,
	31,  34,  37,  38,  38,  37,  34,  31,
	38,  41,  44,  45,  45,  44,  41,  38,
	42,  46,  48,  50,  50,  48,  46,  42,
&#125;;
#endif
Thanks again to Adam.

So how did my values perform?

Those values were supposed to work in an engine that knows about passers, knows about king attacks, knows about storming pawns. Of course, you could do it either way, have psqt with only centralisation and add space separately, but I thought space present in the basic psqt was the most natural way to do it. You can do it either way, nothing wrong with it.

If you decide however that you include only psqt, then you can add many more details to make such tables optimal, for example:

- score sapce on the king side 30% higher, that could account for storming pawns, but also knights attacking the shelter
- score knights within the rectangle of squares c8-c4-h4-h8 30% higher, as those knights, excluding the knight on c4, all attack squares of the short-castled king: Nc5 and Nd4 attack e6, Nh4 attacks g6, etc.
- score 40% higher bishops on the diagonals where they attack the short-castled king: a2-g8, b1-h7, a3-f8, b2-h8, c1-h6, h4-d8, h3-c8
- score rooks on the e,f,g and h files 30% higher, as they attack there the enemy king shelter
- score queen on the king side 50% higher, as this is a very important location from where it attacks the enemy king, but also score higher queen on one of the diagonals where the bishops attack the shelter
- of course, and you are very right here, if there is no passers knowledge, score pawns on the 7th double pawns on the 6th, and pawns on the 8th double pawns on the 7th (would this engine know how to queen?)

I suppose, if all those elements are added, those table will beat everything, but you still need some other elements like mobility for the engine to play a good game. I suppose a perfect psqt, including centralisation, space, king attacks, storming pawns knowledge, passers knowledge would be able to reach the 2600-2700 elo level, if the engine also has a relatively good mobility.
I think that if we talk about reasonable evaluation then there there are many reasonable evaluations so there is no need to discuss about optimal piece square table because for every reasonable evaluation the optimal piece square table is different.

I also think that in order to reach 2600-2700 elo level you only need to search deep enough.

I believe that piece square table with no more knowledge
together with a good search can already do it today and I will not be surprised if a special version of stockfish that include only the optimal piece square table get 2600-2700 CCRL rating or even higher than that.

Stockfish is already above 3200 in the CCRL rating list and it may be interesting to test a special version that include only piece square table to measure the elo points that stockfish earns from the fact that it has a more complex evaluation(of course you should use something that is close to be optimal piece square table and not the existing piece square table).
User avatar
velmarin
Posts: 1600
Joined: Mon Feb 21, 2011 9:48 am

Re: Piece/square table challenge

Post by velmarin »

Lyudmil Tsvetkov wrote:
If you decide however that you include only psqt, then you can add many more details to make such tables optimal, for example:
The challenge is simply that.
The value of the pieces and,
the PST, the 12 arrays, neither more nor less, just get it the best performance.
So I understand.
Of course there are many things to evaluate, are other discussions that.
Pio
Posts: 334
Joined: Sat Feb 25, 2012 10:42 pm
Location: Stockholm

Re: Piece/square table challenge

Post by Pio »

PK wrote:First results are:

Code: Select all

 
    Program                          Elo    +   -   Games   Score   Av.Op.  Draws
  1 Adam Hair                      &#58; 2079   14  14  2034    62.9 %   1988   17.7 %
  2 Pawel Koziol                    &#58; 2056   13  13  2068    58.9 %   1993   24.0 %
  3 Tomasz Michniewski / CPW       &#58; 2000   13  13  2016    49.0 %   2007   25.5 %
  4 Lucas Braesch                  &#58; 1962   13  13  2026    42.1 %   2017   24.7 %
  5 Mikko Aarnos &#40;MY ERROR&#41;       &#58; 1932   14  14  2036    36.9 %   2025   22.0 %
Unfortunately I'll have to replay all games of Mikko's entry, as I made a typo with queen value. But this will come tomorrow.
Hi Pawel!

I hope I am not too late.

Here are my tables (without a doubt the worst ones).

I took a wild gambling putting -110 for the bishops at the usual place for a pawn trap so it is not a typo. Thanks for running this!

/Pio

#define PAWN_VAL 100
#define KNIGHT_VAL 305
#define BISHOP_VAL 330
#define ROOK_VAL 510
#define QUEEN_VAL 900

const int pstPawnMg[64] =
{
//A1 H1
0, 0, 0, 0, 0, 0, 0, 0
-15, 5, 5, -5, -5, 5, 5,-15
-25,-10,-10,-10,-10,-10,-10,-25
-30,-10, -5, 0, 0, -5,-10,-30
-25, -5, 0, 0, 0, 0, -5,-25
-10, 0, 0, 0, 0, 0, 0,-10
40, 60, 60, 60, 60, 60, 60, 40
0, 0, 0, 0, 0, 0, 0, 0
//A8 H8
};

const int pstPawnEg[64] =
{
0, 0, 0, 0, 0, 0, 0, 0
20, 35, 35, 35, 35, 20, 35, 20
15, 30, 30, 30, 30, 30, 30, 15
15, 30, 30, 30, 30, 30, 30, 15
15, 30, 30, 30, 30, 30, 30, 15
25, 40, 40, 40, 40, 40, 40, 25
75,100,100,100,100,100,100, 75
0, 0, 0, 0, 0, 0, 0, 0
};

const int pstKnightMg[64] =
{
-75,-20,-15,-15,-15,-15,-20,-75
-20,-10, 0, 0, 0, 0,-10,-20
-15, 0, 10, 10, 10, 10, 0,-15
-15, 0, 10, 10, 10, 10, 0,-15
-15, 0, 10, 10, 10, 10, 0,-15
-15, 0, 10, 10, 10, 10, 0,-15
-20,-10, 0, 0, 0, 0,-10,-20
-75,-20,-15,-15,-15,-15,-20,-75
};

const int pstKnightEg[64] =
{
-75,-20,-15,-15,-15,-15,-20,-75
-20,-10, 0, 0, 0, 0,-10,-20
-15, 0, 10, 10, 10, 10, 0,-15
-15, 0, 10, 10, 10, 10, 0,-15
-15, 0, 10, 10, 10, 10, 0,-15
-15, 0, 10, 10, 10, 10, 0,-15
-20,-10, 0, 0, 0, 0,-10,-20
-75,-40,-30,-30,-30,-30,-40,-75
};

const int pstBishopMg[64] =
{
-5, -5,-10,-15,-15,-10, -5, -5
0, 10, 5, 0, 0, 5, 10, 0
-10, 0, 0, 0, 0, 0, 0, -10
-10, 0, 0, 5, 5, 0, 0, -10
-10, 5, 5, 5, 5, 5, 5, -10
-10, 0, 5, 5, 5, 5, 0, -10
-110, 0, 0, 0, 0, 0, 0,-110
-25,-10,-10,-10,-10,-10,-10, -25
};

const int pstBishopEg[64] =
{
-20, 5, 5, 5, 5, 5, 5,-20
5, 5, 5, 5, 5, 5, 5, 5
5, 5, 5, 5, 5, 5, 5, 5
5, 5, 5, 5, 5, 5, 5, 5
5, 5, 5, 5, 5, 5, 5, 5
5, 5, 5, 5, 5, 5, 5, 5
5, 5, 5, 5, 5, 5, 5, 5
5, 5, 5, 5, 5, 5, 5, 5
};

const int pstRookMg[64] =
{
0, 0, 5, 5, 5, 5, 0, 0
0, 0, 0, 0, 0, 0, 0, 0
0, 0, 0, 0, 0, 0, 0, 0
0, 0, 0, 0, 0, 0, 0, 0
0, 0, 0, 0, 0, 0, 0, 0
0, 0, 0, 0, 0, 0, 0, 0
10, 10, 10, 10, 10, 10, 10, 10
0, 0, 0, 0, 0, 0, 0, 0
};

const int pstRookEg[64] =
{
0, 0, 0, 0, 0, 0, 0, 0
0, 0, 0, 0, 0, 0, 0, 0
0, 0, 0, 0, 0, 0, 0, 0
0, 0, 0, 0, 0, 0, 0, 0
0, 0, 0, 0, 0, 0, 0, 0
0, 0, 0, 0, 0, 0, 0, 0
5, 5, 5, 5, 5, 5, 5, 5
0, 0, 0, 0, 0, 0, 0, 0
};

const int pstQueenMg[64] =
{
0, 0, 0, 0, 0, 0, 0, 0
0, 0, 0, 0, 0, 0, 0, 0
0, 0, 0, 0, 0, 0, 0, 0
0, 0, 0, 0, 0, 0, 0, 0
0, 0, 0, 0, 0, 0, 0, 0
0, 0, 0, 0, 0, 0, 0, 0
5, 5, 5, 5, 5, 5, 5, 5
0, 0, 0, 0, 0, 0, 0, 0
};

const int pstQueenEg[64] =
{
0, 5, 5, 5, 5, 5, 5, 0
5, 5, 5, 5, 5, 5, 5, 5
5, 5, 5, 5, 5, 5, 5, 5
5, 5, 5, 5, 5, 5, 5, 5
5, 5, 5, 5, 5, 5, 5, 5
5, 5, 5, 5, 5, 5, 5, 5
5, 5, 5, 5, 5, 5, 5, 5
0, 5, 5, 5, 5, 5, 5, 0
};

const int pstKingMg[64] =
{
-15, 0,-20,-10,-10,-20, 0,-15
-20,-20,-20,-20,-20,-20,-20,-20
-40,-40,-40,-40,-40,-40,-40,-40
-40,-40,-40,-40,-40,-40,-40,-40
-40,-40,-40,-40,-40,-40,-40,-40
-40,-40,-40,-40,-40,-40,-40,-40
-40,-40,-40,-40,-40,-40,-40,-40
-40,-40,-40,-40,-40,-40,-40,-40
};

const int pstKingEg[64] =
{
0, 10, 15, 15, 15, 15, 10, 0
10, 20, 25, 25, 25, 25, 20, 10
15, 25, 30, 35, 35, 30, 25, 15
15, 25, 35, 40, 40, 35, 25, 15
15, 25, 35, 40, 40, 35, 25, 15
15, 25, 30, 35, 35, 30, 25, 15
10, 20, 25, 25, 25, 25, 20, 10
0, 10, 15, 15, 15, 15, 10, 0
};
Lyudmil Tsvetkov
Posts: 6052
Joined: Tue Jun 12, 2012 12:41 pm

Re: Piece/square table challenge

Post by Lyudmil Tsvetkov »

velmarin wrote:
Lyudmil Tsvetkov wrote:
If you decide however that you include only psqt, then you can add many more details to make such tables optimal, for example:
The challenge is simply that.
The value of the pieces and,
the PST, the 12 arrays, neither more nor less, just get it the best performance.
So I understand.
Of course there are many things to evaluate, are other discussions that.
It is possible to do that, but it is very much artificial and based on guesswork. You guess that the kings will usually castle long and weigh the table accordingly. What if they castle short or stay in the center? This could be much effort for nothing. For example, I decide to do a table like Adam's, with weighed in kingside attacks besides space, what if Adam or someone else supplies then her own new table version where in the king table the king gets huge penalty for landing on g1 and huge bonus for landing on b1. The king will castle all the way long and my table suddenly goes busted. That is why this is an artificial approach.

Btw., I could give my new version of the king table with huge penalty for g1 and huge bonus for b1 in the middlegame, match it against Adam's version and enjoy the results. :D
Uri Blass
Posts: 10297
Joined: Thu Mar 09, 2006 12:37 am
Location: Tel-Aviv Israel

Re: Piece/square table challenge

Post by Uri Blass »

Lyudmil Tsvetkov wrote:
velmarin wrote:
Lyudmil Tsvetkov wrote:
If you decide however that you include only psqt, then you can add many more details to make such tables optimal, for example:
The challenge is simply that.
The value of the pieces and,
the PST, the 12 arrays, neither more nor less, just get it the best performance.
So I understand.
Of course there are many things to evaluate, are other discussions that.
It is possible to do that, but it is very much artificial and based on guesswork. You guess that the kings will usually castle long and weigh the table accordingly. What if they castle short or stay in the center? This could be much effort for nothing. For example, I decide to do a table like Adam's, with weighed in kingside attacks besides space, what if Adam or someone else supplies then her own new table version where in the king table the king gets huge penalty for landing on g1 and huge bonus for landing on b1. The king will castle all the way long and my table suddenly goes busted. That is why this is an artificial approach.

Btw., I could give my new version of the king table with huge penalty for g1 and huge bonus for b1 in the middlegame, match it against Adam's version and enjoy the results. :D
I do not see a reason why do you think castling is going to score better than short castling.

I prefer symmetric tables by file.
It is possible to do every table as symmetric by replacing 2 numbers by their average.

I also think that the value of the pieces should not be 1,3,3,5,9 but something like 1,3.2,3.3,4.8,9 to prevent trading of bishop and knight by a rook and a pawn that is a bad deal.

I wonder if modification of adam's table to be symmetric is not going to score better even without changes in piece values.