Play5sDeveloper notes

How a Solitaire Hint Picks a Move and Spots a Stuck Deal

The Hint button in Play5s solitaire never plays a card: it points at one card that has a sensible move, or at the stock, or says that no useful move is left. Klondike ranks moves foundation first, then runs that uncover a hidden card, then the waste. FreeCell removes duplicate moves and walks a five-step preference list. The stuck verdict is the careful part, because the game turns through the whole stock on a copy of the deal before it admits that nothing is left.

This note covers the Hint code of Klondike and FreeCell. Puzzle hints work differently and have their own notes.

In what order does Klondike look for a move?

Klondike Hint looks for1a card that fits a foundation2a whole face-up run onto a column(uncovers a card or a column)3the waste card onto a column4turn the stock5nothing: no useful movethe first rung that fits winsIs the deal stuck?Hint on a copyA real move?not stuckyesnoTurn the stockon the copy onlyNo card to turnstuck
Klondike Hint looks for1a card that fits a foundation2a whole face-up run onto a column3the waste card onto a column4turn the stock5nothing: no useful movethe first rung that fits winsIs the deal stuck?Hint on a copyA real move?noTurn the stockon the copy onlyNo card to turn: stuckyesnotstuck
Left: the order in which Klondike Hint looks for a move. Right: how a request to draw is checked on a copy of the deal before the game admits nothing useful is left.

A hint is only worth pressing if it tends to name the move a good player would make. Klondike's hint() is a short ordered search that returns the first hit:

  1. Any card to its foundation. The sources are the top of the waste and the bottom card of each column, and a card that fits its suit's foundation is always the answer.
  2. A column's whole face-up run onto another column. The move starts at the first face-up card of the column, so it uncovers a face-down card or empties the column. A king that already sits at the base of its column with nothing hidden under it is skipped, because moving it gains nothing.
  3. The waste card onto a column.
  4. Turn the stock, when the stock or the waste still has cards.
  5. Nothing, when none of the above applies.

The run in step 2 is the whole face-up run on purpose. Moving only the lower part of a run leaves a face-up card on top of the same face-down one and uncovers nothing, so the search never proposes it. The ordering also never suggests taking a card down from a foundation, because that step can only be a deliberate player choice.

How does it know a deal is stuck?

Step 4 is not proof of anything. "Turn the stock" only says that the table has no move of its own, and the next card might supply one. Telling the player that the deal is stuck needs more, and hasUsefulMove does the work on a copy:

export function hasUsefulMove(s: State): boolean {
  const x = clone(s);
  const turns = Math.ceil((x.stock.length + x.waste.length) / x.mode) + 1;
  for (let i = 0; i <= turns; i++) {
    const h = hint(x);
    if (h && h !== 'draw') return true;
    if (!draw(x, { fast: true })) return false;
  }
  return false;
}

The copy is made with a JSON round trip, so the player's real table is never touched. The loop runs once per stock turn: with draw 1 that is the number of stock and waste cards, with draw 3 a third of it, plus one for the recycle that puts the waste back. On each turn the same hint() is asked again, and a real move ends the loop with a yes. The fast option makes draw change the copy in place and skip the move log, so the whole scan costs a handful of array operations. If the stock cannot be turned any more, or the loop runs out of turns, the answer is no.

Only then does the interface say "No useful moves left. Try Undo or start a new game." and play the stuck sound. The word is useful. The scan accepts the same moves the hint accepts, so a legal shuffle that uncovers nothing, such as moving a red six from one black seven to the other, does not count. A stuck deal here means no progress is possible, which is what a player wants to know.

How is FreeCell Hint different?

FreeCell has too many legal moves to try them in a fixed scan. legalMoves lists every legal move and prunes duplicates first: one free cell is as good as another, so only the first free cell is a destination, and one empty column is as good as another. Cell to cell, a column onto itself and a whole column into an empty column are dropped as well. The hint then picks from what is left by a five-step preference, written as comments in the source:

FreeCell Hint preferences, in order
RankMove
1Any card to a foundation
2A card out of a cell onto a column
3A run onto a column, preferring a move that uncovers a card the foundation wants next; moves that only shuffle a run already sitting on the card it builds on are skipped, and longer runs win
4Park a card in a cell when that uncovers a card the foundation wants, or a card that can build on a column
5Any move that does not just trade a column for a cell

Two helpers carry the logic. under finds the card beneath the one that moves, which is what the move uncovers. wantedByFoundation is true when that card's rank is one more than the cards already on its suit's foundation. Together they give the hint a sense of purpose: it prefers moves that free the next card the game needs. The list returns nothing only when there is no legal move at all.

How is the answer shown?

Klondike's Hint names a card, not a destination. doHint marks the chosen card, and the cards that travel with it, with the is-hint class for 1.4 seconds, or the stock slot for 1.2 seconds, and plays the hint sound. It also writes a line such as "Try moving the 7 of hearts." into a live region for screen readers, the same mechanism described in the dragging note. The stuck message, and the reason when Undo is refused, are also printed on the table for four seconds. FreeCell's version goes one step further and lights the destination too, the card it would land on, the foundation slot, the free cell or the empty column, and the spoken line says where.

Hint never changes the game. doHint does not call the commit path, and the engine's score table has no entry for a hint, so pressing it costs no points and no moves. The guide covers the player's side in the page on Undo and Hint.

On 27 November 2026, 49 of the 51 open games have a Hint button. Hearts, which sits on the card-game hub, takes a third approach: its Hint asks the computer player what it would pass or play in your seat. The number puzzles use something different again: a solver that can give a reason. Minesweeper, Sudoku and Nonogram each explain a hint by the rule that forces the move, because for those games a hint without a reason is just an answer.