<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Nesim Razon</title>
    <description>The latest articles on DEV Community by Nesim Razon (@nesimrazon).</description>
    <link>https://dev.to/nesimrazon</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4229210%2Fde7efa93-80bc-4dfe-b69e-a43c10bbb3d3.jpg</url>
      <title>DEV Community: Nesim Razon</title>
      <link>https://dev.to/nesimrazon</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nesimrazon"/>
    <language>en</language>
    <item>
      <title>How We Build Pentomino Levels with Dancing Links</title>
      <dc:creator>Nesim Razon</dc:creator>
      <pubDate>Thu, 12 Nov 2026 18:54:12 +0000</pubDate>
      <link>https://dev.to/nesimrazon/how-we-build-pentomino-levels-with-dancing-links-153h</link>
      <guid>https://dev.to/nesimrazon/how-we-build-pentomino-levels-with-dancing-links-153h</guid>
      <description>&lt;p&gt;Every Fit level in Pentolings is a promise: there is a way to fill this shape with these pieces. To keep that promise in 150 levels, and to give you a hint at any moment, the game contains a small solver based on Donald Knuth's Dancing Links. Here is how it works, using a tiny example anyone can follow.&lt;/p&gt;

&lt;h2&gt;
  
  
  A pentomino puzzle is an exact cover problem
&lt;/h2&gt;

&lt;p&gt;Look at a level as a list of rules. Every piece must be used exactly once. Every square of the shape must be covered exactly once. Nothing may overlap and nothing may be left over. A problem made of rules like these is called an exact cover problem, and a lot of puzzles turn out to be exactly that, from Sudoku to scheduling.&lt;/p&gt;

&lt;p&gt;To get a computer to solve it, we write the problem as a table. Each column is one rule: a column for every piece, and a column for every square of the shape. Each row is one possible move: a specific piece, turned a specific way, placed at a specific spot. A row marks the columns it satisfies: the piece's own column, and the five squares it would cover. The puzzle is solved when you choose rows so that every column is marked exactly once.&lt;/p&gt;

&lt;h2&gt;
  
  
  63 positions: the rows of the table
&lt;/h2&gt;

&lt;p&gt;A pentomino can be turned and flipped, so first the game lists every different position of each of the twelve pieces. It rotates and mirrors the shape and keeps only the results that are really new. X gives 1 position, I gives 2, T, U, V, W and Z give 4 each, and F, L, N, P and Y give 8 each. That adds up to 63 positions for the whole set, a number the code checks.&lt;/p&gt;

&lt;p&gt;Then, for the level's shape, it slides each position to every spot where all five squares lie inside the shape. For a 3x20 rectangle with all twelve pieces, that makes 1236 candidate rows. For the biggest level, a 6x10 rectangle, there are 2056. The table has 72 columns: 12 pieces plus 60 squares.&lt;/p&gt;

&lt;h2&gt;
  
  
  A tiny example
&lt;/h2&gt;

&lt;p&gt;Take a 3x5 rectangle and the pieces P, U and V. The table has 3 piece columns and 15 square columns, so 18 columns in all. The pieces have 40, 20 and 12 possible placements, which gives 72 rows. Choosing three rows that mark every column exactly once gives the answer: V on the left and bottom edges, U on the right, P in the middle. In text, the three rows of the board read VPPUU, VPPPU and VVVUU. Turning or mirroring the whole rectangle gives four versions of the same answer, so the solver finds four solutions that look the same to a person.&lt;/p&gt;

&lt;h2&gt;
  
  
  Knuth's Dancing Links, in plain words
&lt;/h2&gt;

&lt;p&gt;The search is Algorithm X. Pick a column that is not yet covered. Try each row that marks it. Choosing a row means that its other columns are now taken, so every row that conflicts with it can be thrown away. Then repeat with the smaller table. If a column ever has no rows left, you made a wrong choice earlier, so you back up and try the next row.&lt;/p&gt;

&lt;p&gt;The clever part is how the table is stored. Donald Knuth observed that you can keep the marks in linked lists, where every mark points to its left, right, upper and lower neighbor. Removing a row is just re-pointing a few links, and the removed item keeps remembering where it was, so putting it back is a matter of reversing the steps. Because nodes seem to jump out and back in, he called the technique Dancing Links. In Pentolings, Dlx.kt is about eighty lines and works on plain integer arrays for speed.&lt;/p&gt;

&lt;p&gt;One more trick: at each step the solver picks the column with the fewest remaining rows. If a square can be covered in only two ways, the search quickly tests those two instead of wandering around the table. It is the computer version of what we said in the how-to guide: start with the tight spots.&lt;/p&gt;

&lt;h2&gt;
  
  
  Locked pieces and levels that are fair
&lt;/h2&gt;

&lt;p&gt;Some Pentolings levels begin with a locked piece. Those pieces come from a real solution: the generator finds one answer, then freezes one or two of its pieces. The solver treats them as already chosen, removes their squares and columns from the table, and counts what is left.&lt;/p&gt;

