// sorting the moves. A move m1 is considered to be better
// than a move m2 if it has a higher score, or if the moves
// have equal score but m1 has the higher node count.
- bool RootMove::operator<(const RootMove& m) const {
+ bool operator<(const RootMove& m) const {
return score != m.score ? score < m.score : theirBeta <= m.theirBeta;
}
bool ok_to_do_nullmove(const Position& pos);
bool ok_to_prune(const Position& pos, Move m, Move threat);
bool ok_to_use_TT(const TTEntry* tte, Depth depth, Value beta, int ply);
+ Value refine_eval(const TTEntry* tte, Value defaultEval, int ply);
void update_history(const Position& pos, Move move, Depth depth, Move movesSearched[], int moveCount);
void update_killers(Move m, SearchStack& ss);
//// Functions
////
+//FIXME: HACK
+static double lnArray[512];
+
+inline double ln(int i)
+{
+ return lnArray[i];
+}
/// perft() is our utility to verify move generation is bug free. All the legal
/// moves up to given depth are generated and counted and the sum returned.
/// and initializes the split point stack and the global locks and condition
/// objects.
+#include <cmath> //FIXME: HACK
+
void init_threads() {
+ // FIXME: HACK!!
+ for (int i = 0; i < 512; i++)
+ lnArray[i] = log(double(i));
+
volatile int i;
#if !defined(_MSC_VER)
int64_t nodes;
Move move;
StateInfo st;
- Depth ext, newDepth;
+ Depth depth, ext, newDepth;
RootMoveNumber = i + 1;
FailHigh = false;
bool moveIsCheck = pos.move_is_check(move);
bool captureOrPromotion = pos.move_is_capture_or_promotion(move);
bool dangerous;
+ depth = (Iteration - 2) * OnePly + InitialDepth;
ext = extension(pos, move, true, captureOrPromotion, moveIsCheck, false, false, &dangerous);
- newDepth = (Iteration - 2) * OnePly + ext + InitialDepth;
+ newDepth = depth + ext;
// Make the move, and search it
pos.do_move(move, st, ci, moveIsCheck);
{
// Try to reduce non-pv search depth by one ply if move seems not problematic,
// if the move fails high will be re-searched at full depth.
- if ( newDepth >= 3*OnePly
- && i >= MultiPV + LMRPVMoves
+ if ( depth >= 3*OnePly // FIXME was newDepth
&& !dangerous
&& !captureOrPromotion
&& !move_is_castle(move))
{
- ss[0].reduction = OnePly;
- value = -search(pos, ss, -alpha, newDepth-OnePly, 1, true, 0);
+ double red = 0.5 + ln(RootMoveNumber - MultiPV + 1) * ln(depth / 2) / 6.0;
+ if (red >= 1.0)
+ {
+ ss[0].reduction = Depth(int(floor(red * int(OnePly))));
+ value = -search(pos, ss, -alpha, newDepth-ss[0].reduction, 1, true, 0);
+ }
+ else
+ value = alpha + 1; // Just to trigger next condition
} else
value = alpha + 1; // Just to trigger next condition
// Try to reduce non-pv search depth by one ply if move seems not problematic,
// if the move fails high will be re-searched at full depth.
if ( depth >= 3*OnePly
- && moveCount >= LMRPVMoves
&& !dangerous
&& !captureOrPromotion
&& !move_is_castle(move)
&& !move_is_killer(move, ss[ply]))
{
- ss[ply].reduction = OnePly;
- value = -search(pos, ss, -alpha, newDepth-OnePly, ply+1, true, threadID);
+ double red = 0.5 + ln(moveCount) * ln(depth / 2) / 6.0;
+ if (red >= 1.0)
+ {
+ ss[ply].reduction = Depth(int(floor(red * int(OnePly))));
+ value = -search(pos, ss, -alpha, newDepth-ss[ply].reduction, ply+1, true, threadID);
+ }
+ else
+ value = alpha + 1; // Just to trigger next condition
}
else
value = alpha + 1; // Just to trigger next condition
return value_from_tt(tte->value(), ply);
}
- approximateEval = quick_evaluate(pos);
+ approximateEval = refine_eval(tte, quick_evaluate(pos), ply);
isCheck = pos.is_check();
// Null move search
pos.do_null_move(st);
// Null move dynamic reduction based on depth
- int R = (depth >= 5 * OnePly ? 4 : 3);
+ int R = 3 + (depth >= 5 * OnePly ? depth / 8 : 0);
// Null move dynamic reduction based on value
if (approximateEval - beta > PawnValueMidgame)
// Try to reduce non-pv search depth by one ply if move seems not problematic,
// if the move fails high will be re-searched at full depth.
if ( depth >= 3*OnePly
- && moveCount >= LMRNonPVMoves
&& !dangerous
&& !captureOrPromotion
&& !move_is_castle(move)
- && !move_is_killer(move, ss[ply]))
+ && !move_is_killer(move, ss[ply])
+ /* && move != ttMove*/)
{
- ss[ply].reduction = OnePly;
- value = -search(pos, ss, -(beta-1), newDepth-OnePly, ply+1, true, threadID);
+ double red = 0.5 + ln(moveCount) * ln(depth / 2) / 3.0;
+ if (red >= 1.0)
+ {
+ ss[ply].reduction = Depth(int(floor(red * int(OnePly))));
+ value = -search(pos, ss, -(beta-1), newDepth-ss[ply].reduction, ply+1, true, threadID);
+ }
+ else
+ value = beta; // Just to trigger next condition
}
else
value = beta; // Just to trigger next condition
// Try to reduce non-pv search depth by one ply if move seems not problematic,
// if the move fails high will be re-searched at full depth.
if ( !dangerous
- && moveCount >= LMRNonPVMoves
&& !captureOrPromotion
&& !move_is_castle(move)
&& !move_is_killer(move, ss[sp->ply]))
{
- ss[sp->ply].reduction = OnePly;
- value = -search(pos, ss, -(sp->beta-1), newDepth - OnePly, sp->ply+1, true, threadID);
+ double red = 0.5 + ln(moveCount) * ln(sp->depth / 2) / 3.0;
+ if (red >= 1.0)
+ {
+ ss[sp->ply].reduction = Depth(int(floor(red * int(OnePly))));
+ value = -search(pos, ss, -(sp->beta-1), newDepth-ss[sp->ply].reduction, sp->ply+1, true, threadID);
+ }
+ else
+ value = sp->beta; // Just to trigger next condition
}
else
value = sp->beta; // Just to trigger next condition
// Try to reduce non-pv search depth by one ply if move seems not problematic,
// if the move fails high will be re-searched at full depth.
if ( !dangerous
- && moveCount >= LMRPVMoves
&& !captureOrPromotion
&& !move_is_castle(move)
&& !move_is_killer(move, ss[sp->ply]))
{
- ss[sp->ply].reduction = OnePly;
- value = -search(pos, ss, -sp->alpha, newDepth - OnePly, sp->ply+1, true, threadID);
+ double red = 0.5 + ln(moveCount) * ln(sp->depth / 2) / 6.0;
+ if (red >= 1.0)
+ {
+ ss[sp->ply].reduction = Depth(int(floor(red * int(OnePly))));
+ value = -search(pos, ss, -sp->alpha, newDepth-ss[sp->ply].reduction, sp->ply+1, true, threadID);
+ }
+ else
+ value = sp->alpha + 1; // Just to trigger next condition
}
else
value = sp->alpha + 1; // Just to trigger next condition
// RootMoveList simple methods definitions
- inline void RootMoveList::set_move_nodes(int moveNum, int64_t nodes) {
+ void RootMoveList::set_move_nodes(int moveNum, int64_t nodes) {
moves[moveNum].nodes = nodes;
moves[moveNum].cumulativeNodes += nodes;
}
- inline void RootMoveList::set_beta_counters(int moveNum, int64_t our, int64_t their) {
+ void RootMoveList::set_beta_counters(int moveNum, int64_t our, int64_t their) {
moves[moveNum].ourBeta = our;
moves[moveNum].theirBeta = their;
// RootMoveList::sort() sorts the root move list at the beginning of a new
// iteration.
- inline void RootMoveList::sort() {
+ void RootMoveList::sort() {
sort_multipv(count - 1); // Sort all items
}
}
+ // refine_eval() returns the transposition table score if
+ // possible otherwise falls back on static position evaluation.
+
+ Value refine_eval(const TTEntry* tte, Value defaultEval, int ply) {
+
+ if (!tte)
+ return defaultEval;
+
+ Value v = value_from_tt(tte->value(), ply);
+
+ if ( (is_lower_bound(tte->type()) && v >= defaultEval)
+ || (is_upper_bound(tte->type()) && v < defaultEval))
+ return v;
+
+ return defaultEval;
+ }
+
// update_history() registers a good move that produced a beta-cutoff
// in history and marks as failures all the other moves of that ply.