+const int halfDensityMap[][9] =
+{
+ {2, 0, 1},
+ {2, 1, 0},
+
+ {4, 0, 0, 1, 1},
+ {4, 0, 1, 1, 0},
+ {4, 1, 1, 0, 0},
+ {4, 1, 0, 0, 1},
+
+ {6, 0, 0, 0, 1, 1, 1},
+ {6, 0, 0, 1, 1, 1, 0},
+ {6, 0, 1, 1, 1, 0, 0},
+ {6, 1, 1, 1, 0, 0, 0},
+ {6, 1, 1, 0, 0, 0, 1},
+ {6, 1, 0, 0, 0, 1, 1},
+
+ {8, 0, 0, 0, 0, 1, 1, 1, 1},
+ {8, 0, 0, 0, 1, 1, 1, 1, 0},
+ {8, 0, 0, 1, 1, 1, 1, 0 ,0},
+ {8, 0, 1, 1, 1, 1, 0, 0 ,0},
+ {8, 1, 1, 1, 1, 0, 0, 0 ,0},
+ {8, 1, 1, 1, 0, 0, 0, 0 ,1},
+ {8, 1, 1, 0, 0, 0, 0, 1 ,1},
+ {8, 1, 0, 0, 0, 0, 1, 1 ,1},
+};
+
+
+// Thread::search() is the main iterative deepening loop. It calls search()
+// repeatedly with increasing depth until the allocated thinking time has been
+// consumed, the user stops the search, or the maximum search depth is reached.
+
+void Thread::search() {
+
+ Stack stack[MAX_PLY+4], *ss = stack+2; // To allow referencing (ss-2) and (ss+2)
+ Value bestValue, alpha, beta, delta;
+ Move easyMove = MOVE_NONE;
+ MainThread* mainThread = (this == Threads.main() ? Threads.main() : nullptr);
+
+ std::memset(ss-2, 0, 5 * sizeof(Stack));
+
+ bestValue = delta = alpha = -VALUE_INFINITE;
+ beta = VALUE_INFINITE;
+ completedDepth = DEPTH_ZERO;
+
+ if (mainThread)
+ {
+ easyMove = EasyMove.get(rootPos.key());
+ EasyMove.clear();
+ mainThread->easyMovePlayed = mainThread->failedLow = false;
+ mainThread->bestMoveChanges = 0;
+ TT.new_search();
+ }