calgorithmtimeminimaxgomoku

Gomoku: limited time to search


I'm creating a C program to play Gomoku. It uses Minimax search to decide on the best move. However, it can only search for the best move for 10 seconds. How to I determine when my search function has spent 10 seconds searching. If you could provide me with either an example or a link to the documentation that would be much appreciated.


Solution

  • #include <time.h>
    time_t start_time = time(NULL);
    while (((int)(time(NULL) - start_time)) < 10) {
      //search
    }
    

    That is, what comes to my mind. It is not tested though.