Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Trace a Room From File to Verdict

In this video, you followed one room, The Harbourmaster’s Office, through the reference version of the escape room builder from the course downloads, from its room file to its verdict and report lines. You followed it part by part, without reading the code line by line.

Here’s what node check-room.js rooms/the-harbourmasters-office.json printed in the reference version’s folder, the run you traced:

Language: Text
The Harbourmaster's Office: can be finished.
Dead end: the sea chest uses up the brass key, and the lamp-room door still needs it.
Longest chain: the tide board, the lamp-room door, the signal mast (3 puzzles, 25 minutes)
In parallel: the harbourmaster's desk and the tide board
In parallel: the signal mast and the sea chest

Key points:

  • The file goes in: The room starts as rooms/the-harbourmasters-office.json, five puzzles that each list what they need and what they unlock. The sea chest also uses up the brass key.
  • The command reads it: check-room.js reads the file and parses the JSON into a room object. That’s the only check at this step. Nothing checks the room’s shape. If a designer misspells an item in a list, the checker takes it as written, and the verdict can be wrong.
  • Nothing is written: The command only reads. Nothing in this trip writes a file, and the room file never changes.
  • The checker decides the verdict: The command hands the room object to checkRoom() in src/check-room.js, which asks one question: does any solving order finish the room? To answer, it tries every order a team could take. Solving a puzzle adds what it unlocks and removes what it uses up.
  • The order that finishes: The lamp-room door and the sea chest both need the brass key, and the sea chest uses it up, so a team has to solve the lamp-room door first. That order solves every puzzle. One order is enough, because a team chooses its own order. That’s a decision in the project map. The checker hands back “can be finished”, and the command prints it as the first line.
  • The report lines: The command asks missingNeeds() for every room. It names any puzzle whose needs nothing reachable unlocks. It doesn’t count used-up keys. Here nothing is missing, so it adds no lines.
  • The dead end: findDeadEnds() asks a different question: can a used-up key strand a puzzle in some order? Solve the sea chest before the lamp-room door, and the lamp-room door is stuck without the brass key. That’s the dead-end line. As the map’s decisions say, it’s printed even for a room that can be finished, because a team can still walk into a dead end. Last, because the room can be finished, chainReport() adds the longest chain and the puzzles that run in parallel.

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

00:00 In the last lesson, you tested your picture of the project with one change. Now you’ll follow one room through the reference version from the course downloads, from its file to its verdict.

00:12 The room is The Harbourmaster’s Office. Run the check-room command on it, and five lines come back.

00:20 Can you say which part of the project wrote each line? And how can a room with a dead end still be finished? Following the room through the parts answers both, without reading every line of code.

00:34 The room starts as a file in the rooms folder. It has five puzzles. Each one lists what it needs and what it unlocks. The sea chest also uses up the brass key.

00:48 The check-room command reads that file and parses the JSON into a room object. That’s the only check at this step. Nothing checks the room’s shape. If a designer misspells an item in a list, the checker takes it as written, and the verdict can be wrong.

01:05 The command only reads. Nothing in this trip writes a file, and the room file never changes.

01:14 Next, the command hands the room object to the checker, in the source folder. Its checkRoom function asks one question: does any solving order finish the room?

01:25 To answer, it tries every order a team could take. Solving a puzzle adds what it unlocks and removes what it uses up. Look at the lamp-room door and the sea chest.

01:37 Both need the brass key, and the sea chest uses it up. Your turn: pause the video and predict which of the two a team has to solve first to finish the room.

01:48 The lamp-room door. Solve it while you still have the brass key, and every puzzle gets solved. So checkRoom finds an order that finishes the room. One is enough, because a team chooses its own order.

02:03 That’s a decision in the project map. The checker hands back “can be finished”, and the command prints it as the first line.

02:13 Then the command asks the checker for the report lines. First, it asks missingNeeds, for every room. It names any puzzle whose needs nothing reachable unlocks.

02:24 It doesn’t count used-up keys. Here nothing is missing, so it adds no lines.

02:31 Next, findDeadEnds asks a different question: can a used-up key strand a puzzle in some order? Solve the sea chest before the lamp-room door, and the brass key is gone.

02:44 The lamp-room door is stuck. That’s the dead-end line. The project map gives the reason it’s printed for a room that can be finished. A team can still walk into a dead end.

02:57 Last, because the room can be finished, chainReport adds the longest chain and the puzzles that run in parallel. That’s all you need about those lines for now.

03:08 So here’s the whole trip: the command reads the file. The checker decides the verdict, then the missing needs, the dead ends and the chain. The command prints each line, and the room file never changes.

03:24 The reference version’s map describes the same path, under How a Room Moves. One line is a little off. The map says missingNeeds runs only when a room can’t be finished, but the command asks every time.

03:39 For a room that can be finished, missingNeeds hands back nothing, so the output is the same. A map drifts as the code changes.

03:48 To explain a project, follow one input through its parts the way you did here. Say which part does each step, and give the decision behind anything that surprises.

03:59 You never had to read a function line by line.

04:03 Your agent will keep changing these parts. Next, in Keep Your Project Map True, you’ll check your agent’s explanation of a part against the code and a run, and bring your map up to date.

Become a Member to join the conversation.