TutorialsBinary Search

Myth Engine: Crack the Safe

Learn Binary Search by Building a Safe-Cracking Game, Step by Step

Welcome

This is Crack the Safe. Play it first. Every piece of it, you’ll make yourself.

Click the game, then type a guess.

The safe is locked, and the code inside is a whole number from 1 to 100. You have seven scans to find it. These are your keys:

  • Type a guess on the keypad, or with the number keys. Backspace takes away the last digit, and Delete clears it.
  • SCAN, or Enter, asks the safe about your guess.
  • New safe, or R, hides a fresh code and gives you back all seven scans.
  • C, or the Computer cracks it tab, turns the game around. Type a code of your own and press LOCK CODE, or Enter, to seal it. STEP, or Space, lets the computer take one scan, and RUN, or A, lets it scan on by itself.
  • H, or the I crack it tab, hands the safe back to you.
  • F, or the Myth lesson button, opens the lesson panel, and Esc closes it.

The Story

A quiet room in deep navy. In it stands one safe: blue steel, gold plates on every corner, a gold wheel on the door and a small green light beside it.

Type a guess and scan it. The safe won’t open for a wrong number, but it tells you something true: HIGHER THAN 50, or LOWER THAN 75. Each clue rules codes out, and a strip of 100 small marks shows what’s still possible, a teal band that grows thinner with every scan. Find the code, and the safe stands open on gold bars, gold coins and one blue gem.

Then the game turns around. You lock a code, and the computer cracks it with the same scanner you used. It never looks at your code. It only ever tries the middle of what’s left, and for any code from 1 to 100, that takes seven scans or fewer. The lesson panel says it in four words: ONE SCANNER. TWO PLAYERS.

That steady middle guess has a name. It’s binary search. By Chapter 4, you’ll have built it yourself.

What You’ll Build

All of it. Here is the game, in the order the chapters build it:

  • A dark room, a closed safe, and a keypad that answers your fingers. The display starts at 50, and your first digit replaces it.
  • The scanner. SCAN gives a clue, the possible codes close in from both ends, and seven scans are all you get. Find the code, and the safe stands open.
  • The search you can see. A hundred marks, teal where a code is still possible, dark where it’s ruled out, gold where you guessed last, and a card for every scan.
  • The game turned around. Lock a code of your own, press STEP, and the computer takes its turn: always the middle, and never a look at your code.
  • The computer on its own. RUN gives it one turn every 0.9 seconds, slow enough to watch each mark go dark. After your own attempt, Watch computer cracks the very same code beside your result, and the Myth lesson gathers it all on one panel.

Five lines, five chapters. Each chapter ends with a game you can play. Its Goal lets you play it right there on the page, so you can see where you’re going before you start.

How Each Chapter Teaches

Every piece of the game comes to you as a story and a card. The story puts the piece in your head: what it does, and roughly how. The card gives every exact name and number. Read the story, then build from the card with that picture in mind. Then run your game and watch it happen.

Binary search comes the same way. Each chapter shows one more step of it on the screen before it names what you’re seeing.

Making what a card shows is the page for the cards. It shows how to make each kind of card, in the editor’s own words. Read its first two passages before Chapter 1, and come back whenever a card shows you a kind of thing you haven’t made yet.

Every chapter also has a catch-up download in its Goal. It’s that chapter’s finished project. If your game and the chapter part ways, open it and compare the two. Or start the next chapter from it.

Get the Starter Kit

Every picture the game uses comes in one Myth Pack: the safe, closed and open, and the panels, keys and buttons around it. That’s the Starter Kit. Make a new Blank 2D project, and install the Starter Kit into it. Choose File > Install Myth Pack… and pick the file. The window starts on Add to This Project, which is the one you want, so press Install. Chapter 1 starts there.

Crack the Safe Starter KitMyth Pack · 959 KB · every picture

To install it, open Myth Engine, choose File › Install Myth Pack... and pick the downloaded file.

Get the Finished Game’s Project

The game at the top of this page is a project too, and you can open it. It’s the same file as Chapter 5’s catch-up download. Open it whenever you want to see how a finished piece was put together.

Crack the Safe, the finished gameMyth project · 1.8 MB

To open it, start Myth Engine, choose File › Open Project... and pick the downloaded file.

If your own project has changes you haven’t saved, Myth Engine asks first, and offers to save it before it opens this one.

In Chapter 1, the safe draws its code, and nothing can ask it yet. Five chapters from now, it’s the game you played above.