TinyGames · how it works

Jumble

The letters of a word, in the wrong order. Put them back before the clock runs out; every word you get adds eight seconds to it. Five languages.

Open index.html. No build step, no dependencies, no images — the tiles are drawn.

jumble/
  index.html      markup
  style.css       the frame around the canvas
  js/lexicon.js   shared: the alphabets, the keyboards, the folding rules
  js/anagram.js   the shuffling, the tiles and the arithmetic
                  - no pixels, no engine, no DOM
  js/jumble.js    the playable layer
  test-anagram.js   node test-anagram.js

The shuffle that never finishes

The obvious way to scramble a word is to shuffle until no letter is where it started. That loop does not always end, and the reason is easy to miss.

Take aab. Its arrangements are aab, aba, baa. A derangement would need something other than a at position 0, something other than a at position 1, and something other than b at position 2. baa fails at position 1. aba fails at position 0. There is no third candidate — no derangement of "aab" exists. Ask for one and you wait forever.

Worse, a word whose letters are all the same has exactly one arrangement, so even the weaker "shuffle until it differs from the original" never returns.

So scramble does not demand anything it cannot promise. It takes a bounded number of shuffles, keeps the one with the fewest letters left in place, and returns it. That always finishes, it is as scrambled as the word allows, and for the pathological words it quietly gives back what it was given rather than hanging.

The test feeds it exactly those words — aab, aaaa, abab, aabb — and then, as a negative control, builds the naive version, gives it a budget of 5,000 attempts on aab, and shows it exhausts every one. The same function finds a derangement of an ordinary word on the first try, so the budget is not what is doing the work.

$ node test-anagram.js
67 passed, 0 failed

Repeated letters, again

With two T's in otter, either tile will do. A puzzle that insisted on the "right" one would be unsolvable in a way the player could not possibly see, so built compares the word rather than the tile identities, and the test spells otter both ways round to prove it.


What the tests are worth

Six mutants. Five broke something real; the sixth changed nothing on purpose.

mutation result
scramble drops a letter caught (10 assertions)
scramble hands back the word unshuffled caught (7)
useHint always refuses caught (5)
placeTile ignores which tiles are used caught (3)
built ignores empty places caught (1)
built wrapped, behaviour unchanged passes, as it should

Tiles, not a keyboard

The one place this game deliberately differs from Hangman and Quintet. The letters are all in front of you already; a keyboard would ask you to find them again on a different layout, and on a phone it would eat the half of the screen the tiles need.

Typing still works for anyone who has a real keyboard, and it moves the tiles rather than bypassing them — so what happens on screen is the same thing either way.

A tile that has been placed leaves its space behind in the rack rather than closing it up. Letters that shuffled along every time one was taken would move under the finger reaching for them.

Playing it

Tap a tile to place it, tap a placed letter to take it back. Hint puts the next correct letter where it belongs and costs six seconds; Clear empties the word. A physical keyboard types, Backspace takes back, Escape or P pauses.

Words are four to eight letters. Below four an anagram is not much of a puzzle; above eight the tiles stop fitting on a phone.