How the Rummy AI Works: Meld Search and Board Manipulation
The opponents on LK Forge Rummy face a puzzle every turn: given the tiles in front of them, what is the best legal way to lay them down? Tile rummy has no dice and no hidden opponent hand to guess — the hard part is the combinatorics of the melds themselves. So the AI is not a sampler like our card games; it is an exact meld-solver.
Runs, groups, and one big search
Every tile you play has to belong to a valid meld: a run (three or more consecutive numbers in one color, like red 4-5-6) or a group (three or four tiles of the same number in different colors). The engine's job is to partition the tiles it can use into the best set of those melds. It decomposes candidate runs, enumerates how groups can be formed, and — crucially — resolves jokers into whatever a meld is missing, all while searching for the arrangement that legally places the most tiles.
Board manipulation: the distinctly rummy part
Here is where tile rummy gets deep. You are not limited to adding tiles to the table as it stands — you may rearrange what's already there: split a run, borrow the odd tile out of a group, recombine everything, as long as the table is left fully valid. That "manipulation" is what lets a single well-chosen tile unlock a big play, and it is exactly the combinatorial part a beginner misses. The AI searches it directly.
The difficulty levels are simply how much of that search the AI is allowed:
- Easy — no manipulation: it only forms new melds and adds to the table as it stands.
- Medium — it tries the simple play first, and only rearranges the table when a plain play would place nothing.
- Hard — it always searches full board manipulation, hunting the arrangement that offloads the most tiles.
// aiMove: the level just controls how much rearranging is allowed function aiMove(state, level) { const ctx = { board: state.board, rack: rackOf(state) }; let move; if (!opened(state)) move = bestMove({ ...ctx, opened: false }); // must reach 30 else if (level === 'easy') move = bestMove({ ...ctx, manipulation: false }); else if (level === 'medium') { move = bestMove({ ...ctx, manipulation: false }); if (!move.feasible || move.tilesPlaced === 0) move = bestMove({ ...ctx, manipulation: true }); // escalate } else move = bestMove({ ...ctx, manipulation: true }); // hard return move.tilesPlaced > 0 ? { type: 'commit', board: move.newBoard } : { type: 'draw' }; // nothing legal → draw }
When nothing fits, draw
If the search can't legally place a single tile — the melds just aren't there yet — the AI does the only sensible thing and draws, exactly as you would. And because the whole search runs in a Web Worker, off the main thread, the board stays responsive even while Hard is grinding through table rearrangements. The same solver powers the Hint button: it runs the Hard search on your rack and lights up the tiles of the best play it finds.
That is the whole engine: treat the turn as a meld-partition problem, resolve jokers, honour the 30-point opening, and — at higher levels — rearrange the whole table to place the most tiles. Curious how our other games decide? See Six Games, Three Classic Algorithms, or why none of them are chatbots in Real Game AI, Not a Chatbot.
FAQ
How does the Rummy AI decide what to play?
The Rummy AI runs an exact meld-solver: it searches the ways your available tiles can be partitioned into valid runs and groups — resolving jokers as it goes — and commits the arrangement that legally places the most tiles. If it cannot place any tile, it draws. The search runs in a Web Worker so the board never freezes.
What is board manipulation and does the AI do it?
Manipulation is rearranging the melds already on the table — splitting a run, borrowing a tile from a group — so that more of your own tiles find a home. It is the hard, distinctly rummy part of the game. On Hard the AI always attempts it; on Medium only when a simple play places nothing; on Easy it never manipulates and just adds to what it can.
How does the AI handle jokers and the 30-point opening?
A joker is resolved to whatever tile a run or group needs, and scores as that tile. Until a player has opened, the solver only accepts an arrangement whose brand-new melds — built entirely from the player's own rack — total at least 30 points, exactly as the rules require. Once a player has opened, that 30-point threshold no longer applies and any legal meld may be played or manipulated.
Does the Rummy AI use a neural network?
No — the Rummy AI is a classical combinatorial search over meld arrangements — a memoized dynamic-programming solver that works rank by rank, trying every way runs and groups can absorb the tiles in play, rather than a trained or learned model. Because rummy's difficulty comes from combinatorics rather than hidden information, exact search reliably finds the best legal placement instead of an approximation. There's no model file, no training and no server call: the tile logic and the AI both run entirely in your browser, inside a Web Worker so the board never freezes while it searches.
Take on the solver — and watch it manipulate the table.
Play Rummy →