Understanding the stable matching puzzle
Berth is a puzzle about preferences. Boats and moorings each rank the other side from best to worst, and you swap boats between berths until no pair would rather break away together. The concept comes from a famous problem in mathematics, but the puzzle itself needs no maths at all. This guide explains the rules, the controls, and the thinking that leads to a stable harbour.

What the board shows you
The board displays a set of boats and a set of moorings. There are always the same number of each, so every boat has a berth and no mooring sits empty. Each boat shows a ranked list of the moorings it prefers, best first. Each mooring shows a ranked list of the boats it prefers, also best first. The current pairing is shown by which boat sits in which mooring.
When the pairing has a problem, the board highlights it in red and names the pair underneath. That pair is the trouble: one boat and one mooring that would both prefer each other over their current match. Your job is to rearrange the boats so that no such pair exists anywhere on the board.
What makes a pairing unstable
A pairing is unstable when there is at least one blocking pair. A blocking pair is a boat and a mooring that both prefer each other to what they currently have. Both sides must want the swap, not just one. If a boat wishes it were somewhere else but the mooring it wants is perfectly happy with its current boat, there is no problem. The mooring would refuse, so the deal cannot happen.
Think of it this way. If you locked every boat into its berth and walked away, would any boat and any mooring agree to swap behind your back? If the answer is yes for even one pair, the arrangement is not stable. Stability does not mean everyone is happy. It means nobody can improve by cooperating with someone else. A harbour where every boat sits in its second-worst choice can still be perfectly stable, as long as no mutual improvement is possible.
How to swap boats
Tap one boat, then tap another. The two boats exchange berths. That is the only move in the game. You cannot drag a boat to an empty mooring because there are none. Every swap changes two berths at once, which means fixing one problem can create another somewhere else.
The stats bar above the board tracks how many swaps you have made. The game also shows par, which is the fewest swaps needed to reach any stable pairing. There is often more than one stable arrangement, and reaching any of them counts as a win. Par is measured to the nearest one, not to one specific solution.
Controls and harbour sizes
The Harbour menu sets the size of the puzzle. Small gives a few boats and moorings, which is best for learning how preferences interact. Medium is the standard challenge with more boats and longer preference lists. Large fills the board and demands careful tracking of every list.
The New game button generates a fresh harbour with new preferences and a new starting arrangement. The starting arrangement is always unstable, so there is always work to do. Your time is tracked in the stats bar. Start with small harbours until you can spot blocking pairs quickly, then move up to medium and large when the chain-following habit feels natural.
Strategy: read the red pair first
The board always names one blocking pair in red. Start by giving that boat that mooring. This removes that specific complaint from the board every time, because the pair now has each other and neither wants to leave. The boat that just lost its mooring ends up somewhere else, and that move may or may not create a new complaint.
After the first fix, check whether a new red pair appears. If it does, fix that one the same way. You will often find that the complaints form a short chain: fixing A displaces B, fixing B displaces C, and C settles without complaint. Following the chain instead of jumping around tends to reach stability in fewer swaps. On a medium harbour, most chains close within three or four moves. On a large harbour, you may follow two or three separate chains before the board goes quiet.
Strategy: look for strong preferences
Some moorings rank one boat far above the rest. That boat will almost certainly end up there in any stable pairing, because no other boat can dislodge it. If the mooring wants that boat and the boat is at least willing, the match is solid. Identify these anchors early and build the rest of the arrangement around them.
The same applies the other way. If a boat ranks one mooring far above the rest and that mooring also ranks the boat highly, the pair is almost locked in. Looking for mutual high rankings on both sides gives you fixed points that reduce the number of unknowns. The fewer uncertain slots you leave, the shorter the chain of swaps you need at the end. On a large harbour, finding even two or three anchors at the start can cut the remaining work in half.
Strategy: last choice can still be stable
It is tempting to assume that a boat stuck in its last-choice mooring must be moved. That is not always true. If every mooring that boat prefers already has a boat it likes more, there is no blocking pair and the unhappy boat stays put. Stability is not about fairness. It is about the absence of deals that both sides want.
This insight saves wasted swaps. Before moving a boat out of a low-ranked berth, check whether any mooring it prefers would actually take it. Read the mooring's preference list. If the mooring ranks its current boat higher, the swap does not help and may create a new problem elsewhere. Only move a boat when both sides of the trade benefit.
The idea behind the puzzle
The stable matching problem was studied by David Gale and Lloyd Shapley in 1962. They proved that a stable pairing always exists for any set of complete preference lists, and they gave a step-by-step procedure, now called the deferred-acceptance algorithm, that finds one. In their method, one side proposes and the other side holds the best offer so far while turning the rest away. The rejected proposers move to their next choice, and the process repeats until everyone is matched.
The same idea is used in practice to assign junior doctors to hospitals and children to schools in several countries. Shapley shared the 2012 Nobel Memorial Prize in Economics for this work. In the game, the generator searches across all possible pairings to find the fewest swaps to reach any stable result, so the par number shown on the board is always accurate. The key insight from the theorem is that no matter how tangled the preferences look, at least one stable pairing always exists. You are never stuck with an impossible harbour.
Common beginner mistakes
The most common mistake is treating one side's unhappiness as a problem by itself. A boat wanting a different mooring is not a blocking pair unless the mooring also wants that boat. Check both preference lists before moving anything.
The second mistake is trying to make everyone happy. Some stable pairings leave several boats in low-ranked berths. That is fine as long as no blocking pair exists. Chasing perfect satisfaction leads to endless swapping.
The third mistake is ignoring the chain. When you fix one blocking pair, the displaced boat often creates exactly one new complaint. If you fix that new complaint and then fix the next, the chain usually closes within a handful of swaps. Jumping to a different part of the board instead of following the chain almost always costs extra moves and can undo progress you already made.
Privacy and how the game runs
The entire puzzle runs in your browser. No data is sent to a server, there is no account, and nothing leaves your device. Your best score is stored in local browser storage on this device only. The game works offline once the page has loaded. You can play as many harbours as you like with no limit.
