Skip to content

Pacman from DFS and BFS to A* | Berkeley CS188 Topic Guide

Aug 22, 20261 min
TL;DRLectures 1–4 and Project 1 connect DFS, BFS, UCS, A*, state representation, and heuristic design. The goal is not memorizing algorithms but separating what the frontier, cost, and state each control.

🌏 中文版

Video status: Videos included. Source details

The opening unit of CS188 asks how an agent should expand possible states when it does not know the solution path. The Lectures 1–4 schedule covers agents, uninformed search, A*, and local search. Project 1 turns that sequence into implementations of DFS, BFS, UCS, and A*, followed by heuristic design for corners and food search.

Fix the common skeleton first

All four graph-search methods share a loop: remove a node from the frontier, test the goal, expand successors, and avoid repeated states. DFS and BFS change frontier order; UCS orders by accumulated cost; A* adds an estimate of remaining cost. Four largely duplicated implementations usually mean the shared abstraction has been missed.

State is harder than the formula

P1 explicitly warns against using the entire GameState as the corners search state. Two positions can be identical while differing in which corners were visited, which changes the future objective. Ghost data and irrelevant food, however, should not inflate the state. A useful representation retains exactly what affects future legal actions and goal tests.

Heuristics must balance speed with correctness. The official P1 specification requires a consistent food heuristic. An impressive-looking estimate that overreaches can remove A*'s guarantee. Begin with a lower bound you can justify, then use the autograder to inspect expansions rather than reverse-engineering a score threshold.

A practical order

  1. Write the frontier rule for all four algorithms before coding.
  2. Implement DFS and BFS; observe how expansion order changes the path.
  3. Implement UCS and A*; test path cost separately from the heuristic.
  4. Describe in one sentence what your corners-state tuple predicts.
  5. Run one question or test case at a time. The local autograder is enough; Gradescope is not required.

After P1, retain three questions: does the state preserve necessary information, what preference does the frontier encode, and does the heuristic provide only a safe directional estimate? Those questions return in MDPs, Bayes nets, and planning.

Series navigation: Previous: Course overview | Next: CSPs and multi-agent search

Course video sources

The official Spring 2026 schedule and the official YouTube playlist ([CS188 SP26] Live Lectures, 28 videos) were checked live on 2026-10-10; the lecture recording embedded here is listed there as a “Recording”. No unverified timestamp is supplied.

YouTube:CS188 Spring 2026 Lecture 1: Intro, Agents, and Environments

Original videos: CS188 Spring 2026 Lecture 1: Intro, Agents, and Environments

Course and recording entries:

Checked: 2026-10-10.

Content check: verified against the video transcript (2026-10-10): sampled check (only the first ~5,000 characters of the transcript were read): the embedded video is Lecture 1, on course introduction, agents and environments; the early part is course logistics and staff introductions (Dan Klein and Stuart Russell sharing lectures) before moving into the notion of an agent, consistent with this article treating Lecture 1 as the start of the search unit. The remaining sections of this article cover other lectures in the unit and the project, not this video.

Update Log

  • 2026-10-10: Added explicit video status and checked recording sources and access notes.
  • 2026-10-10: Rechecked video status. The official Spring 2026 schedule and YouTube playlist were checked live and list the embedded lecture recording, so the status is now Videos included.
  • 2026-10-10: Checked the video content against its transcript. Confirmed the embedded video is Lecture 1 (course introduction, agents and environments) and fits the article scope; no video claims needed correcting.

References