Alpha-Beta Pruning Implementation

Planning, Dynamics & Decision Systems DS practice problem on Onlearn.

Difficulty: medium.

Topics: Alpha-Beta Pruning Implementation, Minimax Strategy, Alpha-Beta Cutoff, Transposition Tables, Depth-Limited Search, Branching Factor, Artificial Intelligence, Game Theory, Computational Complexity, Search Algorithms, Decision Theory, Adversarial Search, State Space Representation, Heuristic Evaluation, Recursive Backtracking, Branch and Bound.

Implement the alpha beta pruning algorithm for searching game trees. Alpha beta pruning is an optimization of the minimax algorithm that eliminates branches of the search tree which cannot influence the final decision, thereby reducing the number of nodes that need to be evaluated. You are given a game tree represented as a nested list structure: A leaf node is a single number (int or float) An internal node is a list of its children (which can be leaves or further nested lists) The function should perform alpha beta search starting from the root, alternating between maximizing and minimizing players at each level of the tree. Children of each node should be evaluated left to right. A branch should be pruned (skipped) when the current node's value makes further exploration pointless: specifically, when alpha = beta. Return a tuple containing: 1. The optimal minimax value found at the root 2. The total number of leaf nodes that were evaluated during the search The function takes two arguments: tree: the nested list game tree is maximizing: a boolean indicating whether the root player is maximizing (default True)