Tu Ngoc Trung
Joined: 23 Feb 2012 Posts: 2
|
Post subject: Re: Stockfish - material balance/imbalance evaluation Posted: Sun May 27, 2012 2:22 am |
|
|
Sorry for my very late reply. I've recently found this topic.
I have some questions:
- In following code (current StockFish snapshot in Github), please notice code in bold format.
| Code: |
namespace {
//...
// Polynomial material balance parameters
const Value RedundantQueenPenalty = Value(320);
const Value RedundantRookPenalty = Value(554);
const int LinearCoefficients[6] = { 1617, -162, -1172, -190, 105, 26 };
|
| Code: |
/*
const int QuadraticCoefficientsSameColor[][8] = {
{ 7, 7, 7, 7, 7, 7 }, { 39, 2, 7, 7, 7, 7 }, { 35, 271, -4, 7, 7, 7 },
{ 7, 25, 4, 7, 7, 7 }, { -27, -2, 46, 100, 56, 7 }, { 58, 29, 83, 148, -3, -25 } };
const int QuadraticCoefficientsOppositeColor[][8] = {
{ 41, 41, 41, 41, 41, 41 }, { 37, 41, 41, 41, 41, 41 }, { 10, 62, 41, 41, 41, 41 },
{ 57, 64, 39, 41, 41, 41 }, { 50, 40, 23, -22, 41, 41 }, { 106, 101, 3, 151, 171, 41 } };
*/
// Re-formatted:
const int QuadraticCoefficientsSameColor[][8] = {
{ 7, 7, 7, 7, 7, 7 },
{ 39, 2, 7, 7, 7, 7 },
{ 35, 271, -4, 7, 7, 7 },
{ 7, 25, 4, 7, 7, 7 },
{ -27, -2, 46, 100, 56, 7 },
{ 58, 29, 83, 148, -3, -25 } };
const int QuadraticCoefficientsOppositeColor[][8] = {
{ 41, 41, 41, 41, 41, 41 },
{ 37, 41, 41, 41, 41, 41 },
{ 10, 62, 41, 41, 41, 41 },
{ 57, 64, 39, 41, 41, 41 },
{ 50, 40, 23, -22, 41, 41 },
{ 106, 101, 3, 151, 171, 41 } };
|
Please notice:
const int QuadraticCoefficientsSameColor[][8] = {
{ 7, 7, 7, 7, 7, 7 },
{ 39, 2, 7, 7, 7, 7 },
{ 35, 271, -4, 7, 7, 7 },
{ 7, 25, 4, 7, 7, 7 },
{ -27, -2, 46, 100, 56, 7 },
{ 58, 29, 83, 148, -3, -25 } };
const int QuadraticCoefficientsOppositeColor[][8] = {
{ 41, 41, 41, 41, 41, 41 },
{ 37, 41, 41, 41, 41, 41 },
{ 10, 62, 41, 41, 41, 41 },
{ 57, 64, 39, 41, 41, 41 },
{ 50, 40, 23, -22, 41, 41 },
{ 106, 101, 3, 151, 171, 41 } };
| Code: |
template<Color Us>
int MaterialTable::imbalance(const int pieceCount[][8]) {
//...
// Redundancy of major pieces, formula based on Kaufman's paper
// "The Evaluation of Material Imbalances in Chess"
if (pieceCount[Us][ROOK] > 0)
value -= RedundantRookPenalty * (pieceCount[Us][ROOK] - 1)
+ RedundantQueenPenalty * pieceCount[Us][QUEEN];
// Second-degree polynomial material imbalance by Tord Romstad
for (pt1 = NO_PIECE_TYPE; [b]pt1 <= QUEEN[/b]; pt1++)
{
pc = pieceCount[Us][pt1];
if (!pc)
continue;
v = LinearCoefficients[pt1];
for (pt2 = NO_PIECE_TYPE; pt2 <= pt1; pt2++)
v += QuadraticCoefficientsSameColor[pt1][pt2] * pieceCount[Us][pt2]
+ QuadraticCoefficientsOppositeColor[pt1][pt2] * pieceCount[Them][pt2];
value += pc * v;
}
|
Please notice:
for (pt2 = NO_PIECE_TYPE; pt2 <= pt1; pt2++)
Questions:
1. What is the meaning of RedundantQueenPenalty, RedundantRookPenalty and why they are used in following code?
| Code: |
if (pieceCount[Us][ROOK] > 0)
value -= RedundantRookPenalty * (pieceCount[Us][ROOK] - 1)
+ RedundantQueenPenalty * pieceCount[Us][QUEEN];
|
2. What is the meaning of LinearCoefficients values?
| Code: |
const int LinearCoefficients[6] = { 1617, -162, -1172, -190, 105, 26 };
|
3. Why do you use for (pt2 = NO_PIECE_TYPE; pt2 <= pt1; pt2++) ? I think it should be for (pt2 = NO_PIECE_TYPE; pt2 <= QUEEN; pt2++). Because if you keep the current code, program will scan thought the arrays QuadraticCoefficientsXXX as I mentioned in blue bold format. Numbers of loop iterations will be (1+2+3+4+5+6)=21 instead of 6x6=36. And red-italic values of QuadraticCoefficientsXXX arrays will not be calculated.
4. Why do you calculate
v += QuadraticCoefficientsSameColor[pt1][pt2] * pieceCount[Us][pt2] + QuadraticCoefficientsOppositeColor[pt1][pt2] * pieceCount[Them][pt2]; ?
Why not calculate
v += QuadraticCoefficientsSameColor[pt1][pt2] * pieceCount[Us][pt2] + QuadraticCoefficientsOppositeColor[pt1][pt2] * pieceCount[Us][pt2]; ?
Because the meaning of array name I understand here is Opposite color but not Opponent color.
Thanks & regards, |
|