Neuron 101

Solving by search / Alpha-beta pruning

Türkçe

Plate20

Unit 2 · Topic 9 of 10

Alpha-beta pruning

Medium, 8 min, 7 steps

MAXMIN?????????????
Keyboard: left and right arrows change the step, space plays and pauses.

Step 1 of 7 Tree

The same tree, hidden leaves

A game tree like the one in the minimax topic. This time the scores of the leaves are hidden: looking at a leaf means playing that game to the end, and it is expensive. The goal is to open as few leaves as possible.

Open in Colab
  1. def ab(d, a, b, max_mi):
  2. if isinstance(d, int):
  3. return d
  4. if max_mi:
  5. for c in d:
  6. v = ab(c, a, b, False)
  7. a = max(a, v)
  8. return a
  9. for c in d:
  10. b = min(b, ab(c, a, b, True))
  11. if b <= a:
  12. break
  13. return b
  14. agac = agac_uret(0)
  15. inf = float("inf")
  16. print(ab(agac, -inf, inf, True))