And the answer to your question is learn about the stopping problem https://en.wikipedia.org/wiki/Optimal_stopping