Skip to content
Strategy

Code Breaker

Glass pegs, black and white clues: crack the secret code.

The classic deduction game: find the secret combination using black pegs (right place) and white pegs (wrong place). Guess the code, make the AI guess yours, or take it on in a duel.

Players
1 player
Length
6 min
  • Against the AI
  • Solo
  • Online with a friend
Play Code Breaker

15 days of full access, no account · No download

Code Breaker preview

How to play

Goal

Find the secret combination of coloured pegs in as few guesses as possible. After each guess, the code-keeper answers with small pegs:

  • Black: a peg of the right colour in the right place.
  • White: a peg of the right colour, but in the wrong place.
  • The order of the small pegs does not tell you which pegs they refer to.

How to play

  • Tap a colour in the palette (or drag it onto a hole) to fill the current row; tap a peg to remove it.
  • On the keyboard: digits 1 to 8 for the colours, Backspace to erase, Enter to confirm.
  • Format: 4 pegs and 6 colours, or 5 pegs and 8 colours. “By level” picks the first up to the Intermediate level, the second after that.
  • A colour may appear several times in a code (except in the AI’s code at the Beginner level).

Who guesses?

  • You: the AI hides a code; find it before you run out of guesses.
  • The AI: make up your code, then score each of the AI’s guesses with the “right place” and “wrong place” buttons (the game checks your scoring). The AI has 6 guesses in 4 × 6 and 8 guesses in 5 × 8: if your code holds out, you win.
  • Duel: each player hides a code and guesses the other’s, taking turns. The first to find it wins; if you both need the same number of guesses, it is a draw.
Tip: an opening guess with two doubled colours (for example red, red, orange, orange) eliminates many possibilities. After that, only propose codes that are consistent with all the answers received.

About the AI

The solver applies Knuth’s algorithm: for each possible guess, it groups the codes that are still consistent by the answer they would produce, then picks the guess whose worst group is smallest (minimax), preferring a code that is itself consistent. In 4 × 6, a precomputed table of the 1,679,616 answers makes the calculation instant and guarantees a solution in five guesses at most. In 5 × 8 (32,768 codes), it samples guesses within a time limit. At the Beginner to Intermediate levels, the AI reasons like a human player: it remembers most of its clues at the Intermediate level, a little under half at the Amateur level and a quarter at the Beginner level, and sometimes tries a code without checking them. The hint uses the full solver.

AI levels

  1. BeginnerBeginner: 12 guesses for you (4 × 6) and a code with no repeated colour. When it guesses, the AI often forgets its clues.
  2. AmateurAmateur: 10 guesses for you (4 × 6). When it guesses, the AI regularly overlooks a clue.
  3. IntermediateIntermediate: 10 guesses for you (4 × 6). When it guesses, the AI takes most clues into account.
  4. ExpertExpert: large 5 × 8 format by default. When it guesses, the AI minimises the worst case among the compatible codes.
  5. MasterMaster: when it guesses, the AI applies Knuth’s minimax (five guesses at most in 4 × 6): nearly unbeatable.

More strategy games

Lire cette page en français