official-stockfish / Stockfish

A free and strong UCI chess engine
https://stockfishchess.org/
GNU General Public License v3.0
11.33k stars 2.25k forks source link

How to check whether the game has ended. #1718

Closed lu4 closed 6 years ago

lu4 commented 6 years ago

I've spent last day trying to figure out how to programmatically check game outcome, i.e. draw / white wins / black wins / unknown for a specific position. Is there a simple way to do so?

I have the following piece of code:

    UCI::init(Options);
    PSQT::init();
    Bitboards::init();
    Position::init();
    Bitbases::init();
    Search::init();
    Pawns::init();
    Tablebases::init(Options["SyzygyPath"]); // After Bitboards are set
    Threads.set(Options["Threads"]);
    Search::clear(); // After threads are up

    StateInfo si;
    Position position;

    Thread thread(0);

    position.set("r1bqk1nr/pppp1Qpp/2nb4/4p3/2B1P3/8/PPPP1PPP/RNB1K1NR b KQkq - 0 4", false, &si, &thread);

    for (const Move& move: MoveList<LEGAL>(position)) {
        cout << "1" << endl;
    }

    auto e1 = Eval::trace(position);

    cout << e1 << endl;

The FEN used in this example is a checkmated position, however it is not clear how to get this information from stockfish.

It's obvious though that if the game has ended then there is no moves for a specific side, but what is the outcome of the game?

Thank you in advance!

snicolet commented 6 years ago

@lu4 As this is not really an issue or a bug report, I re-post your question in the fishcooking forum as the forum is probably a better place to get this kind of answer :-) https://groups.google.com/forum/#!topic/fishcooking/x4UYXu7YgFs

lu4 commented 6 years ago

Oh, got it, thanks!