CodeBlanks Logo Icon CodeBlanks

Summary - Game theory and parallel

Print the minimax value in a mini task.

Summary - Game theory and parallel

In this group we covered game theory and parallel algorithms: minimax, alpha-beta pruning, Nash equilibrium, parallel algorithms and MapReduce.

Minimax and alpha-beta make optimal decisions in game trees. Nash equilibrium defines balance in strategic interaction. Parallel algorithms and MapReduce process big data quickly.

We will now revisit minimax with a small task.

Practice minimax mini task

Write minimax(node, is_max). The max player picks the largest, the min player the smallest. Print 2 with print(minimax([[1, 4], [2, 3]], True)).

Starter code

solution.py
def minimax(node, is_max):
    # Simple minimax value

Sample solution

solution.py
def minimax(node, is_max):
    # Simple minimax value
    if not isinstance(node, list):
        return node
    if is_max:
        return max(minimax(child, False) for child in node)
    return min(minimax(child, True) for child in node)
print(minimax([[1, 4], [2, 3]], True))

Expected output

2

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Which method finds the optimal move in a game tree?

  • Greedy
  • BFS
  • Insertion sort
  • Minimax Correct answer

Explanation: Minimax gives the optimal move in a game tree.

2 minimax value

Question
# node = [[1, 4], [2, 3]], is_max = True
# minimax(node, True) = ____
Answer
# node = [[1, 4], [2, 3]], is_max = True
# minimax(node, True) = 2

Explanation: max(min(1,4), min(2,3)) = max(1, 2) = 2.

3 Method-purpose

Term Meaning
minimax Game tree
alpha-beta Pruning
Nash Equilibrium
MapReduce Big data

All lessons in Expert