How it works...

The algorithm works as a bounded Depth-First Search (DFS). In each step, the move is chosen by selecting the option that maximizes the player's score and assuming the opponent will choose the option of minimizing it until a terminal (leaf) node is reached.

The move tracking is done using recursion, and the heuristic for selecting or assuming an option depends on the Evaluate function.

Get Unity 2018 Artificial Intelligence Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.