src/arasanx.cpp
// Search using the current board position.
//
Search using the current board position.
Search using the current board position .
static Move search(SearchController *searcher, Board &board, Statistics &stats, bool infinite)
{
    last_stats.clear();
    last_score = Constants::MATE;
    ponder_move = NullMove;
    if (doTrace) cout << "# in search()" << endl;
    Move move = NullMove;
    stats.fromBook = false;
    if (!infinite && options.book.book_enabled && !testing) {
        move = openingBook.pick(board);
        if (!IsNull(move)) stats.fromBook = true;
    }
    if (IsNull(move)) {
        stats.clear();
        TalkLevel level = Silent;
        if (verbose && !uci) level = Debug;
        else if (doTrace) level = Trace;
        else level = Silent;
        if (srctype == FixedDepth) {
            move = searcher->findBestMove(board,
                srctype,
                0,
                0,
                ply_limit, false, uci,
                stats,
                level);
        }
        else {
            if (infinite) {
                time_target = INFINITE_TIME;
            } else {
                time_target =
                    (srctype == FixedTime) ? time_limit :
                    (uci ? calcTimeLimit(movestogo,
                                         getIncrUCI(board.sideToMove()),
                                         time_left, opp_time, false, doTrace)
                     : calcTimeLimit(moves, minutes, incr, time_left, opp_time, false, doTrace));
                last_time_target = time_target;
            }
            if (doTrace) {
                cout << "# entering search, time_target = " << time_target << endl;
                cout << "# xtra time = " << calc_extra_time(board.sideToMove()) << endl;
            }
            move = searcher->findBestMove(board,
                srctype,
                time_target,
                calc_extra_time(board.sideToMove()),
                Constants::MaxPly, false, uci,
                stats,
                level);
        }
        if (doTrace) {
            cout << "# search done : move = ";
            MoveImage(move,cout);
            cout << endl;
        }
        last_stats = stats;
        if (!forceMode) {
            if (testing) {
                post_test(stats);
            }
            else {
                post_output(stats);
            }
        }
    }
    else {
        if (ics || uci) {
            vector< pair<Move,int> > choices;
            int moveCount = 0;
            if (options.book.book_enabled) {
                moveCount = openingBook.book_moves(board,choices);
            }
            stringstream s;
            if (uci)
                s << "info string book moves: (";
            else if (computer)
                s << "tellics kibitz book moves: (";
            else
                s << "tellics whisper book moves: (";
            for (int i=0;i<moveCount;i++) {
                Notation::image(board,choices[i].first,Notation::SAN_OUT,s);
                s << ' ';
                s << (int)(100.0*choices[i].second/(float)book::MAX_WEIGHT + 0.5F);
                if (i < moveCount-1)
                    s << ", ";
            }
            s << "), choosing ";
            Notation::image(board,move,Notation::SAN_OUT,s);
            cout << s.str() << endl;
        }
        stats.clear();
    }
    last_computer_move = move;
    last_computer_stats = stats;
    return move;
}
static Move search ( SearchController * searcher , Board & board , Statistics & stats , bool infinite ) { last_stats . clear ( ) ; last_score = Constants :: MATE ; ponder_move = NullMove ; if ( doTrace ) cout << " " << endl ; Move move = NullMove ; stats . fromBook = false ; if ( ! infinite && options . book . book_enabled && ! testing ) { move = openingBook . pick ( board ) ; if ( ! IsNull ( move ) ) stats . fromBook = true ; } if ( IsNull ( move ) ) { stats . clear ( ) ; TalkLevel level = Silent ; if ( verbose && ! uci ) level = Debug ; else if ( doTrace ) level = Trace ; else level = Silent ; if ( srctype == FixedDepth ) { move = searcher -> findBestMove ( board , srctype , 0 , 0 , ply_limit , false , uci , stats , level ) ; } else { if ( infinite ) { time_target = INFINITE_TIME ; } else { time_target = ( srctype == FixedTime ) ? time_limit : ( uci ? calcTimeLimit ( movestogo , getIncrUCI ( board . sideToMove ( ) ) , time_left , opp_time , false , doTrace ) : calcTimeLimit ( moves , minutes , incr , time_left , opp_time , false , doTrace ) ) ; last_time_target = time_target ; } if ( doTrace ) { cout << " " << time_target << endl ; cout << " " << calc_extra_time ( board . sideToMove ( ) ) << endl ; } move = searcher -> findBestMove ( board , srctype , time_target , calc_extra_time ( board . sideToMove ( ) ) , Constants :: MaxPly , false , uci , stats , level ) ; } if ( doTrace ) { cout << " " ; MoveImage ( move , cout ) ; cout << endl ; } last_stats = stats ; if ( ! forceMode ) { if ( testing ) { post_test ( stats ) ; } else { post_output ( stats ) ; } } } else { if ( ics || uci ) { vector < pair < Move , int > > choices ; int moveCount = 0 ; if ( options . book . book_enabled ) { moveCount = openingBook . book_moves ( board , choices ) ; } stringstream s ; if ( uci ) s << " " ; else if ( computer ) s << " " ; else s << " " ; for ( int i = 0 ; i < moveCount ; i ++ ) { Notation :: image ( board , choices [ i ] . first , Notation :: SAN_OUT , s ) ; s << ' ' ; s << ( int ) ( 100.0 * choices [ i ] . second / ( float ) book :: MAX_WEIGHT + 0.5F ) ; if ( i < moveCount - 1 ) s << " " ; } s << " " ; Notation :: image ( board , move , Notation :: SAN_OUT , s ) ; cout << s . str ( ) << endl ; } stats . clear ( ) ; } last_computer_move = move ; last_computer_stats = stats ; return move ; }
Search using the current board position.
Search using the current board position .
// no book move