mirror of
https://github.com/sockspls/badfish
synced 2025-04-30 08:43:09 +00:00
Code style triviality in search.cpp
No functional change. Signed-off-by: Marco Costalba <mcostalba@gmail.com>
This commit is contained in:
parent
d2c2af9e1c
commit
b5685fc564
1 changed files with 159 additions and 152 deletions
111
src/search.cpp
111
src/search.cpp
|
@ -143,8 +143,8 @@ namespace {
|
|||
const bool UseIIDAtNonPVNodes = false;
|
||||
|
||||
// Internal iterative deepening margin. At Non-PV moves, when
|
||||
// UseIIDAtNonPVNodes is true, we do an internal iterative deepening search
|
||||
// when the static evaluation is at most IIDMargin below beta.
|
||||
// UseIIDAtNonPVNodes is true, we do an internal iterative deepening
|
||||
// search when the static evaluation is at most IIDMargin below beta.
|
||||
const Value IIDMargin = Value(0x100);
|
||||
|
||||
// Easy move margin. An easy move candidate must be at least this much
|
||||
|
@ -173,7 +173,7 @@ namespace {
|
|||
const bool PruneBlockingMoves = false;
|
||||
|
||||
// Margins for futility pruning in the quiescence search, and at frontier
|
||||
// and near frontier nodes
|
||||
// and near frontier nodes.
|
||||
const Value FutilityMarginQS = Value(0x80);
|
||||
|
||||
// Remaining depth: 1 ply 1.5 ply 2 ply 2.5 ply 3 ply 3.5 ply
|
||||
|
@ -190,7 +190,7 @@ namespace {
|
|||
const Value RazorApprMargins[6] = { Value(0x520), Value(0x300), Value(0x300), Value(0x300), Value(0x300), Value(0x300) };
|
||||
|
||||
|
||||
/// Variables initialized from UCI options
|
||||
/// Variables initialized by UCI options
|
||||
|
||||
// Minimum number of full depth (i.e. non-reduced) moves at PV and non-PV nodes
|
||||
int LMRPVMoves, LMRNonPVMoves; // heavy SMP read access for the latter
|
||||
|
@ -429,7 +429,7 @@ bool think(const Position &pos, bool infinite, bool ponder, int side_to_move,
|
|||
for (int i = 1; i < ActiveThreads; i++)
|
||||
assert(thread_is_available(i, 0));
|
||||
|
||||
// Set thinking time:
|
||||
// Set thinking time
|
||||
int myTime = time[side_to_move];
|
||||
int myIncrement = increment[side_to_move];
|
||||
|
||||
|
@ -477,7 +477,7 @@ bool think(const Position &pos, bool infinite, bool ponder, int side_to_move,
|
|||
NodesBetweenPolls = 30000;
|
||||
|
||||
|
||||
// Write information to search log file:
|
||||
// Write information to search log file
|
||||
if (UseLogFile)
|
||||
LogFile << "Searching: " << pos.to_fen() << std::endl
|
||||
<< "infinite: " << infinite
|
||||
|
@ -487,8 +487,7 @@ bool think(const Position &pos, bool infinite, bool ponder, int side_to_move,
|
|||
<< " moves to go: " << movesToGo << std::endl;
|
||||
|
||||
|
||||
// We're ready to start thinking. Call the iterative deepening loop
|
||||
// function:
|
||||
// We're ready to start thinking. Call the iterative deepening loop function
|
||||
if (!looseOnTime)
|
||||
{
|
||||
Value v = id_loop(pos, searchMoves);
|
||||
|
@ -528,7 +527,7 @@ void init_threads() {
|
|||
for (i = 0; i < THREAD_MAX; i++)
|
||||
Threads[i].activeSplitPoints = 0;
|
||||
|
||||
// Initialize global locks:
|
||||
// Initialize global locks
|
||||
lock_init(&MPLock, NULL);
|
||||
lock_init(&IOLock, NULL);
|
||||
|
||||
|
@ -561,7 +560,7 @@ void init_threads() {
|
|||
CreateThread(NULL, 0, init_thread, (LPVOID)(&i), 0, iID);
|
||||
#endif
|
||||
|
||||
// Wait until the thread has finished launching:
|
||||
// Wait until the thread has finished launching
|
||||
while (!Threads[i].running);
|
||||
}
|
||||
}
|
||||
|
@ -723,7 +722,7 @@ namespace {
|
|||
// Time to stop?
|
||||
bool stopSearch = false;
|
||||
|
||||
// Stop search early if there is only a single legal move:
|
||||
// Stop search early if there is only a single legal move
|
||||
if (Iteration >= 6 && rml.move_count() == 1)
|
||||
stopSearch = true;
|
||||
|
||||
|
@ -938,7 +937,7 @@ namespace {
|
|||
if (i > 0)
|
||||
BestMoveChangesByIteration[Iteration]++;
|
||||
|
||||
// Print search information to the standard output:
|
||||
// Print search information to the standard output
|
||||
std::cout << "info depth " << Iteration
|
||||
<< " score " << value_to_string(value)
|
||||
<< " time " << current_search_time()
|
||||
|
@ -1134,7 +1133,7 @@ namespace {
|
|||
}
|
||||
// If we are at ply 1, and we are searching the first root move at
|
||||
// ply 0, set the 'Problem' variable if the score has dropped a lot
|
||||
// (from the computer's point of view) since the previous iteration:
|
||||
// (from the computer's point of view) since the previous iteration.
|
||||
if ( ply == 1
|
||||
&& Iteration >= 2
|
||||
&& -value <= IterationInfo[Iteration-1].value - ProblemMargin)
|
||||
|
@ -1155,7 +1154,7 @@ namespace {
|
|||
}
|
||||
|
||||
// All legal moves have been searched. A special case: If there were
|
||||
// no legal moves, it must be mate or stalemate:
|
||||
// no legal moves, it must be mate or stalemate.
|
||||
if (moveCount == 0)
|
||||
return (isCheck ? value_mated_in(ply) : VALUE_DRAW);
|
||||
|
||||
|
@ -1304,7 +1303,7 @@ namespace {
|
|||
}
|
||||
|
||||
// Initialize a MovePicker object for the current position, and prepare
|
||||
// to search all moves:
|
||||
// to search all moves.
|
||||
MovePicker mp = MovePicker(pos, ttMove, depth, Threads[threadID].H, &ss[ply]);
|
||||
|
||||
Move move, movesSearched[256];
|
||||
|
@ -1594,7 +1593,7 @@ namespace {
|
|||
}
|
||||
|
||||
// All legal moves have been searched. A special case: If we're in check
|
||||
// and no legal moves were found, it is checkmate:
|
||||
// and no legal moves were found, it is checkmate.
|
||||
if (pos.is_check() && moveCount == 0) // Mate!
|
||||
return value_mated_in(ply);
|
||||
|
||||
|
@ -1721,7 +1720,7 @@ namespace {
|
|||
lock_grab(&(sp->lock));
|
||||
|
||||
// If this is the master thread and we have been asked to stop because of
|
||||
// a beta cutoff higher up in the tree, stop all slave threads:
|
||||
// a beta cutoff higher up in the tree, stop all slave threads.
|
||||
if (sp->master == threadID && thread_should_stop(threadID))
|
||||
for (int i = 0; i < ActiveThreads; i++)
|
||||
if (sp->slaves[i])
|
||||
|
@ -2050,19 +2049,21 @@ namespace {
|
|||
// for user input and checks whether it is time to stop the search.
|
||||
|
||||
void init_node(SearchStack ss[], int ply, int threadID) {
|
||||
|
||||
assert(ply >= 0 && ply < PLY_MAX);
|
||||
assert(threadID >= 0 && threadID < ActiveThreads);
|
||||
|
||||
Threads[threadID].nodes++;
|
||||
|
||||
if(threadID == 0) {
|
||||
if (threadID == 0)
|
||||
{
|
||||
NodesSincePoll++;
|
||||
if(NodesSincePoll >= NodesBetweenPolls) {
|
||||
if (NodesSincePoll >= NodesBetweenPolls)
|
||||
{
|
||||
poll();
|
||||
NodesSincePoll = 0;
|
||||
}
|
||||
}
|
||||
|
||||
ss[ply].init(ply);
|
||||
ss[ply+2].initKillers();
|
||||
|
||||
|
@ -2116,53 +2117,53 @@ namespace {
|
|||
if (m2 == MOVE_NONE)
|
||||
return false;
|
||||
|
||||
// Case 1: The moving piece is the same in both moves.
|
||||
// Case 1: The moving piece is the same in both moves
|
||||
f2 = move_from(m2);
|
||||
t1 = move_to(m1);
|
||||
if (f2 == t1)
|
||||
return true;
|
||||
|
||||
// Case 2: The destination square for m2 was vacated by m1.
|
||||
// Case 2: The destination square for m2 was vacated by m1
|
||||
t2 = move_to(m2);
|
||||
f1 = move_from(m1);
|
||||
if (t2 == f1)
|
||||
return true;
|
||||
|
||||
// Case 3: Moving through the vacated square:
|
||||
if(piece_is_slider(pos.piece_on(f2)) &&
|
||||
bit_is_set(squares_between(f2, t2), f1))
|
||||
// Case 3: Moving through the vacated square
|
||||
if ( piece_is_slider(pos.piece_on(f2))
|
||||
&& bit_is_set(squares_between(f2, t2), f1))
|
||||
return true;
|
||||
|
||||
// Case 4: The destination square for m2 is attacked by the moving piece
|
||||
// in m1:
|
||||
// Case 4: The destination square for m2 is attacked by the moving piece in m1
|
||||
if (pos.piece_attacks_square(pos.piece_on(t1), t1, t2))
|
||||
return true;
|
||||
|
||||
// Case 5: Discovered check, checking piece is the piece moved in m1:
|
||||
if(piece_is_slider(pos.piece_on(t1)) &&
|
||||
bit_is_set(squares_between(t1, pos.king_square(pos.side_to_move())),
|
||||
f2) &&
|
||||
!bit_is_set(squares_between(t2, pos.king_square(pos.side_to_move())),
|
||||
t2)) {
|
||||
// Case 5: Discovered check, checking piece is the piece moved in m1
|
||||
if ( piece_is_slider(pos.piece_on(t1))
|
||||
&& bit_is_set(squares_between(t1, pos.king_square(pos.side_to_move())), f2)
|
||||
&& !bit_is_set(squares_between(t2, pos.king_square(pos.side_to_move())), t2))
|
||||
{
|
||||
Bitboard occ = pos.occupied_squares();
|
||||
Color us = pos.side_to_move();
|
||||
Square ksq = pos.king_square(us);
|
||||
clear_bit(&occ, f2);
|
||||
if(pos.type_of_piece_on(t1) == BISHOP) {
|
||||
if (pos.type_of_piece_on(t1) == BISHOP)
|
||||
{
|
||||
if (bit_is_set(bishop_attacks_bb(ksq, occ), t1))
|
||||
return true;
|
||||
}
|
||||
else if(pos.type_of_piece_on(t1) == ROOK) {
|
||||
else if (pos.type_of_piece_on(t1) == ROOK)
|
||||
{
|
||||
if (bit_is_set(rook_attacks_bb(ksq, occ), t1))
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
assert(pos.type_of_piece_on(t1) == QUEEN);
|
||||
if (bit_is_set(queen_attacks_bb(ksq, occ), t1))
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -2264,9 +2265,8 @@ namespace {
|
|||
// complicated endgames, e.g. KQ vs KR. FIXME
|
||||
|
||||
bool ok_to_do_nullmove(const Position& pos) {
|
||||
if(pos.non_pawn_material(pos.side_to_move()) == Value(0))
|
||||
return false;
|
||||
return true;
|
||||
|
||||
return pos.non_pawn_material(pos.side_to_move()) != Value(0);
|
||||
}
|
||||
|
||||
|
||||
|
@ -2275,7 +2275,6 @@ namespace {
|
|||
// candidates for pruning.
|
||||
|
||||
bool ok_to_prune(const Position& pos, Move m, Move threat, Depth d, const History& H) {
|
||||
Square mfrom, mto, tfrom, tto;
|
||||
|
||||
assert(move_is_ok(m));
|
||||
assert(threat == MOVE_NONE || move_is_ok(threat));
|
||||
|
@ -2285,12 +2284,14 @@ namespace {
|
|||
assert(!pos.move_is_passed_pawn_push(m));
|
||||
assert(d >= OnePly);
|
||||
|
||||
Square mfrom, mto, tfrom, tto;
|
||||
|
||||
mfrom = move_from(m);
|
||||
mto = move_to(m);
|
||||
tfrom = move_from(threat);
|
||||
tto = move_to(threat);
|
||||
|
||||
// Case 1: Castling moves are never pruned.
|
||||
// Case 1: Castling moves are never pruned
|
||||
if (move_is_castle(m))
|
||||
return false;
|
||||
|
||||
|
@ -2308,7 +2309,7 @@ namespace {
|
|||
&& pos.move_attacks_square(m, tto))
|
||||
return false;
|
||||
|
||||
// Case 4: Don't prune moves with good history.
|
||||
// Case 4: Don't prune moves with good history
|
||||
if (!H.ok_to_prune(pos.piece_on(mfrom), mto, d))
|
||||
return false;
|
||||
|
||||
|
@ -2386,9 +2387,11 @@ namespace {
|
|||
// is used for time managment.
|
||||
|
||||
bool fail_high_ply_1() {
|
||||
|
||||
for(int i = 0; i < ActiveThreads; i++)
|
||||
if (Threads[i].failHighPly1)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -2487,6 +2490,7 @@ namespace {
|
|||
// it correctly predicted the opponent's move.
|
||||
|
||||
void ponderhit() {
|
||||
|
||||
int t = current_search_time();
|
||||
PonderSearch = false;
|
||||
if (Iteration >= 3 &&
|
||||
|
@ -2504,14 +2508,17 @@ namespace {
|
|||
// thread. Called when the UCI option UCI_ShowCurrLine is 'true'.
|
||||
|
||||
void print_current_line(SearchStack ss[], int ply, int threadID) {
|
||||
|
||||
assert(ply >= 0 && ply < PLY_MAX);
|
||||
assert(threadID >= 0 && threadID < ActiveThreads);
|
||||
|
||||
if(!Threads[threadID].idle) {
|
||||
if (!Threads[threadID].idle)
|
||||
{
|
||||
lock_grab(&IOLock);
|
||||
std::cout << "info currline " << (threadID + 1);
|
||||
for (int p = 0; p < ply; p++)
|
||||
std::cout << " " << ss[p].currentMove;
|
||||
|
||||
std::cout << std::endl;
|
||||
lock_release(&IOLock);
|
||||
}
|
||||
|
@ -2574,7 +2581,7 @@ namespace {
|
|||
#endif
|
||||
}
|
||||
|
||||
// If this thread has been assigned work, launch a search:
|
||||
// If this thread has been assigned work, launch a search
|
||||
if(Threads[threadID].workIsWaiting) {
|
||||
Threads[threadID].workIsWaiting = false;
|
||||
if(Threads[threadID].splitPoint->pvNode)
|
||||
|
@ -2585,7 +2592,7 @@ namespace {
|
|||
}
|
||||
|
||||
// If this thread is the master of a split point and all threads have
|
||||
// finished their work at this split point, return from the idle loop:
|
||||
// finished their work at this split point, return from the idle loop.
|
||||
if(waitSp != NULL && waitSp->cpus == 0)
|
||||
return;
|
||||
}
|
||||
|
@ -2717,18 +2724,18 @@ namespace {
|
|||
lock_grab(&MPLock);
|
||||
|
||||
// If no other thread is available to help us, or if we have too many
|
||||
// active split points, don't split:
|
||||
// active split points, don't split.
|
||||
if(!idle_thread_exists(master) ||
|
||||
Threads[master].activeSplitPoints >= MaxActiveSplitPoints) {
|
||||
lock_release(&MPLock);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Pick the next available split point object from the split point stack:
|
||||
// Pick the next available split point object from the split point stack
|
||||
splitPoint = SplitPointStack[master] + Threads[master].activeSplitPoints;
|
||||
Threads[master].activeSplitPoints++;
|
||||
|
||||
// Initialize the split point object:
|
||||
// Initialize the split point object
|
||||
splitPoint->parent = Threads[master].splitPoint;
|
||||
splitPoint->finished = false;
|
||||
splitPoint->ply = ply;
|
||||
|
@ -2747,11 +2754,11 @@ namespace {
|
|||
for(i = 0; i < ActiveThreads; i++)
|
||||
splitPoint->slaves[i] = 0;
|
||||
|
||||
// Copy the current position and the search stack to the master thread:
|
||||
// Copy the current position and the search stack to the master thread
|
||||
memcpy(splitPoint->sstack[master], sstck, (ply+1)*sizeof(SearchStack));
|
||||
Threads[master].splitPoint = splitPoint;
|
||||
|
||||
// Make copies of the current position and search stack for each thread:
|
||||
// Make copies of the current position and search stack for each thread
|
||||
for(i = 0; i < ActiveThreads && splitPoint->cpus < MaxThreadsPerSplitPoint;
|
||||
i++)
|
||||
if(thread_is_available(i, master)) {
|
||||
|
@ -2781,7 +2788,7 @@ namespace {
|
|||
idle_loop(master, splitPoint);
|
||||
|
||||
// We have returned from the idle loop, which means that all threads are
|
||||
// finished. Update alpha, beta and bestvalue, and return:
|
||||
// finished. Update alpha, beta and bestvalue, and return.
|
||||
lock_grab(&MPLock);
|
||||
if(pvNode) *alpha = splitPoint->alpha;
|
||||
*beta = splitPoint->beta;
|
||||
|
|
Loading…
Add table
Reference in a new issue