This article will teach you about the minimax algorithm and alpha-beta pruning, from a beginner's perspective.
Grab a piece of paper and try to fold your way out of this problem.