&lt;p&gt;Making a level involves more than solving. A generator builds an outline by dropping the pieces next to each other at random, so a solution exists by construction. It then scores many outlines, rewarding solid shapes, penalizing holes and rewarding symmetry, and prefers shapes with more answers in early levels. Because outlines made this way usually have exactly one solution, the difficulty mostly comes from the number of pieces and the odd shape of the outline. Each of the 150 levels is solved again by the tests, checked for duplicates (a rotated or mirrored copy counts as the same), and the final level, a 6x10 rectangle, is the one place with a huge number of answers. A test also confirms the classic count for 3x20: eight, which is the two true answers times four ways to turn or mirror the rectangle.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why not just try everything?
&lt;/h2&gt;

&lt;p&gt;You could solve a puzzle by trying every piece in every position, one after another, and checking at the end. That does not work, even for a computer. With twelve pieces, 63 positions and dozens of spots, the number of combinations is astronomical, and almost all of them overlap or leave gaps in the first few moves.&lt;/p&gt;

&lt;p&gt;The trick is to stop a bad branch as soon as you can see it is bad. Algorithm X does exactly that. The moment one square has no piece that could still cover it, the search stops going deeper and backs up. Dancing Links makes each back-up cheap. This is why a 6x10 board, with 2056 candidate placements, is solved quickly even on a phone, and why the hint button does not need a server.&lt;/p&gt;

&lt;h2&gt;
  
  
  What we learned
&lt;/h2&gt;

&lt;p&gt;The same solver logic exists twice: in Python, where the generator builds and checks the 150-level pack, and in Kotlin, which ships in the app. The Kotlin tests then solve every level of the pack again from scratch. Having two independent implementations means a mistake in one is unlikely to hide from the other.&lt;/p&gt;

&lt;p&gt;The biggest surprise was how rarely a random outline has more than one answer. We expected many puzzles to have several solutions and found the opposite. It turns out that this is fine: players care that a level is solvable and fair, not how many solutions exist, so the game accepts any valid fill. What the solver gives us is the promise that every level, and every hint, can be trusted.&lt;/p&gt;

&lt;h2&gt;
  
  
  Hints come from the same solver
&lt;/h2&gt;

&lt;p&gt;The Hint button asks the solver a new question: given the pieces you have already placed, how does the rest fit? It treats your placed pieces as fixed, solves the remainder and highlights the next piece in the answer it finds. If you follow the hint, the next one can come from memory without solving again. The work runs in the background with a time limit so the screen never freezes.&lt;/p&gt;

&lt;p&gt;If your placed pieces make a solution impossible, the solver finds nothing and the game tells you so: no solution from here, take a piece back. That makes hints useful even when you are not stuck but just unsure. And the game accepts any valid way to fill the shape, not only the one the generator found, so you are never forced to guess the author's answer.&lt;/p&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;What is an exact cover problem?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A problem where you must choose some options so that every item is covered exactly once, with no overlaps and no leftovers. A pentomino puzzle is one.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What are Dancing Links?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A way, published by Donald Knuth, to store a search table in linked lists so that rows can be removed and restored very quickly during a backtracking search.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why do the pieces have 63 positions?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Each of the 12 pieces can be rotated and flipped, and some of those positions look the same. Counting only distinct ones gives 63 across the whole set.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Does the game have only one correct answer per level?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;No. The game accepts any valid way to fill the shape, even if it differs from the one the level was built from.&lt;/p&gt;




&lt;p&gt;If you want to see this in action, Pentolings is free on &lt;a href="https://play.google.com/store/apps/details?id=com.pentolings.nesimapps&amp;amp;referrer=utm_source%3Ddev.to%26utm_medium%3Dpost%26utm_campaign%3Dpentomino-dlx"&gt;Google Play&lt;/a&gt; and needs no account. More notes like this one live on &lt;a href="https://nrazon.github.io/blog/" rel="noopener noreferrer"&gt;my site&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>algorithms</category>
      <category>gamedev</category>
      <category>android</category>
      <category>puzzle</category>
    </item>
    <item>
      <title>Mahjong Solitaire History and How It Differs From Mahjong</title>
      <dc:creator>Nesim Razon</dc:creator>
      <pubDate>Thu, 12 Nov 2026 18:54:11 +0000</pubDate>
      <link>https://dev.to/nesimrazon/mahjong-solitaire-history-and-how-it-differs-from-mahjong-4ln5</link>
      <guid>https://dev.to/nesimrazon/mahjong-solitaire-history-and-how-it-differs-from-mahjong-4ln5</guid>
      <description>&lt;p&gt;Mahjong Solitaire and Mahjong share a name and a set of beautiful tiles, but they are very different games. One is a four-player table game with a long history. The other is a quiet one-player puzzle that started on a computer. This post sketches the history of both and explains what really sets them apart.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two games, one name
&lt;/h2&gt;

&lt;p&gt;Ask people about Mahjong and some will describe four players around a table, clicking tiles and calling out words. Others will describe a tall pile of tiles on a screen that you take apart two at a time. Both are correct, and they are not the same game. The second is properly called Mahjong Solitaire, a matching puzzle. It borrows the look of the tiles, not the rules of the table game.&lt;/p&gt;

