summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
187a9fe)
Another attempt at retiring current asymmetric
king evaluation and use a much simpler symmetric
one. As a good side effect we can avoid recalculating
eval after a null move.
Tested in no-regression mode and passed
STC
LLR: 2.96 (-2.94,2.94) [-3.00,1.00]
Total: 21580 W: 3752 L: 3632 D: 14196
LTC
LLR: 2.96 (-2.94,2.94) [-3.00,1.00]
Total: 18253 W: 2593 L: 2469 D: 13191
And a LTC regression test against SF DD to
verify we don't have regression against
weaker engines due to some kind of 'contempt'
effect:
ELO: 54.69 +-2.1 (95%) LOS: 100.0%
Total: 40000 W: 11072 L: 4827 D: 24101
bench:
8205159
}
// Evaluation weights, indexed by evaluation term
}
// Evaluation weights, indexed by evaluation term
- enum { Mobility, PawnStructure, PassedPawns, Space, KingDangerUs, KingDangerThem };
+ enum { Mobility, PawnStructure, PassedPawns, Space, KingSafety };
const struct Weight { int mg, eg; } Weights[] = {
const struct Weight { int mg, eg; } Weights[] = {
- {289, 344}, {233, 201}, {221, 273}, {46, 0}, {271, 0}, {307, 0}
+ {289, 344}, {233, 201}, {221, 273}, {46, 0}, {318, 0}
S(0, 0), S(0, 0), S(56, 70), S(56, 70), S(76, 99), S(86, 118)
};
S(0, 0), S(0, 0), S(56, 70), S(56, 70), S(76, 99), S(86, 118)
};
- // Hanging[side to move] contains a bonus for each enemy hanging piece
- const Score Hanging[2] = { S(23, 20) , S(35, 45) };
+ // Hanging contains a bonus for each enemy hanging piece
+ const Score Hanging = S(23, 20);
- const Score Tempo = make_score(24, 11);
const Score RookOnPawn = make_score(10, 28);
const Score RookOpenFile = make_score(43, 21);
const Score RookSemiopenFile = make_score(19, 10);
const Score RookOnPawn = make_score(10, 28);
const Score RookOpenFile = make_score(43, 21);
const Score RookSemiopenFile = make_score(19, 10);
const int BishopCheck = 2;
const int KnightCheck = 3;
const int BishopCheck = 2;
const int KnightCheck = 3;
- // KingDanger[Color][attackUnits] contains the actual king danger weighted
- // scores, indexed by color and by a calculated integer number.
- Score KingDanger[COLOR_NB][128];
+ // KingDanger[attackUnits] contains the actual king danger weighted
+ // scores, indexed by a calculated integer number.
+ Score KingDanger[128];
// apply_weight() weighs score 'v' by weight 'w' trying to prevent overflow
// apply_weight() weighs score 'v' by weight 'w' trying to prevent overflow
| ei.attackedBy[Them][BISHOP] | ei.attackedBy[Them][ROOK]);
if (b)
| ei.attackedBy[Them][BISHOP] | ei.attackedBy[Them][ROOK]);
if (b)
- attackUnits += QueenContactCheck
- * popcount<Max15>(b)
- * (Them == pos.side_to_move() ? 2 : 1);
+ attackUnits += QueenContactCheck * popcount<Max15>(b);
}
// Analyse the enemy's safe rook contact checks. Firstly, find the
}
// Analyse the enemy's safe rook contact checks. Firstly, find the
| ei.attackedBy[Them][BISHOP] | ei.attackedBy[Them][QUEEN]);
if (b)
| ei.attackedBy[Them][BISHOP] | ei.attackedBy[Them][QUEEN]);
if (b)
- attackUnits += RookContactCheck
- * popcount<Max15>(b)
- * (Them == pos.side_to_move() ? 2 : 1);
+ attackUnits += RookContactCheck * popcount<Max15>(b);
}
// Analyse the enemy's safe distance checks for sliders and knights
}
// Analyse the enemy's safe distance checks for sliders and knights
// Finally, extract the king danger score from the KingDanger[]
// array and subtract the score from evaluation.
// Finally, extract the king danger score from the KingDanger[]
// array and subtract the score from evaluation.
- score -= KingDanger[Us == Search::RootColor][attackUnits];
+ score -= KingDanger[attackUnits];
b = weakEnemies & ~ei.attackedBy[Them][ALL_PIECES];
if (b)
b = weakEnemies & ~ei.attackedBy[Them][ALL_PIECES];
if (b)
- score += more_than_one(b) ? Hanging[Us != pos.side_to_move()] * popcount<Max15>(b)
- : Hanging[Us == pos.side_to_move()];
+ score += more_than_one(b) ? Hanging * popcount<Max15>(b) : Hanging;
Thread* thisThread = pos.this_thread();
// Initialize score by reading the incrementally updated scores included
Thread* thisThread = pos.this_thread();
// Initialize score by reading the incrementally updated scores included
- // in the position object (material + piece square tables) and adding a
- // Tempo bonus. Score is computed from the point of view of white.
- score = pos.psq_score() + (pos.side_to_move() == WHITE ? Tempo : -Tempo);
+ // in the position object (material + piece square tables).
+ // Score is computed from the point of view of white.
+ score = pos.psq_score();
// Probe the material hash table
ei.mi = Material::probe(pos, thisThread->materialTable, thisThread->endgames);
// Probe the material hash table
ei.mi = Material::probe(pos, thisThread->materialTable, thisThread->endgames);
<< " | MG EG | MG EG | MG EG \n"
<< "---------------------+-------------+-------------+-------------\n";
<< " | MG EG | MG EG | MG EG \n"
<< "---------------------+-------------+-------------+-------------\n";
- format_row(ss, "Material, PST, Tempo", PST);
+ format_row(ss, "Material, PST", PST);
format_row(ss, "Material imbalance", IMBALANCE);
format_row(ss, "Pawns", PAWN);
format_row(ss, "Knights", KNIGHT);
format_row(ss, "Material imbalance", IMBALANCE);
format_row(ss, "Pawns", PAWN);
format_row(ss, "Knights", KNIGHT);
for (int t = 0, i = 1; i < 100; ++i)
{
t = int(std::min(Peak, std::min(0.4 * i * i, t + MaxSlope)));
for (int t = 0, i = 1; i < 100; ++i)
{
t = int(std::min(Peak, std::min(0.4 * i * i, t + MaxSlope)));
-
- KingDanger[1][i] = apply_weight(make_score(t, 0), Weights[KingDangerUs]);
- KingDanger[0][i] = apply_weight(make_score(t, 0), Weights[KingDangerThem]);
+ KingDanger[i] = apply_weight(make_score(t, 0), Weights[KingSafety]);
LimitsType Limits;
std::vector<RootMove> RootMoves;
Position RootPos;
LimitsType Limits;
std::vector<RootMove> RootMoves;
Position RootPos;
Time::point SearchTime;
StateStackPtr SetupStates;
}
Time::point SearchTime;
StateStackPtr SetupStates;
}
return (Depth) Reductions[PvNode][i][std::min(int(d) / ONE_PLY, 63)][std::min(mn, 63)];
}
return (Depth) Reductions[PvNode][i][std::min(int(d) / ONE_PLY, 63)][std::min(mn, 63)];
}
+ // Tempo bonus. Must be handled by search to preserve eval symmetry.
+ const int Tempo = 17;
+
size_t MultiPV, PVIdx;
TimeManager TimeMgr;
double BestMoveChanges;
size_t MultiPV, PVIdx;
TimeManager TimeMgr;
double BestMoveChanges;
- RootColor = RootPos.side_to_move();
- TimeMgr.init(Limits, RootPos.game_ply(), RootColor);
+ TimeMgr.init(Limits, RootPos.game_ply(), RootPos.side_to_move());
int cf = Options["Contempt Factor"] * PawnValueEg / 100; // From centipawns
int cf = Options["Contempt Factor"] * PawnValueEg / 100; // From centipawns
- DrawValue[ RootColor] = VALUE_DRAW - Value(cf);
- DrawValue[~RootColor] = VALUE_DRAW + Value(cf);
+ DrawValue[ RootPos.side_to_move()] = VALUE_DRAW - Value(cf);
+ DrawValue[~RootPos.side_to_move()] = VALUE_DRAW + Value(cf);
log << "\nSearching: " << RootPos.fen()
<< "\ninfinite: " << Limits.infinite
<< " ponder: " << Limits.ponder
log << "\nSearching: " << RootPos.fen()
<< "\ninfinite: " << Limits.infinite
<< " ponder: " << Limits.ponder
- << " time: " << Limits.time[RootColor]
- << " increment: " << Limits.inc[RootColor]
+ << " time: " << Limits.time[RootPos.side_to_move()]
+ << " increment: " << Limits.inc[RootPos.side_to_move()]
<< " moves to go: " << Limits.movestogo
<< "\n" << std::endl;
}
<< " moves to go: " << Limits.movestogo
<< "\n" << std::endl;
}
bestValue = -VALUE_INFINITE;
ss->currentMove = ss->ttMove = (ss+1)->excludedMove = bestMove = MOVE_NONE;
ss->ply = (ss-1)->ply + 1;
bestValue = -VALUE_INFINITE;
ss->currentMove = ss->ttMove = (ss+1)->excludedMove = bestMove = MOVE_NONE;
ss->ply = (ss-1)->ply + 1;
- (ss+1)->skipNullMove = false; (ss+1)->reduction = DEPTH_ZERO;
+ (ss+1)->skipNullMove = (ss+1)->nullChild = false; (ss+1)->reduction = DEPTH_ZERO;
(ss+2)->killers[0] = (ss+2)->killers[1] = MOVE_NONE;
// Used to send selDepth info to GUI
(ss+2)->killers[0] = (ss+2)->killers[1] = MOVE_NONE;
// Used to send selDepth info to GUI
{
// Step 2. Check for aborted search and immediate draw
if (Signals.stop || pos.is_draw() || ss->ply > MAX_PLY)
{
// Step 2. Check for aborted search and immediate draw
if (Signals.stop || pos.is_draw() || ss->ply > MAX_PLY)
- return ss->ply > MAX_PLY && !inCheck ? evaluate(pos) : DrawValue[pos.side_to_move()];
+ return ss->ply > MAX_PLY && !inCheck ? evaluate(pos) + Tempo : DrawValue[pos.side_to_move()];
// Step 3. Mate distance pruning. Even if we mate at the next move our score
// would be at best mate_in(ss->ply+1), but if alpha is already bigger because
// Step 3. Mate distance pruning. Even if we mate at the next move our score
// would be at best mate_in(ss->ply+1), but if alpha is already bigger because
{
// Never assume anything on values stored in TT
if ((ss->staticEval = eval = tte->eval_value()) == VALUE_NONE)
{
// Never assume anything on values stored in TT
if ((ss->staticEval = eval = tte->eval_value()) == VALUE_NONE)
- eval = ss->staticEval = evaluate(pos);
+ eval = ss->staticEval = evaluate(pos) + Tempo;
// Can ttValue be used as a better position evaluation?
if (ttValue != VALUE_NONE)
// Can ttValue be used as a better position evaluation?
if (ttValue != VALUE_NONE)
- eval = ss->staticEval = evaluate(pos);
+ eval = ss->staticEval = ss->nullChild ? -(ss-1)->staticEval + 2 * Tempo : evaluate(pos) + Tempo;
TT.store(posKey, VALUE_NONE, BOUND_NONE, DEPTH_NONE, MOVE_NONE, ss->staticEval);
}
TT.store(posKey, VALUE_NONE, BOUND_NONE, DEPTH_NONE, MOVE_NONE, ss->staticEval);
}
+ int(eval - beta) / PawnValueMg * ONE_PLY;
pos.do_null_move(st);
+ int(eval - beta) / PawnValueMg * ONE_PLY;
pos.do_null_move(st);
- (ss+1)->skipNullMove = true;
+ (ss+1)->skipNullMove = (ss+1)->nullChild = true;
nullValue = depth-R < ONE_PLY ? -qsearch<NonPV, false>(pos, ss+1, -beta, -beta+1, DEPTH_ZERO)
: - search<NonPV, false>(pos, ss+1, -beta, -beta+1, depth-R, !cutNode);
nullValue = depth-R < ONE_PLY ? -qsearch<NonPV, false>(pos, ss+1, -beta, -beta+1, DEPTH_ZERO)
: - search<NonPV, false>(pos, ss+1, -beta, -beta+1, depth-R, !cutNode);
- (ss+1)->skipNullMove = false;
+ (ss+1)->skipNullMove = (ss+1)->nullChild = false;
pos.undo_null_move();
if (nullValue >= beta)
pos.undo_null_move();
if (nullValue >= beta)
// Check for an instant draw or if the maximum ply has been reached
if (pos.is_draw() || ss->ply > MAX_PLY)
// Check for an instant draw or if the maximum ply has been reached
if (pos.is_draw() || ss->ply > MAX_PLY)
- return ss->ply > MAX_PLY && !InCheck ? evaluate(pos) : DrawValue[pos.side_to_move()];
+ return ss->ply > MAX_PLY && !InCheck ? evaluate(pos) + Tempo : DrawValue[pos.side_to_move()];
// Decide whether or not to include checks: this fixes also the type of
// TT entry depth that we are going to use. Note that in qsearch we use
// Decide whether or not to include checks: this fixes also the type of
// TT entry depth that we are going to use. Note that in qsearch we use
{
// Never assume anything on values stored in TT
if ((ss->staticEval = bestValue = tte->eval_value()) == VALUE_NONE)
{
// Never assume anything on values stored in TT
if ((ss->staticEval = bestValue = tte->eval_value()) == VALUE_NONE)
- ss->staticEval = bestValue = evaluate(pos);
+ ss->staticEval = bestValue = evaluate(pos) + Tempo;
// Can ttValue be used as a better position evaluation?
if (ttValue != VALUE_NONE)
// Can ttValue be used as a better position evaluation?
if (ttValue != VALUE_NONE)
bestValue = ttValue;
}
else
bestValue = ttValue;
}
else
- ss->staticEval = bestValue = evaluate(pos);
+ ss->staticEval = bestValue = ss->nullChild ? -(ss-1)->staticEval + 2 * Tempo : evaluate(pos) + Tempo;
// Stand pat. Return immediately if static value is at least beta
if (bestValue >= beta)
// Stand pat. Return immediately if static value is at least beta
if (bestValue >= beta)
Move killers[2];
Depth reduction;
Value staticEval;
Move killers[2];
Depth reduction;
Value staticEval;
+ bool skipNullMove;
+ bool nullChild;
extern LimitsType Limits;
extern std::vector<RootMove> RootMoves;
extern Position RootPos;
extern LimitsType Limits;
extern std::vector<RootMove> RootMoves;
extern Position RootPos;
extern Time::point SearchTime;
extern StateStackPtr SetupStates;
extern Time::point SearchTime;
extern StateStackPtr SetupStates;
<< "\n" << Options
<< "\nuciok" << sync_endl;
<< "\n" << Options
<< "\nuciok" << sync_endl;
- else if (token == "eval")
- {
- Search::RootColor = pos.side_to_move(); // Ensure it is set
- sync_cout << Eval::trace(pos) << sync_endl;
- }
+ else if (token == "eval") sync_cout << Eval::trace(pos) << sync_endl;
else if (token == "ucinewgame") TT.clear();
else if (token == "go") go(pos, is);
else if (token == "position") position(pos, is);
else if (token == "ucinewgame") TT.clear();
else if (token == "go") go(pos, is);
else if (token == "position") position(pos, is);