Move Board::think() { // =========================================================================== // This is the entry point for search, it is intended to drive iterative deepening // The search stops if (whatever comes first): // - there is no legal move (checkmate or stalemate) // - there is only one legal move (in this case we don't need to search) // **later** - time is up // - the search is interrupted by the user, or by winboard // - the search depth is reached // =========================================================================== int score, legalmoves, currentdepth; Move singlemove; // =========================================================================== // Check if the game has ended, or if there is only one legal move, // because then we don't need to search: // =========================================================================== if (isEndOfgame(legalmoves, singlemove)) return NOMOVE; if (legalmoves == 1) { std::cout << "forced move: "; displayMove(singlemove); std::cout << std::endl; return singlemove; } // =========================================================================== // There is more than legal 1 move, so prepare to search: // =========================================================================== lastPVLength = 0; memset(lastPV, 0 , sizeof(lastPV)); memset(whiteHeuristics, 0, sizeof(whiteHeuristics)); memset(blackHeuristics, 0, sizeof(blackHeuristics)); inodes = 0; // display console header displaySearchStats(1, 0, 0); timer.init(); msStart = timer.getms(); // iterative deepening: for (currentdepth = 1; currentdepth <= searchDepth; currentdepth++) { // clear the buffers: memset(moveBufLen, 0, sizeof(moveBufLen)); memset(moveBuffer, 0, sizeof(moveBuffer)); memset(triangularLength, 0, sizeof(triangularLength)); memset(triangularArray, 0, sizeof(triangularArray)); followpv = true; score = alphabetapvs(0, currentdepth, -LARGE_NUMBER, LARGE_NUMBER); msStop = timer.getms(); displaySearchStats(2, currentdepth, score); // stop searching if the current depth leads to a forced mate: if ((score > (CHECKMATESCORE-currentdepth)) || (score < -(CHECKMATESCORE-currentdepth))) currentdepth = searchDepth; } return (lastPV[0]); }
Move Board::think() { // =========================================================================== // This is the entry point for search, it is intended to drive iterative deepening // The search stops if (whatever comes first): // - there is no legal move (checkmate or stalemate) // - there is only one legal move (in this case we don't need to search) // - time is up // - the search is interrupted by the user, or by winboard // - the search depth is reached // =========================================================================== int score, legalmoves, currentdepth; Move singlemove; lastScore = 0; // =========================================================================== // Check if the game has ended, or if there is only one legal move, // because then we don't need to search: // =========================================================================== if (isEndOfgame(legalmoves, singlemove)) return NOMOVE; if (legalmoves == 1) { //LC std::cout << "forced move: "; displayMove(singlemove); std::cout << std::endl; /*if (XB_MODE && XB_POST) { printf("0 0 0 0 "); displayMove(singlemove); std::cout << std::endl; }*/ return singlemove; } // =========================================================================== // There is more than legal 1 move, so prepare to search: // =========================================================================== if (XB_MODE) timeControl(); lastPVLength = 0; memset(lastPV, 0 , sizeof(lastPV)); memset(whiteHeuristics, 0, sizeof(whiteHeuristics)); memset(blackHeuristics, 0, sizeof(blackHeuristics)); inodes = 0; countdown = UPDATEINTERVAL; timedout = false; // display console header displaySearchStats(1, 0, 0); timer.init(); msStart = timer.getms(); // iterative deepening: for (currentdepth = 1; currentdepth <= searchDepth; currentdepth++) { // clear the buffers: memset(moveBufLen, 0, sizeof(moveBufLen)); memset(moveBuffer, 0, sizeof(moveBuffer)); memset(triangularLength, 0, sizeof(triangularLength)); memset(triangularArray, 0, sizeof(triangularArray)); followpv = true; allownull = true; score = alphabetapvs(0, currentdepth, -LARGE_NUMBER, LARGE_NUMBER); lastScore = score; // now check if time is up // if not decide if it makes sense to start another iteration: if (timedout) { //LC std::cout << std::endl; return (lastPV[0]); } else { if (!XB_NO_TIME_LIMIT) { msStop = timer.getms(); if ((msStop - msStart) > (STOPFRAC * maxTime)) { //if (!XB_MODE) std::cout << " ok" << std::endl; return (lastPV[0]); } } } displaySearchStats(2, currentdepth, score); // stop searching if the current depth leads to a forced mate: if ((score > (CHECKMATESCORE-currentdepth)) || (score < -(CHECKMATESCORE-currentdepth))) currentdepth = searchDepth; } return (lastPV[0]); }