&lt;h2&gt;
  
  
  Classic Mahjong in a few lines
&lt;/h2&gt;

&lt;p&gt;Mahjong is a game for four players that is usually dated to China in the nineteenth century. The tiles are drawn and discarded in turn. In the common versions, the aim is to complete a hand of fourteen tiles made of four sets and a pair, before the other players do it. The tiles are marked with three numbered suits, usually called dots, bamboo and characters, plus honor tiles such as winds and dragons. Some sets also include flower and season tiles. There are many regional rule sets, with different scoring and hands, so two groups of players can play quite differently and both call it Mahjong.&lt;/p&gt;

&lt;p&gt;The game is about reading opponents, collecting sets and deciding what to throw away. It is social and competitive.&lt;/p&gt;

&lt;h2&gt;
  
  
  1981: a solitaire game appears on PLATO
&lt;/h2&gt;

&lt;p&gt;The one-player version has a clear starting point. In 1981 Brodie Lockard created a computer game called Mah-Jongg on PLATO, an educational computer system used at universities. It used the tile pictures as pieces of a puzzle. The tiles were stacked in a pile, and you removed matching pairs until the pile was gone. There were no opponents and no hands to build, only the pairs and the structure of the pile.&lt;/p&gt;

&lt;h2&gt;
  
  
  1986: Shanghai brings it to home computers
&lt;/h2&gt;

&lt;p&gt;The idea reached a wide audience in 1986 with Shanghai, published by Activision for home computers. Many people met the game under that name, and for years a lot of players called any such puzzle Shanghai. Versions followed on many other systems. Because the rules fit in a few sentences and a game can be played in minutes, it spread easily.&lt;/p&gt;

&lt;h2&gt;
  
  
  Windows and the arrival on phones
&lt;/h2&gt;

&lt;p&gt;Later, versions of the puzzle appeared inside operating systems and on the web. Windows Vista, for example, included a version named Mahjong Titans. With smartphones came a new wave of versions, with touch controls, hints, daily challenges and many layouts. The basic puzzle has hardly changed in all these years, which says a lot about how well it works.&lt;/p&gt;

&lt;h2&gt;
  
  
  What really differs
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Players: Mahjong needs four players. Mahjong Solitaire is for one.&lt;/li&gt;
&lt;li&gt;Goal: Mahjong is about building a winning hand before the others. Solitaire is about clearing the whole pile.&lt;/li&gt;
&lt;li&gt;Moves: in Mahjong you draw and discard tiles. In Solitaire you remove two matching free tiles at a time.&lt;/li&gt;
&lt;li&gt;Rules of matching: in Mahjong, tiles form sets such as runs of numbers or identical triplets. In Solitaire, only two identical tiles match, and flowers and seasons usually match any other flower or season.&lt;/li&gt;
&lt;li&gt;Structure: Mahjong tiles lie flat in a wall and a hand. Solitaire tiles are stacked in a layout, and a tile is free only when nothing lies on it and one of its sides is open.&lt;/li&gt;
&lt;li&gt;Luck and skill: Mahjong mixes luck, memory and reading people. Solitaire is a puzzle of planning, and a deal can be built so that it always has a solution.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Layouts and the free-tile rule
&lt;/h2&gt;

&lt;p&gt;The layout is what makes each Solitaire game feel different. A well-known arrangement is the turtle, a pyramid-like shape of several layers, but there are countless others: towers, bridges, fields and symbols. The free-tile rule turns the layout into a puzzle: a tile can be taken only if nothing is on top and its left or right side is open. Good players learn to read how the layers depend on each other.&lt;/p&gt;

&lt;h2&gt;
  
  
  Beyond the pile: more tile puzzles
&lt;/h2&gt;

&lt;p&gt;The same tile pictures are used in other games. In some, you link two matching tiles with a path that has a limited number of turns. In others, you collect tiles into a rack and clear groups of three. Tilelings combines all these ideas: classic Mahjong Solitaire layouts, a Connect mode with a two-turn path, and a Tile Match mode with a rack. The tile set has the flowers and seasons that echo the table game, and a cute set for players who prefer something friendlier.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why the puzzle works
&lt;/h2&gt;

&lt;p&gt;A good puzzle has a rule that fits in one sentence and consequences that take a lifetime to explore. Mahjong Solitaire has that. You can only take a free tile, and a tile is free when nothing is on top of it and one of its sides is open. Everything else follows. Some pairs open the board, some close it, and some tiles must wait for others. The challenge is not memory or speed, it is order.&lt;/p&gt;

&lt;p&gt;There is also a quiet feeling of progress. Each pair you remove makes the pile a little smaller and a little easier to read. The last few pairs go fast, like the final pieces of a jigsaw.&lt;/p&gt;

&lt;h2&gt;
  
  
  Which one should you try?
&lt;/h2&gt;

