int main() { double a, b, c, d; double rootfloor, rootceil; printf("This program will compute the roots of a cubic equation in the form:\n"); puts("Ax^3 + Bx^2 + Cx + D = 0"); printf("--------------------------------------------------------------------\n"); printf("Input the coefficients A, B, C, and the constant D separated by a space:\n"); scanf("%lf %lf %lf %lf", &a, &b, &c, &d); printf("rootSearch Lower limit: "); scanf("%lf", &rootfloor); printf("rootSearch Upper limit: "); scanf("%lf", &rootceil); rootSearch(a, b, c, d, rootfloor, rootceil); runAgain(); return 0; }
// iterative deepening int SimplePVSearch::idSearch(Board& board) { int bestScore = -maxScore; int iterationScore[maxSearchPly]; int64_t iterationTime[maxSearchPly]; board.setInCheck(board.getSideToMove()); MoveIterator::Move easyMove; rootSearchInfo.alpha = -maxScore; rootSearchInfo.beta = maxScore; rootSearchInfo.allowNullMove = false; int lastDepth=0; MoveIterator::Move bestMove; MoveIterator::Move ponderMove; board.generateAllMoves(rootMoves, board.getSideToMove()); filterLegalMoves(board,rootMoves,agent->getSearchMoves()); scoreRootMoves(board,rootMoves); rootMoves.sort(); setCompletedIteration(false); if (rootMoves.get(0).score > rootMoves.get(1).score + easyMargin ) { easyMove=rootMoves.get(0); } PvLine pv = PvLine(); pv.index=0; for (int depth = 1; depth <= depthToSearch; depth++) { int score = 0; int aspirationDelta=0; maxPlySearched = 0; lastDepth=depth; iterationPVChange[depth]=0; rootSearchInfo.depth=depth; rootSearchInfo.ply=0; score=-maxScore; if (depth >= aspirationDepth) { const int delta = iterationScore[depth-1]-iterationScore[depth-2]; aspirationDelta = std::max(delta, 10) + 5; rootSearchInfo.alpha = std::max(iterationScore[depth-1]-aspirationDelta,-maxScore); rootSearchInfo.beta = std::min(iterationScore[depth-1]+aspirationDelta,+maxScore); } bool finished=false; setCompletedIteration(false); rootMoves.clearScore(); while (!finished) { rootMoves.sort(); rootMoves.first(); score = rootSearch(board, rootSearchInfo, pv); rootMoves.sort(); rootMoves.first(); if (!stop(rootSearchInfo)) { setCompletedIteration(true); } iterationScore[depth]=score; updateHashWithPv(board,pv); if (!stop(rootSearchInfo)) { uciOutput(pv, score, getTickCount()-startTime, agent->hashFull(), rootSearchInfo.depth, maxPlySearched, rootSearchInfo.alpha, rootSearchInfo.beta); } const bool fail = score <= rootSearchInfo.alpha || score >= rootSearchInfo.beta; const bool fullWidth = rootSearchInfo.alpha == -maxScore && rootSearchInfo.beta == maxScore; finished = !fail || fullWidth || depth < aspirationDepth || (stop(rootSearchInfo) && depth>1); if (!finished) { rootSearchInfo.alpha = std::max(rootSearchInfo.alpha-aspirationDelta,-maxScore); rootSearchInfo.beta = std::min(rootSearchInfo.beta+aspirationDelta,+maxScore); aspirationDelta = std::max(aspirationDelta*130/100,15); } } if (isCompletedIteration()) { bestMove=pv.moves[0]; ponderMove=pv.moves[1]; if (score > bestScore) { bestScore = score; } } iterationTime[depth]=getTickCount()-startTime; if (stop(rootSearchInfo) && depth > 1) { break; } int repetition=0; for (int x=depth-1;x>=1;x--) { if (score==iterationScore[x]) { repetition++; } else { break; } } if (!(searchFixedDepth || infinite)) { if (depth>5 && (abs(iterationScore[depth]) >= maxScore-maxSearchPly && abs(iterationScore[depth-1]) >= maxScore-maxSearchPly && abs(iterationScore[depth-2]) >= maxScore-maxSearchPly)) { break; } if (repetition >= maxScoreRepetition && iterationScore[depth-0] == drawScore) { break; } if (depth>12) { if (bestMove!=easyMove) { easyMove = MoveIterator::Move(); } } if (depth>10 && rootMoves.size()==1) { break; } if (depth>7) { if (!easyMove.none() && easyMove==bestMove && nodesPerMove[0]>=nodes*85/100 && iterationTime[depth] > timeToSearch/2) { break; } } if (depth > 8 && depth < 40 && iterationPVChange[depth]>0) { agent->addExtraTime(depth,iterationPVChange); } if (iterationTime[depth] > getTimeToSearch()*70/100) { break; } } } if (bestMove.none()) { bestMove=rootMoves.get(0); ponderMove=emptyMove; } uciOutput(pv, bestMove.score, getTickCount()-startTime, agent->hashFull(), lastDepth, maxPlySearched, rootSearchInfo.alpha, rootSearchInfo.beta); uciOutput(bestMove,ponderMove); return bestMove.score; }