ASI AppsWrite

Games and exercises

PsyGames

Crack the Code: logic puzzle rules

Crack the Code puzzle rules: find a hidden row of coloured pegs from black and white feedback. How the clues work, a worked example and strategy tips.

What is Crack the Code?

Crack the Code is a one-player deduction game, a compact kind of Crack the Code puzzle with no grid to fill in. The computer chooses a secret row of coloured pegs and keeps it hidden. You try to reproduce it by making guesses; after each guess you receive a short report that tells you how close you were, and you use that report to make a better guess next time. The game is also known as Mastermind, after the board game, and the open puzzle collection behind the PsyGames version calls it Guess.

Unlike most puzzles on a grid, this one has no board to fill in and no fixed clues. The clues are created by your own guesses, so the quality of the questions you ask is as important as the logic you use to read the answers.

The goal and the rules

Reproduce the hidden sequence of coloured pegs within the allowed number of guesses.

Each guess is a full row of coloured pegs. When you submit it, it is scored with small feedback pegs:

  • a black peg means a peg of the right colour in the right place;
  • a white peg means a peg of the right colour but in the wrong place.

The default setup matches the familiar board game: six colours, four pegs per guess and ten guesses. The classic collection also lets you change those numbers: more colours, more pegs or fewer guesses all make the game harder. It can also allow repeated colours in the code, which makes the search wider; that is switched on by default. The secret is revealed when you solve the puzzle and also when you run out of guesses.

How to play Crack the Code in PsyGames

The app describes the game as deducing the hidden colour code from hit-and-place clues; the description does not define those terms, and in the original collection the clues are the black and white pegs described above. The app’s description does not list its controls, so use the on-screen controls to set up your guess row.

In the desktop collection you drag a coloured peg from the tray into the current guess, you can copy pegs from earlier rows, and a right-click adds a “hold” marker so that a peg is carried forward into the next guess. Once a guess is complete, you click its feedback pegs to mark it and move to the next row. If the app offers a way of carrying pegs forward, it saves a lot of repeated work, because many of your next guesses will keep part of the last one.

A worked example

Take the version with no repeated colours and imagine the secret is red, blue, green, yellow in that order. You do not know it, and you guess red, green, blue, purple.

The score: the first peg, red, is in the right place, so that is one black peg. Green and blue are both in the code but in the wrong places, so that is two white pegs. Purple is not in the code at all and earns nothing. The feedback is one black and two white.

What can you conclude? Three pegs scored in total, and with no repeats that means three of the four colours you used are in the secret and one is not. You also know that exactly one peg is in the right place, but the feedback does not say which one. For the second guess you could move only two pegs, say swap green and blue, and replace one colour with a colour you have not tried yet. Comparing the new black and white counts with the old ones then tells you what those changes did.

Solving tips and common mistakes

A good Crack the Code puzzle strategy is mostly discipline. These habits help.

  1. Learn the colours first. Early guesses should find out which colours are in the code. Spend the first few turns on that before worrying about places.
  2. Keep every guess consistent. A strong habit is to make each new guess one that could still be the secret, given all the feedback so far. A guess that already contradicts an earlier answer cannot be right.
  3. Change one thing at a time when you are stuck. If you move a single peg, the change in black and white counts tells you exactly what that peg did.
  4. Write down what each answer rules out. A feedback of no pegs removes every colour in the guess in a single move, which is the cheapest piece of information in the game.
  5. Use black pegs as anchors. Once you know a peg is in the right place, keep it there and probe the rest of the row.
  6. Be careful with repeats. If duplicates are allowed, a colour may appear twice, and a white peg for it can mean several things. Count how many of that colour the answer could contain.
  7. Do not waste guesses on the same information twice. If a new guess cannot produce a different feedback pattern from one you have already seen, it teaches you nothing.

How Crack the Code differs from similar puzzles

Most puzzles in PsyGames hand you a board of fixed clues. Crack the Code does not, and that makes it feel unlike Minesweeper, where the numbers are already on the board and you only decide how to read them. Here you decide what to ask.

It has more in common with Black Box, because in both you learn about something hidden through indirect reports rather than by seeing it. The reports are different, though: Black Box answers you with what happens to a ray you send in, while Crack the Code answers with counts of right colours and right places. If you prefer clues that do not change as you play, try Tatham’s Unequal.

Crack the Code in PsyGames

In PsyGames, Crack the Code is part of the Counting group. It is based on the open Simon Tatham’s Portable Puzzle Collection (MIT licence), where the same game is named Guess. You can see the whole range in the catalogue of all games. Each new secret is a fresh start, so a Crack the Code puzzle is easy to pick up for a single round.

Frequently asked questions

What do the black and white pegs mean?

A black peg means one of your pegs has the right colour in the right position. A white peg means a right colour in the wrong position. No peg means that colour is not in the code at all, or you have already used up its matches.

Do the pegs in the feedback tell me which of my guesses was right?

No. The feedback only gives you counts. You are told how many are black and how many are white, but never which of your pegs earned each one, and that gap is what you have to reason about.

How many guesses do I get?

The classic setup follows the Mastermind board game: six colours, four pegs per guess and ten guesses. The desktop collection can change all three numbers, and the app's own limits are not listed on this page.

Is Crack the Code the same as Mastermind?

It is the same kind of game. Mastermind is the name of the board game that many people know, and the classic setup of this puzzle matches it.

More logic puzzles

All games

PsyGames: Brain Training

Learn more: PsyGames