&lt;p&gt;If you enjoy company, noise and friendly rivalry, the four-player table game is wonderful, and it rewards years of play. If you want a few calm minutes alone, the solitaire puzzle is a better fit. Many people enjoy both, and the shared tiles make one a gentle introduction to the other. Start with a small layout, learn to spot free tiles, and the rest will come.&lt;/p&gt;

&lt;h2&gt;
  
  
  A game that kept its charm
&lt;/h2&gt;

&lt;p&gt;Forty years later, a one-player tile puzzle is still easy to learn, calming to play and satisfying to finish. The tiles carry a trace of the table game, but the puzzle stands on its own. Whether you came to it from a family Mahjong table or from a phone, the pleasure is the same: a pile that gets smaller one careful pair at a time.&lt;/p&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Is Mahjong Solitaire the same as Mahjong?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;No. Mahjong is a four-player game of building hands. Mahjong Solitaire is a one-player puzzle where you remove matching pairs of tiles.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Who created Mahjong Solitaire?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The first computer version known as Mah-Jongg was created by Brodie Lockard on the PLATO system in 1981.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why do the games share the tiles?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The puzzle borrowed the tile pictures from the table game, but not its rules.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why do flowers and seasons match any flower or season?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In most solitaire versions they work as bonus tiles that match within their group, which adds flexibility. Tilelings follows this convention.&lt;/p&gt;




&lt;p&gt;If you want to see this in action, Tilelings is free on &lt;a href="https://play.google.com/store/apps/details?id=com.tilelings.nesimapps&amp;amp;referrer=utm_source%3Ddev.to%26utm_medium%3Dpost%26utm_campaign%3Dmahjong-history"&gt;Google Play&lt;/a&gt; and needs no account. More notes like this one live on &lt;a href="https://nrazon.github.io/blog/" rel="noopener noreferrer"&gt;my site&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>gamedev</category>
      <category>history</category>
      <category>android</category>
      <category>puzzle</category>
    </item>
    <item>
      <title>How Hundreds of Puzzle Levels Are Generated and Checked</title>
      <dc:creator>Nesim Razon</dc:creator>
      <pubDate>Thu, 12 Nov 2026 18:52:40 +0000</pubDate>
      <link>https://dev.to/nesimrazon/how-hundreds-of-puzzle-levels-are-generated-and-checked-18gj</link>
      <guid>https://dev.to/nesimrazon/how-hundreds-of-puzzle-levels-are-generated-and-checked-18gj</guid>
      <description>&lt;p&gt;A puzzle game with 300 or 400 levels would take months to draw by hand, and a single unsolvable level ruins the trust of a player. We let the computer build the levels and then prove each one can be solved. This is how that works in our own games.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two programs: a generator and a solver
&lt;/h2&gt;

&lt;p&gt;Almost every generated puzzle needs two pieces of code. The generator proposes a level: a layout of walls, pieces or clues. The solver then plays the level by itself and reports whether it can be finished, in how many moves, and sometimes how many ways there are to do it.&lt;/p&gt;

&lt;p&gt;The solver is the more important of the two. A generator can be sloppy, because anything it produces gets checked. A level only goes into the game if the solver confirms it works. In several of our games the solver is a plain breadth first search over every position the puzzle can reach, which is slow in a big puzzle but exact on a small board.&lt;/p&gt;

&lt;p&gt;A solver also gives us something a human tester cannot: a number. The shortest solution length is a measurement of how long the puzzle is, and that is the starting point for judging difficulty.&lt;/p&gt;

&lt;h2&gt;
  
  
  Working backwards from a solved board
&lt;/h2&gt;

&lt;p&gt;Guessing a random layout and hoping it can be solved wastes a lot of work. A cleverer way is to start from the finished state and undo moves. If every step you take backwards is a legal move played in reverse, the position you reach is guaranteed to be solvable: just play the moves forward again.&lt;/p&gt;

&lt;p&gt;Beamies was designed this way. The generator builds a solvable candidate by working backwards, and the solver is then used mainly to measure how hard it is. Nudgelings uses the same idea in its crate pushing mode: it generates levels by playing the game in reverse, pulling instead of pushing, so the level is solvable by construction. Its sliding vehicle mode takes a different route. There, the generator looks at all the positions connected to a starting layout and searches backwards from the exits, which gives the exact shortest solution for every position at once.&lt;/p&gt;

&lt;p&gt;Working backwards gives you a guarantee, but it does not give you a good puzzle. A level made by a few random reverse steps is often too easy. That is where measuring comes in.&lt;/p&gt;

&lt;h2&gt;
  
  
  Measuring difficulty
&lt;/h2&gt;

&lt;p&gt;Difficulty has no single definition, but a few measurements work well. The simplest is the length of the shortest solution. Longer usually feels harder, because there are more moves to get right and more places to make a mistake.&lt;/p&gt;

