user10737: 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 ?

user12273: Tom Kerrigan's simple chess program uses a scheme to just check every 1024 nodes if a certain amount of time has passed
basically there is a function called think that has the following lines which we jump back to when the time is up...stop_search is set by a function called checkup()
/* some code that lets us longjmp back here and return
    from think() when our time is up */
    stop_search = FALSE;
    setjmp(env);
    if (stop_search) {

        /* make sure to take back the line we were searching */
        while (ply)
            takeback();
        return;
    }    
    start_time = get_ms();
    stop_time = start_time + max_time;    
    ply = 0;
    nodes = 0;

the following lines are part of the search function that gets called by think()
/* do some housekeeping every 1024 nodes */
if ((nodes & 1023) == 0)
    checkup();

You can see that search() calls checkup() every 1024 nodes. In a more complex scheme the think function could dynamically set the amount of time for the searches. 
void checkup()
{
    /* is the engine's time up? if so, longjmp back to the
       beginning of think() */
    if (get_ms() >= stop_time) {
        stop_search = TRUE;
        longjmp(env, 0);
    }
}


user825: 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() > Time.optimum() * unstablePvFactor * improvingFactor / 628
              || (mainThread->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.

10737: <p>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 ?</p>
 12273: <p>Tom Kerrigan's simple chess program uses a scheme to just check every 1024 nodes if a certain amount of time has passed</p>

<p>basically there is a function called think that has the following lines which we jump back to when the time is up...stop_search is set by a function called checkup()</p>

<pre><code>/* some code that lets us longjmp back here and return
    from think() when our time is up */
    stop_search = FALSE;
    setjmp(env);
    if (stop_search) {

        /* make sure to take back the line we were searching */
        while (ply)
            takeback();
        return;
    }    
    start_time = get_ms();
    stop_time = start_time + max_time;    
    ply = 0;
    nodes = 0;
</code></pre>

<p>the following lines are part of the search function that gets called by think()</p>

<pre><code>/* do some housekeeping every 1024 nodes */
if ((nodes &amp; 1023) == 0)
    checkup();
</code></pre>

<p>You can see that search() calls checkup() every 1024 nodes. In a more complex scheme the think function could dynamically set the amount of time for the searches. </p>

<pre><code>void checkup()
{
    /* is the engine's time up? if so, longjmp back to the
       beginning of think() */
    if (get_ms() &gt;= stop_time) {
        stop_search = TRUE;
        longjmp(env, 0);
    }
}
</code></pre>
 825: <p>Possibilities:</p>

<ul>
<li>Number of nodes</li>
<li>Fixed depth</li>
<li>Fixed time</li>
<li>Divide a fixed percentage of remaining time</li>
<li>By the complexity of the position</li>
</ul>

<p>Let's take a quick look at Stockfish. Briefly, the file <a href="https://github.com/official-stockfish/Stockfish/blob/d8f683760c9eb6d2c4714ec83e717dd2143de55c/src/timeman.cpp" rel="nofollow noreferrer">timemann.cpp</a> calculates the minimum time allowed for a move. The default minimum time allowed is about 20 seconds.</p>

<p>Later, during the <a href="https://github.com/official-stockfish/Stockfish/blob/master/src/search.cpp" rel="nofollow noreferrer">search</a> it does:</p>

<pre><code> // 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))
</code></pre>

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

<p>If there is an obvious move (<code>doEasyMove</code>), Stockfish plays it immediately.</p>
