Contents
Figure 1: Classical AI for Beginners: Search, Planning, and Reasoning Explained — a chess board is still the cleanest picture of states, moves, heuristics, and an opponent who fights back
Before neural networks ate the headlines, AI meant something else: programs that searched through possibilities, planned sequences of actions, and reasoned with explicit rules. Those ideas did not disappear. Your phone's navigation app runs a descendant of A*, your scheduling tools lean on constraint solvers, and chip designers lean on SAT solvers. If you have followed this series on reinforcement learning and graphs, you have already met the rivals your learned models must beat. This article introduces them properly.
I cannot claim I have built production systems with every method below, and I have not run the code in this conversation, so test it yourself. I put the sources at the end, not inline. IMO, classical AI is the best place to build the habit of stating a problem precisely (states, actions, goals, costs), which pays off no matter what technique you use next. Ready?
What "Classical AI" Means
Classical (or symbolic) AI solves problems by manipulating explicit models: states of the world, actions, constraints, and logical statements. Learning-based AI infers a model from data instead. University courses teach the classical toolkit under titles like "AI Problem Solving with Search & Logic," and the current Oxford course is built around search as a unifying idea, from BFS and iterative deepening through optimisation and planning. The standard textbook, Russell and Norvig's Artificial Intelligence: A Modern Approach, organizes the same topics, with chapters on searching, search in complex environments, constraint satisfaction, games, logical agents, first-order logic, and automated planning.
Why bother in the era of deep learning? Because classical methods give you guarantees:
- A shortest path is actually shortest.
- A plan satisfies its preconditions, by construction.
- A SAT answer is correct, and "no solution exists" comes with a proof.
Ever wished your model could say "this is provably optimal"? These can.
Part 1: Search
Almost everything starts here. Represent a problem as states, actions, and a goal, then find a sequence of actions from the start state to a goal state. That single sentence covers a maze, a puzzle, a robot, and half of the interview questions you will ever get about AI.
Uninformed Search
These methods know nothing about where the goal lies:
- Breadth-first search (BFS): expands the shallowest nodes first, finds the fewest-step solution, and uses lots of memory.
- Depth-first search (DFS): dives deep first, uses little memory, but can wander forever or return poor solutions.
- Uniform-cost search: expands the cheapest path so far, finding the lowest-cost solution (Dijkstra's algorithm is the same idea).
- Iterative deepening: repeats depth-limited DFS with growing limits, combining low memory with BFS-like completeness (the Oxford course lists iterative deepening among the core strategies).
Informed (Heuristic) Search
A heuristic estimates the remaining cost to the goal. A* expands the node with the lowest f = g + h, where g is the cost so far and h is the heuristic estimate. AIMA covers A* and its properties, memory-saving variants like IDA* and recursive best-first search, and the two conditions that make the guarantee work:
- Admissible: the heuristic never overestimates the true remaining cost.
- Consistent: the estimate never drops by more than the cost of a single step, like a triangle inequality.
With an admissible heuristic, A* finds an optimal solution (on graphs, consistency makes the guarantee clean). A better heuristic expands fewer nodes. A heuristic of zero turns A* into uniform-cost search.
Try It: BFS, Uniform-Cost, and A* on a Maze
I have not run this code, so test it. It counts how many nodes each method expands:
import heapq
from collections import deque
GRID = [
"S..#......",
".#.#.####.",
".#...#....",
".####.#.##",
"......#..G",
]
R, C = len(GRID), len(GRID[0])
def find(ch):
return next((r, c) for r in range(R) for c in range(C) if GRID[r][c] == ch)
def neighbors(pos):
r, c = pos
for dr, dc in ((1, 0), (-1, 0), (0, 1), (0, -1)):
nr, nc = r + dr, c + dc
if 0 <= nr < R and 0 <= nc < C and GRID[nr][nc] != "#":
yield (nr, nc)
def bfs(start, goal):
frontier, parent, expanded = deque([start]), {start: None}, 0
while frontier:
node = frontier.popleft(); expanded += 1
if node == goal:
return path_to(parent, node), expanded
for nxt in neighbors(node):
if nxt not in parent:
parent[nxt] = node; frontier.append(nxt)
def astar(start, goal, h):
frontier, g, parent, closed, expanded = [(h(start), 0, start)], {start: 0}, {start: None}, set(), 0
while frontier:
_, cost, node = heapq.heappop(frontier)
if node in closed: continue
closed.add(node); expanded += 1
if node == goal:
return path_to(parent, node), expanded
for nxt in neighbors(node):
new_cost = cost + 1
if new_cost < g.get(nxt, float("inf")):
g[nxt], parent[nxt] = new_cost, node
heapq.heappush(frontier, (new_cost + h(nxt), new_cost, nxt))
def path_to(parent, node):
path = []
while node: path.append(node); node = parent[node]
return path[::-1]
start, goal = find("S"), find("G")
manhattan = lambda p: abs(p[0] - goal[0]) + abs(p[1] - goal[1])
for name, result in [("BFS", bfs(start, goal)),
("Uniform-cost (h=0)", astar(start, goal, lambda p: 0)),
("A* (Manhattan)", astar(start, goal, manhattan))]:
path, expanded = result
print(f"{name:20s} path length {len(path) - 1} | nodes expanded {expanded}")
Manhattan distance is admissible on a four-connected grid, because you cannot travel faster than a straight Manhattan route. All three methods should return the same path length, and A should expand fewer nodes.* On a bigger, emptier map, the gap grows dramatically. Try a 200 by 200 grid and watch the numbers.
Local Search
Sometimes you do not want a path, just a good solution: a timetable, a layout, a tour. Local search starts with a complete candidate and improves it. The syllabus lists hill climbing, simulated annealing, and genetic algorithms. They scale well but can get stuck in local optima and give no optimality guarantee. If that sounds like the heuristics in the routing and scheduling articles earlier in this series, it should.
Part 2: Constraint Satisfaction
Many real problems say "find values that satisfy these rules." AIMA uses map colouring, timetabling, and resource allocation as the canonical examples. A constraint satisfaction problem (CSP) has variables, domains, and constraints.
The standard solver is backtracking search: assign a variable, check constraints, undo on failure. The improvements that matter:
- Variable ordering (most constrained first): pick the variable with the fewest remaining legal values.
- Value ordering (least constraining first): try values that leave the most options open.
- Forward checking and constraint propagation: prune options early, before conflicts bite.
- Dependency-directed backtracking and tree-structure tricks: exploit the problem's structure.
AIMA notes that CSPs connect to propositional satisfiability and integer programming, and that they are NP-complete in general. That is why modern solvers, like OR-Tools CP-SAT from the earlier articles, mix many tricks.
Try It: Coloring Australia
The classic map-coloring puzzle, with the "fewest legal values first" heuristic. I have not run this:
NEIGHBORS = {
"WA": ["NT", "SA"], "NT": ["WA", "SA", "Q"],
"SA": ["WA", "NT", "Q", "NSW", "V"], "Q": ["NT", "SA", "NSW"],
"NSW": ["Q", "SA", "V"], "V": ["SA", "NSW"], "T": [],
}
COLORS = ["red", "green", "blue"]
def ok(var, color, assign):
return all(assign.get(n) != color for n in NEIGHBORS[var])
def backtrack(assign):
if len(assign) == len(NEIGHBORS):
return assign
unassigned = [v for v in NEIGHBORS if v not in assign]
var = min(unassigned, key=lambda v: sum(ok(v, c, assign) for c in COLORS)) # fewest legal colors
for color in COLORS:
if ok(var, color, assign):
assign[var] = color
result = backtrack(assign)
if result:
return result
del assign[var]
return None
print(backtrack({}))
Now remove one color and watch it return None: that is the solver proving the puzzle has no solution. Also try the same code on a harder problem, like N-Queens.
Part 3: Adversarial Search and Games
When an opponent fights back, plain search is not enough. Minimax assumes both players play optimally: you maximize your score, the opponent minimizes it. Alpha-beta pruning skips branches that cannot change the outcome, giving the same answer with far fewer nodes. AIMA covers minimax, its shortcomings, alpha-beta improvements, heuristic alpha-beta search, Monte Carlo tree search (MCTS), stochastic games, and partially observable games.
MCTS matters historically: it samples random playouts to estimate move quality instead of relying on a hand-built evaluation function, and it became a key ingredient in modern game-playing systems, most famously AlphaGo.
Try It: Tic-Tac-Toe With Alpha-Beta
LINES = [(0,1,2),(3,4,5),(6,7,8),(0,3,6),(1,4,7),(2,5,8),(0,4,8),(2,4,6)]
def winner(b):
for i, j, k in LINES:
if b[i] and b[i] == b[j] == b[k]:
return b[i]
def alphabeta(b, player, alpha=-2, beta=2):
w = winner(b)
if w: return 1 if w == "X" else -1
if all(b): return 0
if player == "X":
best = -2
for i in range(9):
if not b[i]:
best = max(best, alphabeta(b[:i] + ("X",) + b[i+1:], "O", alpha, beta))
alpha = max(alpha, best)
if alpha >= beta: break # prune: opponent will avoid this branch
return best
best = 2
for i in range(9):
if not b[i]:
best = min(best, alphabeta(b[:i] + ("O",) + b[i+1:], "X", alpha, beta))
beta = min(beta, best)
if alpha >= beta: break
return best
print(alphabeta(("",) * 9, "X")) # expect 0: a draw with perfect play
Add a node counter, then compare it against minimax without pruning. The savings surprise most people. Real games like chess need depth limits plus a heuristic evaluation function, since you cannot search to the end. That is also where classical heuristics and learned policies get compared head to head.
Part 4: Automated Planning
Search finds a path through a given graph. Planning works on a described world: you specify what actions do, and the planner builds a sequence that reaches the goal. The Shakey robot project at SRI gave planning its first widely used language, STRIPS (Fikes and Nilsson, 1971), which later evolved into PDDL, the Planning Domain Definition Language, introduced in 1998.
Classical planning uses a factored representation: the world state is a collection of variables (facts), and each action has preconditions and effects (facts it adds and deletes). AIMA explains the frame problem this way: any action description must say what changes and what stays the same. PDDL uses action schemas, a lifted representation that restricts first-order logic, such as a Fly(plane, from, to) action.
How do planners solve problems?
- Forward (state-space) search and backward search from the goal.
- Partial-order planning: commit to orderings only when forced.
- Planning heuristics derived automatically from the problem description.
- Planning graphs and GraphPlan.
- Planning as satisfiability (SATPLAN): translate the problem into propositional logic and call a SAT solver. AIMA credits Kautz and Selman (1992) with showing this approach can compete with search-based planners.
Planning also differs from scheduling: planning decides which actions to take, and scheduling decides when and with which resources. The two meet in job-shop and vehicle-routing problems, which is exactly where RL policies are measured against classical solvers.
Try It: A Tiny STRIPS-Style Planner
This toy does breadth-first search over fact sets. Real planners, such as Fast Downward, add automatically derived heuristics and far better data structures. I have not run this:
from collections import deque
ACTIONS = { # name: (preconditions, add effects, delete effects)
"take_key": ({"at_A", "key_at_A"}, {"have_key"}, {"key_at_A"}),
"unlock": ({"at_A", "have_key"}, {"door_open"}, set()),
"move_AB": ({"at_A", "door_open"}, {"at_B"}, {"at_A"}),
"move_BA": ({"at_B", "door_open"}, {"at_A"}, {"at_B"}),
}
def plan(start, goal):
start = frozenset(start)
frontier, seen = deque([(start, [])]), {start}
while frontier:
state, steps = frontier.popleft()
if goal <= state:
return steps
for name, (pre, add, delete) in ACTIONS.items():
if pre <= state:
nxt = frozenset((state - delete) | add)
if nxt not in seen:
seen.add(nxt); frontier.append((nxt, steps + [name]))
print(plan({"at_A", "key_at_A"}, {"at_B"})) # ['take_key', 'unlock', 'move_AB']
Notice what the planner does without being told: it discovers it must grab the key and unlock the door before moving. Add a second room and a second key, and watch the search space grow, which is the combinatorial explosion that makes heuristics necessary.
Part 5: Logic and Reasoning
Logic lets a program represent knowledge and derive conclusions. A knowledge-based agent keeps a knowledge base of facts and rules and asks what follows. AIMA illustrates this with the Wumpus World, which remains the best teaching example in the book.
- Propositional logic: statements that are true or false, joined by AND, OR, NOT, and IMPLIES, with syntax, semantics, and theorem proving.
- First-order logic: adds objects, predicates, and quantifiers ("for all," "there exists"), so you can say "every parent of a parent is a grandparent", plus unification and resolution for logic programming.
- SAT solving: deciding whether a propositional formula has a satisfying assignment, taught through the DP and DPLL algorithms, with modern solvers adding clause learning.
That "no solution exists" answer, with proof, is something learned models cannot give you. SAT solvers power verification, planning, and scheduling tools.
Try It: A Tiny DPLL SAT Solver
Clauses use DIMACS-style integers: 1 means variable 1 is true, and -1 means it is false. I have not run this:
def simplify(clauses, lit):
out = []
for c in clauses:
if lit in c:
continue # clause satisfied
reduced = [x for x in c if x != -lit]
if not reduced:
return None # empty clause: conflict
out.append(reduced)
return out
def dpll(clauses, assignment=None):
assignment = dict(assignment or {})
while True: # unit propagation
unit = next((c[0] for c in clauses if len(c) == 1), None)
if unit is None:
break
assignment[abs(unit)] = unit > 0
clauses = simplify(clauses, unit)
if clauses is None:
return None
if not clauses:
return assignment
lit = clauses[0][0] # branch on a literal
for choice in (lit, -lit):
reduced = simplify(clauses, choice)
if reduced is not None:
result = dpll(reduced, {**assignment, abs(choice): choice > 0})
if result is not None:
return result
return None
# (A or B) and (not A or C) and (not B or C) and (not C or D)
print(dpll([[1, 2], [-1, 3], [-2, 3], [-3, 4]]))
It should report that C and D must be true. Now add the clause [-4] and watch it return None: the formula is unsatisfiable.
Where Each Method Shows Up Today
- Shortest paths and navigation: A* and its relatives.
- Scheduling, timetabling, and routing with rules: constraint programming and CP-SAT.
- Games and decision-making under opposition: minimax, alpha-beta, and MCTS.
- Robotics and logistics planning: PDDL planners and hierarchical planning.
- Hardware and software verification, configuration, and test generation: SAT and related solvers.
- Rules and expert systems: logic-based reasoning.
Classical AI vs. Learning: An Honest Comparison
Classical methods win when:
- You have an accurate model of the problem (rules, costs, constraints).
- You need guarantees: optimality, feasibility, or a proof of impossibility.
- You need explanations a human can audit.
- Data is scarce but knowledge is rich.
Learning methods win when:
- The world is too messy to model by hand (perception, language).
- You have lots of data and a good simulator.
- You need fast approximate answers on repetitive problems.
They combine well. A learned model can supply the heuristic for A, propose a warm start for a solver, or translate messy input into a form a planner can use.* The earlier articles on RL for routing and scheduling push the same lesson: always benchmark your learned policy against the classical solver or heuristic. Beating a strong classical baseline is the real test.
How to Learn This
AIMA's fourth edition maps to the topics here: search (Chapters 3 and 4), constraint satisfaction (Chapter 5), games (Chapter 6, including alpha-beta and MCTS), logical agents and first-order logic (Chapters 7 and 8), and automated planning (Chapter 11). The Oxford course page makes a free roadmap even if you never enroll.
- Search: implement BFS, uniform-cost, and A*, then compare node counts on larger mazes.
- CSPs: solve N-Queens and Sudoku with backtracking, then add forward checking.
- Games: build a Connect Four player with alpha-beta and a depth limit.
- Planning: encode a small domain in PDDL and try an existing planner.
- Logic: encode a puzzle as SAT and run a real SAT solver.
- Compare with modern tools: solve the same scheduling problem with OR-Tools.
If you want a gentler on-ramp, the genetic algorithm vs reinforcement learning comparison is a useful bridge between local search and learned policies.
Common Pitfalls to Avoid
- Using an inadmissible heuristic and expecting optimal paths. A* guarantees optimality only with an admissible heuristic.
- Forgetting repeated-state checking. Graph search without a closed set can loop or blow up.
- Choosing variable order at random in CSPs. Ordering heuristics change runtimes by orders of magnitude.
- Treating minimax values as exact in deep games. You need a depth limit and an evaluation function.
- Writing planning domains without thinking about the frame problem. Forgetting delete effects gives impossible plans.
- Assuming all problems need AI. A sort, a shortest-path library call, or a linear program may do.
- Skipping the classical baseline when you try learning-based methods.
- Ignoring scale. Toy code teaches ideas, but real problems need real solvers.
Did you notice that most mistakes involve skipping the precise problem definition? That is the whole lesson.
Best Book to Read
| Cover | Book | Description | Get it |
|---|---|---|---|
![]() |
Artificial Intelligence: A Modern Approach (4th Edition) | the standard reference for search, CSPs, games, logic, and planning, with pseudocode for every algorithm in this article. | View on Amazon |
As an Amazon Associate I earn from qualifying purchases. Links on this page are affiliate links, and I may earn a commission at no extra cost to you.
Read the chapters alongside the code, not before it. The maze, the coloring puzzle, and the SAT solver above map almost one-to-one onto the book's sections, and the exercises are where the ideas actually stick.
Wrapping Up
Classical AI teaches one durable idea: define the problem precisely, then pick the right search or reasoning method. Search explores states, heuristics point the way, CSP solvers satisfy rules, adversarial search handles opponents, planners build action sequences, and logic derives conclusions with proof. Modern systems still lean on all of them, often alongside learning.
So run the maze code this week, then make the grid bigger and watch the node counts diverge between BFS and A*. If A barely expands more than the path length, you just saw why heuristics matter.* If it expands almost everything, congratulations: you built a bad heuristic, and finding out why is the best lesson in the chapter.
Frequently Asked Questions
What is classical AI in simple terms?
Classical AI solves problems by manipulating explicit models: states of the world, actions, constraints, and logical statements. Learning-based AI infers a model from data instead. The classical toolkit is search, constraint satisfaction, adversarial search, planning, and logic with SAT solving.
What is the difference between BFS, uniform-cost search, and A*?
BFS expands the shallowest nodes first and finds the fewest-step solution. Uniform-cost search expands the cheapest path so far and finds the lowest-cost solution, which is Dijkstra's algorithm. A* adds a heuristic and expands the node with the lowest f = g + h, finding an optimal path with fewer expansions when the heuristic is admissible.
What is a heuristic and why does admissibility matter?
A heuristic estimates the remaining cost to the goal. It is admissible when it never overestimates that cost. With an admissible heuristic A* returns an optimal solution; a consistent heuristic, which never drops by more than one step's cost, keeps the guarantee clean on graphs. A zero heuristic turns A* into uniform-cost search.
What is the difference between search and planning?
Search finds a path through a graph you already have. Planning works on a described world: you specify what actions do, with preconditions and add and delete effects, and the planner builds an action sequence that reaches the goal. STRIPS and PDDL are the standard languages for that description.
Is classical AI still useful with deep learning?
Yes. A* descendants run navigation and routing, constraint solvers run scheduling and timetabling, minimax and MCTS run game engines, PDDL planners run robotics and logistics, and SAT solvers run verification, configuration, and test generation. Classical methods also give guarantees and explanations that learned models cannot.
Sources
[1]Russell and Norvig, Artificial Intelligence: A Modern Approach (4th edition) — search, CSPs, games including MCTS, logic, and automated planning: aima.cs.berkeley.edu[2]University of Oxford, AI Problem Solving with Search & Logic — the current course outline covering BFS, DFS, iterative deepening, optimisation, and planning: cs.ox.ac.uk[3]Fikes and Nilsson, STRIPS: A New Approach to the Application of Theorem Proving to Problem Solving (1971) — the Shakey planner and add/delete effects: doi.org[4]Planning Domain Definition Language (PDDL) reference — action schemas, preconditions, and effects in the language STRIPS evolved into: planning.wiki[5]Silver et al., Mastering the Game of Go with Deep Neural Networks and Tree Search (2016) — MCTS combined with learned networks in AlphaGo: nature.com
