How do chess engines manage time when they play real games? I was just watching a video on YouTube that analysed a game in between two chess engines. So, chess engines do find good moves but how do they manage their time when they're playing a game ? Is there any algorithm that tells them how much longer they must continue thinking till they make a move, keeping the amount of time left for them in the game in mind ?
Possibilities:


Number of nodes
Fixed depth
Fixed time
Divide a fixed percentage of remaining time
By the complexity of the position


Let's take a quick look at Stockfish. Briefly, the file timemann.cpp calculates the minimum time allowed for a move. The default minimum time allowed is about 20 seconds.

Later, during the search it does:

 // Stop the search if only one legal move is available, or if all
 // of the available time has been used, or if we matched an easyMove
 // from the previous search and just did a fast verification.

 ...

 if (   rootMoves.size() == 1
              || Time.elapsed() &gt; Time.optimum() * unstablePvFactor * improvingFactor / 628
              || (mainThread-&gt;easyMovePlayed = doEasyMove, doEasyMove))


If the position requires longer thinking (unstable position -
 unstablePvFactor), the engine would extend the search. How long it extend depend on calibrated parameters.

If there is an obvious move (doEasyMove), Stockfish plays it immediately.