&lt;p&gt;For Beamies we measure the minimum number of drags with a search that finds the cheapest solution. The game's levels are given a target for that number which rises with the level, with a gentle sawtooth inside each world: an easier level after a hard one, and a harder one at the end. Nudgelings has a similar plan. Its sliding vehicle levels aim for around 3 moves at the start, 10 near level 20 and more than 40 near the end of 200 levels, and the push mode has its own, lower curve measured in pushes.&lt;/p&gt;

&lt;p&gt;Other measurements capture something different. Grumblings looks at the whole graph of positions and checks, for example, how many of the reachable positions are dead ends, and how often the monster ends up close to the hero. A level where most of the paths are traps feels very different from one where most are safe, even if the shortest solution has the same length.&lt;/p&gt;

&lt;p&gt;Logiclings has a rater for its crown puzzles that solves them with the kinds of reasoning a person uses, from a single possible square up to trying a guess and spotting a contradiction. The puzzle gets the lowest level of technique that is enough to solve it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Hill climbing: improving a level by small changes
&lt;/h2&gt;

&lt;p&gt;A random level is usually easy. To get harder ones we use hill climbing. Take a level, change one small thing, such as moving a wall, an alien or a vehicle, and measure it again. If the level became harder, keep the change. If not, throw it away. Repeat hundreds of times.&lt;/p&gt;

&lt;p&gt;This is simple and it works. In Beamies the shortest solution of a typical candidate went from 4 drags to between 10 and 19 after a few hundred steps of climbing. Nudgelings added the same idea to both of its modes after its first levels turned out too flat for players. Logiclings uses a version of it in its crown puzzles: the generator moves the borders between regions in the way that leaves fewer solutions, until the puzzle has exactly one.&lt;/p&gt;

&lt;p&gt;Climbing has a limit. It can get stuck on a small hill when a better level exists far away, and a level can become hard in a boring way, such as a long forced sequence. That is why we also pick from several candidates and look at the results on a real device.&lt;/p&gt;

&lt;h2&gt;
  
  
  One answer only: uniqueness
&lt;/h2&gt;

&lt;p&gt;Some puzzles must have exactly one solution, otherwise the player can do everything right and still be told they are wrong. This is the case for several of our logic puzzles. The solver is written to count solutions, and it stops as soon as it finds a second one.&lt;/p&gt;

&lt;p&gt;Logiclings builds its two-colour puzzle from a complete board and then removes clues and marks one by one, keeping a removal only if the solver still finds a single answer. The path puzzle starts from a full route through every square, then keeps only the numbers needed for that route to be the only one, and adds a few extra on easier settings.&lt;/p&gt;

&lt;p&gt;Notice that uniqueness and difficulty pull in opposite directions. Fewer clues make a harder puzzle, but too few lose the single answer. The solver is what lets us walk right up to that edge.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pre-generate, then verify every level
&lt;/h2&gt;

&lt;p&gt;Generating a hard level can be slow. In Beamies, making some later levels while the game is running took more than 8 seconds, which is too long to make a player wait. So the 400 levels are built ahead of time on a computer and stored in the app as a file. Every phone then loads exactly the same levels instantly. Grumblings does the same with its 300 levels, which take under a minute to generate together and are picked from a pool of candidates by how hard they score.&lt;/p&gt;

&lt;p&gt;Nothing goes in unchecked. A test in Grumblings opens every level in the pack and replays the stored solution through the real game rules, and a test in Nudgelings checks both of its packs with the solver. If one level fails, the build fails. If the rules change, the pack is generated again.&lt;/p&gt;

&lt;p&gt;The last check is a human one. A computer can tell you that a level is solvable and how long it is. It cannot tell you whether it is fun. We play levels on a phone, and that is where the curve gets adjusted.&lt;/p&gt;

&lt;h2&gt;
  
  
  Mistakes we made
&lt;/h2&gt;

&lt;p&gt;Measuring helped us catch real problems. An early player test of Nudgelings found that its vehicle levels did not feel harder until level 27, so the whole pack was generated again with a steeper curve and new mechanics.&lt;/p&gt;

&lt;p&gt;Solvers also need limits. A search that is fine at generation time can run out of memory on a phone. A Beamies hint and stuck-check once used a solver with no memory limit, and a large level crashed it. We now run those searches with a budget.&lt;/p&gt;

&lt;p&gt;A generated puzzle is only as good as the rule it measures. If you measure the wrong thing, you build a very efficient machine that makes the wrong levels.&lt;/p&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;How do you know a generated level can be solved?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A solver plays it first. Some generators also build levels by working backwards from the finished position, so they are solvable by construction.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is hill climbing in level design?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Making one small change to a level, measuring it again and keeping the change only if the level got harder. Repeating it many times produces much harder levels than random ones.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why not generate levels while the game runs?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Hard levels can take several seconds to make. Building them ahead of time means every player gets the same levels and no one waits.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Does a solver tell you if a level is fun?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;No. It measures things like solution length and dead ends. A person still has to play the level to judge it.&lt;/p&gt;

