1
0
Fork 0
mirror of https://github.com/sockspls/badfish synced 2025-05-01 01:03: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:
Marco Costalba 2009-06-11 15:57:42 +02:00
parent d2c2af9e1c
commit b5685fc564

View file

@ -143,8 +143,8 @@ namespace {
const bool UseIIDAtNonPVNodes = false; const bool UseIIDAtNonPVNodes = false;
// Internal iterative deepening margin. At Non-PV moves, when // Internal iterative deepening margin. At Non-PV moves, when
// UseIIDAtNonPVNodes is true, we do an internal iterative deepening search // UseIIDAtNonPVNodes is true, we do an internal iterative deepening
// when the static evaluation is at most IIDMargin below beta. // search when the static evaluation is at most IIDMargin below beta.
const Value IIDMargin = Value(0x100); const Value IIDMargin = Value(0x100);
// Easy move margin. An easy move candidate must be at least this much // Easy move margin. An easy move candidate must be at least this much
@ -173,7 +173,7 @@ namespace {
const bool PruneBlockingMoves = false; const bool PruneBlockingMoves = false;
// Margins for futility pruning in the quiescence search, and at frontier // Margins for futility pruning in the quiescence search, and at frontier
// and near frontier nodes // and near frontier nodes.
const Value FutilityMarginQS = Value(0x80); const Value FutilityMarginQS = Value(0x80);
// Remaining depth: 1 ply 1.5 ply 2 ply 2.5 ply 3 ply 3.5 ply // 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) }; 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 // 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 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++) for (int i = 1; i < ActiveThreads; i++)
assert(thread_is_available(i, 0)); assert(thread_is_available(i, 0));
// Set thinking time: // Set thinking time
int myTime = time[side_to_move]; int myTime = time[side_to_move];
int myIncrement = increment[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; NodesBetweenPolls = 30000;
// Write information to search log file: // Write information to search log file
if (UseLogFile) if (UseLogFile)
LogFile << "Searching: " << pos.to_fen() << std::endl LogFile << "Searching: " << pos.to_fen() << std::endl
<< "infinite: " << infinite << "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; << " moves to go: " << movesToGo << std::endl;
// We're ready to start thinking. Call the iterative deepening loop // We're ready to start thinking. Call the iterative deepening loop function
// function:
if (!looseOnTime) if (!looseOnTime)
{ {
Value v = id_loop(pos, searchMoves); Value v = id_loop(pos, searchMoves);
@ -528,7 +527,7 @@ void init_threads() {
for (i = 0; i < THREAD_MAX; i++) for (i = 0; i < THREAD_MAX; i++)
Threads[i].activeSplitPoints = 0; Threads[i].activeSplitPoints = 0;
// Initialize global locks: // Initialize global locks
lock_init(&MPLock, NULL); lock_init(&MPLock, NULL);
lock_init(&IOLock, NULL); lock_init(&IOLock, NULL);
@ -561,7 +560,7 @@ void init_threads() {
CreateThread(NULL, 0, init_thread, (LPVOID)(&i), 0, iID); CreateThread(NULL, 0, init_thread, (LPVOID)(&i), 0, iID);
#endif #endif
// Wait until the thread has finished launching: // Wait until the thread has finished launching
while (!Threads[i].running); while (!Threads[i].running);
} }
} }
@ -723,7 +722,7 @@ namespace {
// Time to stop? // Time to stop?
bool stopSearch = false; 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) if (Iteration >= 6 && rml.move_count() == 1)
stopSearch = true; stopSearch = true;
@ -938,7 +937,7 @@ namespace {
if (i > 0) if (i > 0)
BestMoveChangesByIteration[Iteration]++; BestMoveChangesByIteration[Iteration]++;
// Print search information to the standard output: // Print search information to the standard output
std::cout << "info depth " << Iteration std::cout << "info depth " << Iteration
<< " score " << value_to_string(value) << " score " << value_to_string(value)
<< " time " << current_search_time() << " time " << current_search_time()
@ -1134,7 +1133,7 @@ namespace {
} }
// If we are at ply 1, and we are searching the first root move at // 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 // 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 if ( ply == 1
&& Iteration >= 2 && Iteration >= 2
&& -value <= IterationInfo[Iteration-1].value - ProblemMargin) && -value <= IterationInfo[Iteration-1].value - ProblemMargin)
@ -1155,7 +1154,7 @@ namespace {
} }
// All legal moves have been searched. A special case: If there were // 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) if (moveCount == 0)
return (isCheck ? value_mated_in(ply) : VALUE_DRAW); return (isCheck ? value_mated_in(ply) : VALUE_DRAW);
@ -1304,7 +1303,7 @@ namespace {
} }
// Initialize a MovePicker object for the current position, and prepare // 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]); MovePicker mp = MovePicker(pos, ttMove, depth, Threads[threadID].H, &ss[ply]);
Move move, movesSearched[256]; Move move, movesSearched[256];
@ -1594,7 +1593,7 @@ namespace {
} }
// All legal moves have been searched. A special case: If we're in check // 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! if (pos.is_check() && moveCount == 0) // Mate!
return value_mated_in(ply); return value_mated_in(ply);
@ -1721,7 +1720,7 @@ namespace {
lock_grab(&(sp->lock)); lock_grab(&(sp->lock));
// If this is the master thread and we have been asked to stop because of // 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)) if (sp->master == threadID && thread_should_stop(threadID))
for (int i = 0; i < ActiveThreads; i++) for (int i = 0; i < ActiveThreads; i++)
if (sp->slaves[i]) if (sp->slaves[i])
@ -2050,19 +2049,21 @@ namespace {
// for user input and checks whether it is time to stop the search. // for user input and checks whether it is time to stop the search.
void init_node(SearchStack ss[], int ply, int threadID) { void init_node(SearchStack ss[], int ply, int threadID) {
assert(ply >= 0 && ply < PLY_MAX); assert(ply >= 0 && ply < PLY_MAX);
assert(threadID >= 0 && threadID < ActiveThreads); assert(threadID >= 0 && threadID < ActiveThreads);
Threads[threadID].nodes++; Threads[threadID].nodes++;
if(threadID == 0) { if (threadID == 0)
{
NodesSincePoll++; NodesSincePoll++;
if(NodesSincePoll >= NodesBetweenPolls) { if (NodesSincePoll >= NodesBetweenPolls)
{
poll(); poll();
NodesSincePoll = 0; NodesSincePoll = 0;
} }
} }
ss[ply].init(ply); ss[ply].init(ply);
ss[ply+2].initKillers(); ss[ply+2].initKillers();
@ -2116,53 +2117,53 @@ namespace {
if (m2 == MOVE_NONE) if (m2 == MOVE_NONE)
return false; 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); f2 = move_from(m2);
t1 = move_to(m1); t1 = move_to(m1);
if (f2 == t1) if (f2 == t1)
return true; 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); t2 = move_to(m2);
f1 = move_from(m1); f1 = move_from(m1);
if (t2 == f1) if (t2 == f1)
return true; return true;
// Case 3: Moving through the vacated square: // Case 3: Moving through the vacated square
if(piece_is_slider(pos.piece_on(f2)) && if ( piece_is_slider(pos.piece_on(f2))
bit_is_set(squares_between(f2, t2), f1)) && bit_is_set(squares_between(f2, t2), f1))
return true; return true;
// Case 4: The destination square for m2 is attacked by the moving piece // Case 4: The destination square for m2 is attacked by the moving piece in m1
// in m1:
if (pos.piece_attacks_square(pos.piece_on(t1), t1, t2)) if (pos.piece_attacks_square(pos.piece_on(t1), t1, t2))
return true; return true;
// Case 5: Discovered check, checking piece is the piece moved in m1: // Case 5: Discovered check, checking piece is the piece moved in m1
if(piece_is_slider(pos.piece_on(t1)) && if ( piece_is_slider(pos.piece_on(t1))
bit_is_set(squares_between(t1, pos.king_square(pos.side_to_move())), && bit_is_set(squares_between(t1, pos.king_square(pos.side_to_move())), f2)
f2) && && !bit_is_set(squares_between(t2, pos.king_square(pos.side_to_move())), t2))
!bit_is_set(squares_between(t2, pos.king_square(pos.side_to_move())), {
t2)) {
Bitboard occ = pos.occupied_squares(); Bitboard occ = pos.occupied_squares();
Color us = pos.side_to_move(); Color us = pos.side_to_move();
Square ksq = pos.king_square(us); Square ksq = pos.king_square(us);
clear_bit(&occ, f2); 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)) if (bit_is_set(bishop_attacks_bb(ksq, occ), t1))
return true; 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)) if (bit_is_set(rook_attacks_bb(ksq, occ), t1))
return true; return true;
} }
else { else
{
assert(pos.type_of_piece_on(t1) == QUEEN); assert(pos.type_of_piece_on(t1) == QUEEN);
if (bit_is_set(queen_attacks_bb(ksq, occ), t1)) if (bit_is_set(queen_attacks_bb(ksq, occ), t1))
return true; return true;
} }
} }
return false; return false;
} }
@ -2264,9 +2265,8 @@ namespace {
// complicated endgames, e.g. KQ vs KR. FIXME // complicated endgames, e.g. KQ vs KR. FIXME
bool ok_to_do_nullmove(const Position& pos) { bool ok_to_do_nullmove(const Position& pos) {
if(pos.non_pawn_material(pos.side_to_move()) == Value(0))
return false; return pos.non_pawn_material(pos.side_to_move()) != Value(0);
return true;
} }
@ -2275,7 +2275,6 @@ namespace {
// candidates for pruning. // candidates for pruning.
bool ok_to_prune(const Position& pos, Move m, Move threat, Depth d, const History& H) { 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(move_is_ok(m));
assert(threat == MOVE_NONE || move_is_ok(threat)); assert(threat == MOVE_NONE || move_is_ok(threat));
@ -2285,12 +2284,14 @@ namespace {
assert(!pos.move_is_passed_pawn_push(m)); assert(!pos.move_is_passed_pawn_push(m));
assert(d >= OnePly); assert(d >= OnePly);
Square mfrom, mto, tfrom, tto;
mfrom = move_from(m); mfrom = move_from(m);
mto = move_to(m); mto = move_to(m);
tfrom = move_from(threat); tfrom = move_from(threat);
tto = move_to(threat); tto = move_to(threat);
// Case 1: Castling moves are never pruned. // Case 1: Castling moves are never pruned
if (move_is_castle(m)) if (move_is_castle(m))
return false; return false;
@ -2308,7 +2309,7 @@ namespace {
&& pos.move_attacks_square(m, tto)) && pos.move_attacks_square(m, tto))
return false; 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)) if (!H.ok_to_prune(pos.piece_on(mfrom), mto, d))
return false; return false;
@ -2386,9 +2387,11 @@ namespace {
// is used for time managment. // is used for time managment.
bool fail_high_ply_1() { bool fail_high_ply_1() {
for(int i = 0; i < ActiveThreads; i++) for(int i = 0; i < ActiveThreads; i++)
if (Threads[i].failHighPly1) if (Threads[i].failHighPly1)
return true; return true;
return false; return false;
} }
@ -2487,6 +2490,7 @@ namespace {
// it correctly predicted the opponent's move. // it correctly predicted the opponent's move.
void ponderhit() { void ponderhit() {
int t = current_search_time(); int t = current_search_time();
PonderSearch = false; PonderSearch = false;
if (Iteration >= 3 && if (Iteration >= 3 &&
@ -2504,14 +2508,17 @@ namespace {
// thread. Called when the UCI option UCI_ShowCurrLine is 'true'. // thread. Called when the UCI option UCI_ShowCurrLine is 'true'.
void print_current_line(SearchStack ss[], int ply, int threadID) { void print_current_line(SearchStack ss[], int ply, int threadID) {
assert(ply >= 0 && ply < PLY_MAX); assert(ply >= 0 && ply < PLY_MAX);
assert(threadID >= 0 && threadID < ActiveThreads); assert(threadID >= 0 && threadID < ActiveThreads);
if(!Threads[threadID].idle) { if (!Threads[threadID].idle)
{
lock_grab(&IOLock); lock_grab(&IOLock);
std::cout << "info currline " << (threadID + 1); std::cout << "info currline " << (threadID + 1);
for (int p = 0; p < ply; p++) for (int p = 0; p < ply; p++)
std::cout << " " << ss[p].currentMove; std::cout << " " << ss[p].currentMove;
std::cout << std::endl; std::cout << std::endl;
lock_release(&IOLock); lock_release(&IOLock);
} }
@ -2574,7 +2581,7 @@ namespace {
#endif #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) { if(Threads[threadID].workIsWaiting) {
Threads[threadID].workIsWaiting = false; Threads[threadID].workIsWaiting = false;
if(Threads[threadID].splitPoint->pvNode) if(Threads[threadID].splitPoint->pvNode)
@ -2585,7 +2592,7 @@ namespace {
} }
// If this thread is the master of a split point and all threads have // 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) if(waitSp != NULL && waitSp->cpus == 0)
return; return;
} }
@ -2717,18 +2724,18 @@ namespace {
lock_grab(&MPLock); lock_grab(&MPLock);
// If no other thread is available to help us, or if we have too many // 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) || if(!idle_thread_exists(master) ||
Threads[master].activeSplitPoints >= MaxActiveSplitPoints) { Threads[master].activeSplitPoints >= MaxActiveSplitPoints) {
lock_release(&MPLock); lock_release(&MPLock);
return false; 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; splitPoint = SplitPointStack[master] + Threads[master].activeSplitPoints;
Threads[master].activeSplitPoints++; Threads[master].activeSplitPoints++;
// Initialize the split point object: // Initialize the split point object
splitPoint->parent = Threads[master].splitPoint; splitPoint->parent = Threads[master].splitPoint;
splitPoint->finished = false; splitPoint->finished = false;
splitPoint->ply = ply; splitPoint->ply = ply;
@ -2747,11 +2754,11 @@ namespace {
for(i = 0; i < ActiveThreads; i++) for(i = 0; i < ActiveThreads; i++)
splitPoint->slaves[i] = 0; 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)); memcpy(splitPoint->sstack[master], sstck, (ply+1)*sizeof(SearchStack));
Threads[master].splitPoint = splitPoint; 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; for(i = 0; i < ActiveThreads && splitPoint->cpus < MaxThreadsPerSplitPoint;
i++) i++)
if(thread_is_available(i, master)) { if(thread_is_available(i, master)) {
@ -2781,7 +2788,7 @@ namespace {
idle_loop(master, splitPoint); idle_loop(master, splitPoint);
// We have returned from the idle loop, which means that all threads are // 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); lock_grab(&MPLock);
if(pvNode) *alpha = splitPoint->alpha; if(pvNode) *alpha = splitPoint->alpha;
*beta = splitPoint->beta; *beta = splitPoint->beta;