Chapter 3

Intelligent search

Informed search means that the algorithm has some context of the specific problem being solved, instead of blindly searching breadth-first or depth-first. Heuristics are a way to represent this information. Often called a rule of thumb, a heuristic is a rule or set of rules used to evaluate a state. It can be used to define criteria that a state must satisfy or measure the performance of a specific state. A heuristic is used when a clear method of finding an optimal solution is not possible. A heuristic can be interpreted as an educated guess and should be seen more as a guideline rather than as a scientific truth with respect to the problem that is being solved. When you’re ordering a pizza at a restaurant, for example, your heuristic of how good it is may be defined by the ingredients and type of base used. If you enjoy extra tomato sauce, extra cheese, mushrooms, and pineapple on a thick base with crunchy crust, a pizza that includes more of these will be more appealing to you and achieve a better score for your heuristic. A pizza that contains fewer of those attributes will be less appealing and achieve a poorer score.

Adversarial search is characterized by opposition or conflict. Adversarial problems require us to anticipate, understand, and counteract the actions of the opponent in pursuit of a goal. Examples of adversarial problems include two-player turn-based games such as Tic-Tac-Toe and Connect Four. The players take turns for the opportunity to change the state of the environment of the game to their favor. A set of rules dictates how the environment may be changed and what the winning and end states are. These are often called Zero-Sum Games: for one player to win (+10), the other must lose (-10). The total sum of the outcome is always zero.

Let’s explore the game of Connect Four to explore adversarial problems. Connect Four is a game consisting of a grid in which players take turns dropping tokens into one of the columns. The tokens in a specific column pile up, and any player who manages to create four adjacent sequences of their tokens—vertically, horizontally, or diagonally wins. If the grid is full, with no winner, the game results in a draw.

Connect Four

Minimax search aims to build a tree of possible outcomes based on moves that each player could make and favor paths that are advantageous to the agent while avoiding paths that are favorable to the opponent. To do so, this type of search simulates possible moves assuming that both players play perfectly. The opponent will always choose the move that hurts the agent most, and the agent will always choose the move that helps itself most. Because the full game tree is usually too large to search completely, the algorithm only looks ahead to a specified depth. A depth of 4, for example, means that each player has had 2 turns. Player A makes a move, player B makes a move, player A makes another move, and player B makes another move.

Heuristics

The minimax algorithm uses a heuristic score to make decisions. This score is defined by a crafted heuristic and is not automatically learned by the algorithm. If we have a specific game state, every possible valid outcome of a move from that state will be a child node in the game tree.

Assume that we have a heuristic that provides a score in which positive numbers are better than negative numbers. By simulating every possible valid move, the minimax search algorithm tries to avoid moves where the opponent will gain an advantage and favor moves that strengthen the agent’s position.

Minimax algorithm

To use minimax search in the Connect Four example, the algorithm evaluates all possible moves from a current game state, then all possible responses to those moves, until it reaches the search depth limit. Game states that result in a win for the agent return a score of 10, and states that result in a win for the opponent return a score of -10. Minimax tries to maximize the positive score for the agent while assuming the opponent will do the opposite.

Why pruning matters

Even in a game as approachable as Connect Four, the number of possible futures grows quickly. From a single position, the algorithm may need to consider several legal moves, then several responses to each of those, then several replies to those responses. That branching explosion is why heuristics and pruning matter so much. Without them, intelligent search would become too slow to feel intelligent.

Try to beat the AI at Connect Four

The game below is Connect Four. Try to create a row, column, or diagonal of four tokens of your color to win the game. The AI will try to prevent you from winning and win for itself. Start a new game, make your first move, and then watch the AI thinking section to see how the search tree and evaluation scores change in response. You can also increase the search depth to make the opponent stronger, though that usually means more search work and slower thinking.

This toy only searches a shallow slice of the full game tree, but that is enough to reveal the core idea: intelligent play often comes from evaluating promising futures, not from checking everything exhaustively.

Play Connect Four

Drop your discs to connect four in a row before the AI does.

Turn You
Moves 0
Select a circle to drop your first disc and start the game.
You AI Winning line
Depth 4
Nodes 0
Pruned 0

Intelligent Search Frequently Asked Questions (FAQ)

What is adversarial search?

Adversarial search is search in situations where another agent is actively trying to stop you from winning. Game-playing AI is a common example because every move must account for an opponent's best possible response.

How does the minimax algorithm work?

Minimax evaluates future game states by assuming the current player tries to maximize the score while the opponent tries to minimize it. That lets the AI choose moves based on likely best-play outcomes instead of just the immediate board position.

What does minimax optimize for?

Minimax tries to choose the move that leads to the best guaranteed outcome, assuming the opponent also plays well. It is a cautious but powerful way to reason in competitive games.

What is a game tree?

A game tree is a branching structure of possible moves and replies. Each level represents a future turn, and the AI evaluates that tree to estimate which present move is strongest.

What is a heuristic in game-playing AI?

A heuristic is a scoring rule that estimates how good a position is without fully solving the game. It matters because most interesting games are too large to search exhaustively.

Why is alpha-beta pruning important?

Alpha-beta pruning cuts away branches of the game tree that cannot improve the final decision. This makes minimax much faster, which is why the AI can look ahead more moves without checking every possible line.

Does alpha-beta pruning change the answer?

No, when implemented correctly it reaches the same decision as minimax would without pruning. It simply avoids wasting time on branches that cannot affect the result.

Why does search depth matter in Connect Four?

Search depth determines how many future moves the AI considers. A deeper search usually produces stronger play, but it also increases the amount of computation needed.

Why can't the AI just brute force every possible game?

The number of possible game states grows extremely quickly. Even for games that seem simple, exhaustive search becomes too expensive unless you use heuristics, pruning, or specialized optimizations.

What does the Connect Four demo teach beyond the game itself?

It shows how intelligent search combines look-ahead, evaluation, and pruning. Those same ideas appear in many decision-making systems where actions must be chosen under competition or uncertainty.

What should I pay attention to in the simulation?

Watch how the AI's move quality changes with search depth, and notice the node and prune counts. They make the computational cost of stronger play visible.