</description>
      <category>gamedev</category>
      <category>algorithms</category>
      <category>programming</category>
      <category>puzzle</category>
    </item>
    <item>
      <title>How a Daily Puzzle Can Be the Same for Everyone, No Server</title>
      <dc:creator>Nesim Razon</dc:creator>
      <pubDate>Thu, 12 Nov 2026 18:52:39 +0000</pubDate>
      <link>https://dev.to/nesimrazon/how-a-daily-puzzle-can-be-the-same-for-everyone-no-server-1gji</link>
      <guid>https://dev.to/nesimrazon/how-a-daily-puzzle-can-be-the-same-for-everyone-no-server-1gji</guid>
      <description>&lt;p&gt;Many puzzle games offer a daily challenge that is identical for every player, so you can compare scores with friends. It sounds like it needs a server that hands out the puzzle. It does not. Here is how we do it in our own games, and where the limits are.&lt;/p&gt;

&lt;h2&gt;
  
  
  The idea: the date is the puzzle
&lt;/h2&gt;

&lt;p&gt;A computer cannot produce truly random numbers on its own. A random number generator is a recipe: you give it a starting number, called a seed, and it produces a long sequence that looks random. The important part is that the same seed always produces exactly the same sequence.&lt;/p&gt;

&lt;p&gt;That is the whole trick. If every phone turns today's date into a number and uses that number as the seed, every phone builds the same shuffle, the same pieces or the same layout. Nobody has to send anything. The date works as the shared secret that everyone already has.&lt;/p&gt;

&lt;p&gt;In practice the games do not use the raw date as a recipe on its own. They mix it with a few more numbers, such as a puzzle type or a board size, so that different puzzles on the same day do not become copies of each other.&lt;/p&gt;

&lt;h2&gt;
  
  
  What our games actually do
&lt;/h2&gt;

&lt;p&gt;Cubbles turns the local date into a single number in the form year, month, day, for example 20261110, and uses it as the seed for the pieces. Each set of three pieces is drawn from a generator that is started from that day number, the number of the set, and an attempt counter. So the first set of the day is always the same, and so is the second, and so on.&lt;/p&gt;

&lt;p&gt;Cardles uses the day number as the seed for its deals. The shuffling code in the game is its own small, portable random generator, written so that the same seed gives the same deal on every device and every Android version. The type of game also rotates with the calendar, so the daily challenge cycles through four different solitaire games.&lt;/p&gt;

&lt;p&gt;Logiclings builds a pack of three puzzles each day. Its seed combines the day count with the puzzle type and size, and the type rotates through the five kinds of puzzle so each one comes around regularly. Pentolings picks its daily fitting puzzle from a fixed pool of medium levels using the day count, and its daily falling-blocks round uses a seed derived from the day.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why deterministic randomness is enough
&lt;/h2&gt;

&lt;p&gt;The word deterministic means that the result depends only on the inputs. A shuffle that starts from the same seed and goes through the same steps cannot come out differently. As long as the code that builds the puzzle is identical on every phone, the puzzle is identical too.&lt;/p&gt;

&lt;p&gt;This also means that a good daily puzzle is mostly about the builder, not the delivery. In Cardles, for example, a deal is not accepted blindly. Some deals are impossible to win, so the game checks the daily deal and, if it is stuck or cannot be won, tries the next nearby seed in a fixed order. Every phone follows the same order, so every phone ends up on the same deal.&lt;/p&gt;

&lt;p&gt;Cubbles does something similar. A set of three pieces has to be placeable together, so the game tries up to forty seeded attempts and uses the first one that works. We will come back to what that means for fairness in a moment.&lt;/p&gt;

&lt;h2&gt;
  
  
  Time zones: whose midnight?
&lt;/h2&gt;

&lt;p&gt;Without a server there is no single clock that decides when a new day starts. Our games use the date on your own phone. When it is already tomorrow in Sydney, a player in Los Angeles is still on today's puzzle. Both are correct for their own calendar.&lt;/p&gt;

&lt;p&gt;For a single player this is the friendliest choice. The new puzzle appears at your own midnight, and your streak follows your own days. The cost is that a global daily comparison is slightly fuzzy: two people can be playing different days at the same moment.&lt;/p&gt;

&lt;p&gt;A streak is calculated the same way. A streak counts consecutive local days, and the game is forgiving: if you have not played yet today, yesterday still keeps the streak alive until the day is over.&lt;/p&gt;

&lt;h2&gt;
  
  
  Same puzzle, mostly
&lt;/h2&gt;

&lt;p&gt;In the strictest sense a seeded puzzle is identical only if every step depends on the seed and nothing else. Cubbles is an honest example of where that is not quite true. The check that each set of pieces can be placed depends on the state of your board. If an attempt does not fit your board, the game moves to the next attempt, so two players can occasionally see a different set of pieces. Most of the time the first attempt works and everyone sees the same ones, which is why we describe the daily game as the same for nearly everyone rather than for everyone.&lt;/p&gt;

&lt;p&gt;There is another small caveat for puzzles that are picked from a list. If an update changes the list of levels, the pick for a given day can change with it. Players on different versions may then see different puzzles for a few days.&lt;/p&gt;

