13  Algorithmic Thinking: Building an AI

We will write a function that evaluates the board in this exact order:

  1. Rule 1 (Offense): Can I win on this turn? If yes, take that spot.
  2. Rule 2 (Defense): Is the player about to win on their next turn? If yes, block that spot.
  3. Rule 3 (Strategy): Is a corner open? Take it.
  4. Rule 4 (Default): Take any random empty space.