Back to workCase study

In internal testing on Google Play

Marine Wobbles

A tap-to-pop match-3 for Android, written natively in Kotlin and Jetpack Compose. This case study covers the engineering: bots that measure how hard each level is, rules ported exactly from my prototype, and purchases that can't be lost or granted twice.

levels in eight chapters
80
strategy bots
7
seeded games per balance run
2.2M
unit tests
455
recorded games replayed exactly
264
languages, English and Spanish
2

The game

Tap a group of matching sea creatures on a six-by-six board to pop it; the rest fall into place. Each of the eight chapters is built around a new mechanic, taught in its first levels and then put to work:

  1. Popping, combos and collecting
  2. Gravity, in four directions
  3. Pearls, and two-colour goals
  4. Coral
  5. Marked and deep patches
  6. Spreading patches
  7. The urchin, which blasts
  8. Stones

Around the board: lives, six boosters, a coin store, and 27 illustrated episodes, each with a map whose sea moves, a level card and a victory scene. Eight of them have levels so far.

Level 2: a group of purple octopuses popping for 1,500 points.
Level 66: urchins and patches to clear, with 55 moves left.

How it's put together

The rules live in their own package of pure Kotlin, with no Android and no Compose in it: the board, gravity, turns, powers, coins, lives, the bots and the tuner. Everything that decides an outcome can run on a plain JVM, which is what makes the testing and the simulations below possible.

  • One immutable session in a StateFlow. The view model holds the game as a data class that is copied on every change; the UI collects it with the lifecycle.
  • A turn is one coroutine. Pop, settle and reshuffle run in the view model's scope, so restarting a level cancels every pending step through structured concurrency, instead of the timer list and run counter the prototype needed.
  • Few dependencies. No navigation library and no dependency injection: screens are state, and the only swappable service, the shop, is an interface chosen by build type.

Measuring difficulty with bots

Seven strategy bots (random, decent, greedy, hoarder, tiler, collector, breaker) call the same rule functions the game ships, so the two can't drift apart. Each level is played 2,000 to 5,000 times per bot from fixed seeds, and a bot chosen per goal type stands in for a typical player.

Every tier has a contract: a band for that player's win rate, a cap on how much luck can carry the best play, a window for when in the move budget the win lands, a minimum gap over random play, and no drop of more than 30 points between neighbouring levels. Tests hold every level to its contract and every tier to being harder than the one before. An auto-tuner records games once per move budget, reads the win rate for any target without replaying them, and proposes fixes; it never edits the level file itself.

The win-rate band for each tier, and how many of the 80 levels sit in it
TierLevelsWin rate
Tutorial885–95%
Easy3970–85%
Medium2245–70%
Hard825–45%
Peak315–25%

A full run is about 2.2 million seeded games and takes some thirteen minutes, so results are cached by content: each measurement is keyed by a hash of the rule sources it ran and the level's own inputs, and the cache is committed, so a change only pays for the levels it touches. Building this exposed a bug in the build: tests that read the level file directly were invisible to Gradle's up-to-date check and reported stale passes, until I declared the file as a task input.

A port that replays exactly

The game started as my React Native prototype, written in TypeScript. The Kotlin rules are a port of it, held to identical results:

  • The random generator is ported bit for bit, with the unsigned-arithmetic traps written down, and pinned by tests against values printed by the TypeScript.
  • 264 whole games recorded from the prototype (44 levels, three play styles, two seeds) replay state for state.
  • The prototype's 220-cell win-rate table comes out identical. Insisting on that caught a speculative “what if” move that was quietly advancing the real deck.

Purchases that can't be lost or doubled

Coin packs are consumable purchases through Google Play Billing, handled in this order:

  1. Grant coins only once a purchase reports as completed.
  2. Save the new balance.
  3. Only then consume the purchase, so a crash in between can't lose money or grant twice.
  4. Treat the purchase token as the key, so the same purchase is never granted again.
  5. Re-check unfinished and pending purchases every time the game comes back to the foreground.

A fake shop that can be told to succeed, wait, fail, cancel or be unreachable let the whole flow be built and tried on a phone before the store account existed. On the internal test track it was verified with test cards: approved, declined, cancelled and slow payments, each granted exactly once. Purchases are verified on the device rather than on a server, a trade-off I chose because the game has no accounts.

Tests

455 unit tests in 44 classes, all on the JVM, because the rules and much of the UI's logic are pure functions. Beyond the rules:

  • The turn engine runs under a virtual clock, so a whole animated turn is tested in milliseconds.
  • Forty tests guard the shipped level file itself: pacing, how move budgets progress, chapter structure.
  • The copy is typed: Spanish is a subclass of English, so a missing translation fails to compile, and a test bans literal strings in the UI.
  • The slow balance suites are opt-in, so everyday runs stay fast.

Drawing, motion and access

  • The board is drawn on a Compose canvas and can switch, by a debug link, between one composable per creature and one painted node, to compare frame times against what React Native could manage.
  • The creatures are the prototype's original SVG paths, read by a small path parser of my own.
  • Turning off animations in Android shortens every animation and every phase of a turn, and stops the idle motion.
  • Spoken labels throughout, 44 dp touch targets, and text that scales up to 1.4 times.

The art, and the pipeline behind it

The illustrations are generated from my prompts and art direction. The work around them is code: the moving seas are cut out of each painted map by colour in CIE Lab, rendered as 120 frames in Blender, checked so that no land pixel ever moves, looped seamlessly and encoded to HEVC, for all 27 maps. The level badges sit where the painted trail actually runs, measured from it by colour and arc length.

Stack

Kotlin · Jetpack Compose · Coroutines and StateFlow · Google Play Billing · kotlinx-serialization · JUnit and kotlinx-coroutines-test · R8

Tooling: Python, Blender and ffmpeg