&lt;p&gt;These are the kinds of details worth deciding on purpose. Either the puzzle depends on nothing but the seed, or you accept a small difference and say so.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cheating, clocks and what no server costs you
&lt;/h2&gt;

&lt;p&gt;The price of skipping a server is trust. The game believes the date on your phone. If you change the clock, you can open another day's puzzle. For a game played for fun, with scores that are shared as a friendly challenge, we think that is an acceptable trade. A server that checks every score would need accounts, storage and care for people's data, and it would be one more thing that can break.&lt;/p&gt;

&lt;p&gt;Scores that go to a leaderboard are reported by the app. A determined person can send a number the game did not earn, and the app cannot fully prevent that. That is why we treat leaderboards as a game between friends and not as a contest with prizes.&lt;/p&gt;

&lt;p&gt;If you ever build one, decide early what the daily puzzle must never depend on. Keep it to the seed, test that two devices produce the same result, and keep the rule that builds the puzzle frozen. If you must change the builder, change it with a new version of the daily and not silently, or yesterday's puzzle will no longer match.&lt;/p&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Does a daily challenge need an internet connection?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In our games, no. The puzzle is built on your phone from the date, so it works offline.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Will my friend in another country get the same puzzle today?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Usually yes, but a new day starts at each player's own midnight, so someone far away may be a day ahead or behind.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Can someone cheat by changing the phone's clock?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;They can open another day's puzzle. Without a server the game trusts the phone's date, so we treat the daily as a friendly challenge.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is a seed?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A starting number for a random number generator. The same seed always gives the same sequence, which is how different devices build the same puzzle.&lt;/p&gt;

</description>
      <category>gamedev</category>
      <category>algorithms</category>
      <category>programming</category>
      <category>android</category>
    </item>
    <item>
      <title>How We Guarantee a Mahjong Solitaire Board Is Solvable</title>
      <dc:creator>Nesim Razon</dc:creator>
      <pubDate>Thu, 12 Nov 2026 18:52:38 +0000</pubDate>
      <link>https://dev.to/nesimrazon/how-we-guarantee-a-mahjong-solitaire-board-is-solvable-flm</link>
      <guid>https://dev.to/nesimrazon/how-we-guarantee-a-mahjong-solitaire-board-is-solvable-flm</guid>
      <description>&lt;p&gt;A Mahjong Solitaire board that cannot be finished is a small betrayal. You spend ten minutes thinking, and then learn that nothing you did could have worked. In Tilelings every deal has a solution, and we do not hope for it: we build it in. This post explains the method in plain language, including where the guarantee stops.&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem with random deals
&lt;/h2&gt;

&lt;p&gt;The obvious way to make a board is to take the tiles, shuffle them and lay them on the layout. It is quick, and it is what many simple games do. The trouble is that Mahjong Solitaire is a game of blocking. Tiles sit on top of each other and beside each other, and a tile can only leave when it is free. If two identical tiles end up in the wrong places, for example one directly on top of the other, neither can ever be removed. A random deal can contain such traps without anyone noticing.&lt;/p&gt;

&lt;p&gt;You could shuffle and then test whether the board can be solved, and shuffle again if not. That works, but testing is a search problem that can be slow on a phone, and it gives you no control over how hard the result is. We chose a different route.&lt;/p&gt;

&lt;h2&gt;
  
  
  The idea: play the game before the tiles exist
&lt;/h2&gt;

&lt;p&gt;Instead of placing pictures first and checking afterwards, we start with a layout that has no pictures at all, only empty positions. Then we play a pretend game of solitaire on it. At every step we look at which positions are free, pick two of them at random, and take them off the board. We write the two positions down. We repeat this until the layout is empty.&lt;/p&gt;

&lt;p&gt;The list we wrote down is a complete sequence of legal moves: each pair was free at the moment it was taken. Now comes the clever part. We hand out the pictures along that list. Pair number one gets two tiles with the same picture, pair number two gets another matching pair, and so on. When you play the finished board, the very same sequence of moves is available to you, because every pair of positions was free in turn and every pair now matches. A solution exists by construction.&lt;/p&gt;

&lt;h2&gt;
  
  
  What happens at a dead end
&lt;/h2&gt;

&lt;p&gt;Choosing pairs at random can paint us into a corner. If two positions are taken and only one free position is left while many tiles remain, the pretend game cannot continue. So the builder keeps a rule: after taking a pair, at least two free positions must remain, unless the board is empty. If the rule fails, the builder steps back and tries a different pair. This is called backtracking.&lt;/p&gt;

&lt;p&gt;To keep it fast on a phone, the search has a limit of a few thousand steps. If it hits the limit, it throws the attempt away and starts again with a fresh random choice. In practice a good sequence is found quickly, and the player never waits.&lt;/p&gt;

&lt;h2&gt;
  
  
  A tiny example
&lt;/h2&gt;

&lt;p&gt;Picture a layout of just six positions in one row, with nothing stacked. A tile in a row is free when its left or right side is open, so only the two end positions are free at the start. We take both ends and note them down as step one. Now the next two positions are the new ends, so we take them as step two, and the last two positions become step three.&lt;/p&gt;

