Stockfish Code ( Piece Value's)

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

NJDenson
Posts: 75
Joined: Tue May 23, 2006 7:01 pm

Stockfish Code ( Piece Value's)

Post by NJDenson »

Does anyone know where in the code of stockfish you can change the piece values. I believe the values are not correct and want to tweak them and compile with new binary?

Thanks
Sven
Posts: 4052
Joined: Thu May 15, 2008 9:57 pm
Location: Berlin, Germany
Full name: Sven Schüle

Re: Stockfish Code ( Piece Value's)

Post by Sven »

NJDenson wrote:Does anyone know where in the code of stockfish you can change the piece values. I believe the values are not correct and want to tweak them and compile with new binary?
types.h (prior to SF2.1 in piece.h)

Code: Select all

/*
  Stockfish, a UCI chess playing engine derived from Glaurung 2.1
  Copyright (C) 2004-2008 Tord Romstad (Glaurung author)
  Copyright (C) 2008-2012 Marco Costalba, Joona Kiiski, Tord Romstad

  Stockfish is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.

  Stockfish is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http&#58;//www.gnu.org/licenses/>.
*/

// ...

const Value PawnValueMidgame   = Value&#40;0x0C6&#41;;
const Value PawnValueEndgame   = Value&#40;0x102&#41;;
const Value KnightValueMidgame = Value&#40;0x331&#41;;
const Value KnightValueEndgame = Value&#40;0x34E&#41;;
const Value BishopValueMidgame = Value&#40;0x344&#41;;
const Value BishopValueEndgame = Value&#40;0x359&#41;;
const Value RookValueMidgame   = Value&#40;0x4F6&#41;;
const Value RookValueEndgame   = Value&#40;0x4FE&#41;;
const Value QueenValueMidgame  = Value&#40;0x9D9&#41;;
const Value QueenValueEndgame  = Value&#40;0x9FE&#41;;
Sven
User avatar
Ajedrecista
Posts: 1968
Joined: Wed Jul 13, 2011 9:04 pm
Location: Madrid, Spain.

Re: StockFish code (piece values) in centipawns?

Post by Ajedrecista »

Hello:
Sven Schüle wrote:
NJDenson wrote:Does anyone know where in the code of stockfish you can change the piece values. I believe the values are not correct and want to tweak them and compile with new binary?
types.h (prior to SF2.1 in piece.h)

Code: Select all

/*
  Stockfish, a UCI chess playing engine derived from Glaurung 2.1
  Copyright &#40;C&#41; 2004-2008 Tord Romstad &#40;Glaurung author&#41;
  Copyright &#40;C&#41; 2008-2012 Marco Costalba, Joona Kiiski, Tord Romstad

  Stockfish is free software&#58; you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  &#40;at your option&#41; any later version.

  Stockfish is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http&#58;//www.gnu.org/licenses/>.
*/

// ...

const Value PawnValueMidgame   = Value&#40;0x0C6&#41;;
const Value PawnValueEndgame   = Value&#40;0x102&#41;;
const Value KnightValueMidgame = Value&#40;0x331&#41;;
const Value KnightValueEndgame = Value&#40;0x34E&#41;;
const Value BishopValueMidgame = Value&#40;0x344&#41;;
const Value BishopValueEndgame = Value&#40;0x359&#41;;
const Value RookValueMidgame   = Value&#40;0x4F6&#41;;
const Value RookValueEndgame   = Value&#40;0x4FE&#41;;
const Value QueenValueMidgame  = Value&#40;0x9D9&#41;;
const Value QueenValueEndgame  = Value&#40;0x9FE&#41;;
Sven
It is very interesting... what are these values in centipawns? Sorry for my lack of knowledge, but I do not know what they mean and even what they are (maybe magic numbers?). Please answer and thanks in advance.

Regards from Spain.

Ajedrecista.
Sven
Posts: 4052
Joined: Thu May 15, 2008 9:57 pm
Location: Berlin, Germany
Full name: Sven Schüle

Re: StockFish code (piece values) in centipawns?

Post by Sven »

Ajedrecista wrote:It is very interesting... what are these values in centipawns?
The values are based on a "pawn unit" being 0x100 (decimal 256), see below.

Code: Select all

mg			
			
piece hex   dec  cp
P     0x0c6  198 0,773
N     0x331  817 3,191
B     0x344  836 3,266
R     0x4f6 1270 4,961
Q     0x9d9 2521 9,848

eg			
			
piece hex   dec  cp
P     0x102  258 1,008
N     0x34e  846 3,305
B     0x359  857 3,348
R     0x4fe 1278 4,992
Q     0x9fe 2558 9,992
Sven
User avatar
Ajedrecista
Posts: 1968
Joined: Wed Jul 13, 2011 9:04 pm
Location: Madrid, Spain.

Thank you very much.

Post by Ajedrecista »

Hello Sven:
Sven Schüle wrote:
Ajedrecista wrote:It is very interesting... what are these values in centipawns?
The values are based on a "pawn unit" being 0x100 (decimal 256), see below.

Code: Select all

mg			
			
piece hex   dec  cp
P     0x0c6  198 0,773
N     0x331  817 3,191
B     0x344  836 3,266
R     0x4f6 1270 4,961
Q     0x9d9 2521 9,848

eg			
			
piece hex   dec  cp
P     0x102  258 1,008
N     0x34e  846 3,305
B     0x359  857 3,348
R     0x4fe 1278 4,992
Q     0x9fe 2558 9,992
Sven
Thanks for your fast answer. I tried hexadecimal (the appearance of the values claims for that) and I got these values (198, 817, ...) but I did not know about the standard 0x100 (256) pawn unit. I can understand it now!

Regards from Spain.

Ajedrecista.
Sven
Posts: 4052
Joined: Thu May 15, 2008 9:57 pm
Location: Berlin, Germany
Full name: Sven Schüle

Re: Thank you very much.

Post by Sven »

Ajedrecista wrote:
Sven Schüle wrote:
Ajedrecista wrote:It is very interesting... what are these values in centipawns?
The values are based on a "pawn unit" being 0x100 (decimal 256)
I tried hexadecimal (the appearance of the values claims for that) and I got these values (198, 817, ...) but I did not know about the standard 0x100 (256) pawn unit.
My tables wrongly use "cp" as column heading although the values are in pawns, not centipawns.

My claim 'are based on a "pawn unit" being 0x100' is of course debatable since only the endgame value of a pawn is close to 0x100. But at least it is clear that the original values have to be divided by 2.56 (or 256 as I did) to get those centipawn values the eyes of most of us are used to see.

Sven
NJDenson
Posts: 75
Joined: Tue May 23, 2006 7:01 pm

Re: Thank you very much.

Post by NJDenson »

Wow, I am still some what lost but here is won I found in code of SF 2.2.1

const Value PawnValueMidgame = Value(0x0C6);
const Value PawnValueEndgame = Value(0x102);
const Value KnightValueMidgame = Value(0x331);
const Value KnightValueEndgame = Value(0x34E);
const Value BishopValueMidgame = Value(0x344);
const Value BishopValueEndgame = Value(0x359);
const Value RookValueMidgame = Value(0x4F6);
const Value RookValueEndgame = Value(0x4FE);
const Value QueenValueMidgame = Value(0x9D9);
const Value QueenValueEndgame = Value(0x9FE);

I believe the values for mid game rook is too low and mid game queen:

Thanks all for info provide thus far.
NJDenson
Posts: 75
Joined: Tue May 23, 2006 7:01 pm

Re: Thank you very much. ( I got It)

Post by NJDenson »

New testing Values:

const Value PawnValueMidgame = Value(0x0C6);
const Value PawnValueEndgame = Value(0x102);
const Value KnightValueMidgame = Value(0x331);
const Value KnightValueEndgame = Value(0x34E);
const Value BishopValueMidgame = Value(0x344);
const Value BishopValueEndgame = Value(0x359);
const Value RookValueMidgame = Value(0x4FB);
const Value RookValueEndgame = Value(0x4FE);
const Value QueenValueMidgame = Value(0x9E7);
const Value QueenValueEndgame = Value(0x9FE);

Thanks Again All
UncombedCoconut
Posts: 319
Joined: Fri Dec 18, 2009 11:40 am
Location: Naperville, IL

Re: StockFish code (piece values) in centipawns?

Post by UncombedCoconut »

Sven Schüle wrote:
Ajedrecista wrote:It is very interesting... what are these values in centipawns?
The values are based on a "pawn unit" being 0x100 (decimal 256), see below.
If you wish to compare them to displayed scores, PawnValueMidgame = 100 cp. Also, if you run SF directly you can use the "eval" command to see a breakdown of eval factors. (The example below uses it on a real position; in practice, I think eval is more often used on silly positions that arise during search.)

Stockfish 120107 64bit SSE4.2 by Tord Romstad, Marco Costalba and Joona Kiiski
position fen r1bq1b1r/ppp3pp/4k3/3np3/1nB5/2N2Q2/PPPP1PPP/R1B1K2R w KQ - 4 9
eval

Code: Select all

           Eval term |    White    |    Black    |     Total     
                     |   MG    EG  |   MG    EG  |   MG     EG   
---------------------+-------------+-------------+---------------
Material, PST, Tempo |   ---   --- |   ---   --- |  -2.91  -3.15 
  Material imbalance |   ---   --- |   ---   --- |  -0.33  -0.33 
               Pawns |   ---   --- |   ---   --- |   0.40   0.20 
             Knights |  0.00  0.00 |  0.00  0.00 |  +0.00  +0.00 
             Bishops |  0.00  0.00 |  0.00  0.00 |  +0.00  +0.00 
               Rooks | -0.37  0.00 |  0.00  0.00 |  -0.37  +0.00 
              Queens |  0.00  0.00 |  0.00  0.00 |  +0.00  +0.00 
            Mobility |  0.32  0.42 |  0.03 -0.06 |  +0.29  +0.48 
         King safety |  0.65  0.00 | -4.92  0.00 |  +5.57  +0.00 
             Threats |  0.27  0.64 |  0.04  0.20 |  +0.24  +0.44 
        Passed pawns |  0.00  0.00 |  0.00  0.00 |  +0.00  +0.00 
   Unstoppable pawns |   ---   --- |   ---   --- |  +0.00  +0.00 
               Space |  0.31  0.00 |  0.53  0.00 |  -0.22  +0.00 
---------------------+-------------+-------------+---------------
               Total |   ---   --- |   ---   --- |  +2.65  -2.36 

Uncertainty margin&#58; White&#58; +0.00, Black&#58; +5.25
Scaling&#58; 100.00% MG,   0.00% * 100.00% EG.
Total evaluation&#58; 2.67
User avatar
lucasart
Posts: 3232
Joined: Mon May 31, 2010 1:29 pm
Full name: lucasart

Re: Stockfish Code ( Piece Value's)

Post by lucasart »

NJDenson wrote:I believe the values are not correct
... and what's your supporting evidence ?

believe me marco and joona aren't amateurs, and didn't choose them randomly. they did some very expensive CLOP optimization of piece values and PST.

if you can get a significant elo gain by making your random modifications, i can't wait to see it. but i seriously doubt it...