&lt;p&gt;Next we hand out pictures along those steps. Step one gets a sun and a sun, step two a moon and a moon, step three a star and a star. The finished row reads sun, moon, star, star, moon, sun. Play it and you take the suns, then the moons, then the stars: the same order we built. A random shuffle of the same six tiles could produce a row such as sun, star, moon, sun, star, moon, where the suns are never free together. Real layouts have towers and many rows, so the traps are far less obvious, but the idea is exactly the same.&lt;/p&gt;

&lt;h2&gt;
  
  
  Handing out the pictures
&lt;/h2&gt;

&lt;p&gt;Most pictures in the set appear four times. Flowers are four different tiles that all match each other, and so are the seasons. When we assign tiles, we group them into packages: each ordinary picture contributes two pairs, which together make its four tiles. Packages are shuffled and handed out to the steps of the solution.&lt;/p&gt;

&lt;p&gt;On harder levels there is an extra twist. The two pairs of the same picture are spread between the first half and the second half of the solution. That means identical tiles tend to become free at different times, so you cannot simply grab matches that are available together. The board feels tighter and asks for more planning.&lt;/p&gt;

&lt;h2&gt;
  
  
  Choosing the difficulty
&lt;/h2&gt;

&lt;p&gt;For every level we build several candidate deals, six in the current version. Then we measure each one by replaying its solution and counting, at every step, how many matching pairs were available to the player. The average is a good proxy for difficulty. A high average means many choices and a forgiving board. A low average means few choices and a demanding one.&lt;/p&gt;

&lt;p&gt;Easy takes the candidate with the most choices, Hard takes the one with the fewest, and Normal picks the middle one. All three are solvable. The difference is how many ways you have to go wrong.&lt;/p&gt;

&lt;h2&gt;
  
  
  The same seed, the same board
&lt;/h2&gt;

&lt;p&gt;The random choices come from a seeded generator, so a given seed always produces the same board. That is why the daily challenge can be identical for everyone and why a half-finished game can be restored: the game saves only your moves and the seed, and rebuilds the board by replaying them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Shuffle, hints and the honest limit
&lt;/h2&gt;

&lt;p&gt;The guarantee is about the deal you start with. It does not say that every sequence of moves leads to a win. A player can still take a pair that buries the last two copies of a tile, and the board becomes impossible from that point. That is part of the puzzle.&lt;/p&gt;

&lt;p&gt;For those moments the game has helpers. Hint uses a real solver. It searches the current position, tries the moves that free the most tiles first, remembers positions it has already shown to be dead ends, and has a limit on the number of positions it will look at. If it finds a full solution, the hint is the first move of it. If it hits the limit, it falls back to the move that frees the most tiles. Shuffle runs the same backward building process again, this time on the remaining positions, using the remaining pictures grouped into pairs. The shuffled board is solvable again. Very rarely the remaining positions themselves are the problem, for example when two tiles are stacked on each other. Then no shuffle can help, and the game says so, so that you can undo or restart.&lt;/p&gt;

&lt;h2&gt;
  
  
  Connect mode uses the same trick
&lt;/h2&gt;

&lt;p&gt;Connect, the mode where you link tiles with a path of at most two turns, is built the same way. We start with a full grid, repeatedly choose two tiles that can currently be connected, remove them, apply the sliding rule for that level, and record the pair. Pictures are handed out along the recorded list. The board is solvable, and so is the shuffled one.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why we care
&lt;/h2&gt;

&lt;p&gt;Honest difficulty matters. When a puzzle is hard because it asks for planning, it feels fair and you want to try again. When it is hard because the deal was broken, it feels like a trick. Building boards backward lets us promise the first kind. If you ever meet a board that looks impossible, use Undo, take a hint or shuffle. There is always a way through from the start.&lt;/p&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Is every Mahjong Solitaire deal in Tilelings solvable?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Yes. Each deal is built from a legal sequence of moves, so at least one solution exists when you start.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Then how can I get stuck?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Because some sequences of your own moves can bury matching tiles. The guarantee covers the starting deal, not every path.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How does Shuffle stay solvable?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It rebuilds the remaining positions with the same backward method and the remaining pictures.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Are hints always correct?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A hint comes from a search of the current position. If the search finishes, it follows a real solution. If not, it suggests the move that frees the most tiles.&lt;/p&gt;




&lt;p&gt;If you want to see this in action, Tilelings is free on &lt;a href="https://play.google.com/store/apps/details?id=com.tilelings.nesimapps&amp;amp;referrer=utm_source%3Ddev.to%26utm_medium%3Dpost%26utm_campaign%3Dmahjong-solvable"&gt;Google Play&lt;/a&gt; and needs no account. More notes like this one live on &lt;a href="https://nrazon.github.io/blog/" rel="noopener noreferrer"&gt;my site&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>gamedev</category>
      <category>algorithms</category>
      <category>android</category>
      <category>puzzle</category>
    </item>
  </channel>
</rss>
