10/10Kingdom.py Write Python, grow a town
Script the heroes, townsfolk and trade routes of a six-island kingdom, one line of Python at a time.
A town builder you play by writing Python. Your scripts send heroes to build houses, collect taxes, sow fields and hold off bandits, while townsfolk take jobs, fall in love and pass personalities to their children. Trade with six islands, and watch each line light up as it runs. Wrong lines are explained in plain words, so you learn as the town grows.
- Single-player
- 1 player
- Windows
- macOS
- Linux
Building with code instead of clicks
Everything in the town begins with a few lines of Python. The opening setup is spare: a small island, a single hero, a town hall, and an empty main.py waiting for you. There is no hammer to swing or button to press, so your first real decision is what the hero does first, and you answer it with a line such as build(House, 3, 4). Hit Run and the hero sets off for the plot, carrying out your script line by line while the editor highlights whichever line is executing, so you can follow your own code as it turns into a street of houses. When a line is wrong, the game flags it and explains the problem in everyday language, which means a typo never becomes a mystery: you fix the line, run it again, and the hero gets back to work.

An economy that keeps moving
Once the houses are standing, the town needs to actually run, and that is where your scripts take over. Nothing fills the treasury by itself: a tax collector has to be dispatched to each house, so a script that skips that step leaves you rich in buildings and poor in coins. The same goes for everything else. A lumberyard sits idle once its grove is cleared, a field has to be planted and then brought in before the grain spoils, and each step feeds the next: grain and wood go to the bakery for bread, the miners are paid in that bread, and the smithy turns iron into tools. So you are really writing a chain of small programs, each one deciding when to start, when to stop and what to check first. The chain also has holes you have to cover. Bandits may reach a home before your guard does, and a merchant ship will leave without your goods if they never made it to the pier, which means a script that works perfectly in a quiet town can still lose you the shipment.

Learning Python through the story
That chain of small programs is exactly what the story teaches you to write. Each chapter pairs one piece of the town with a new Python concept, starting with plain variables and working through loops, conditionals, iteration and collections before reaching functions and modules, in the same gradual way your town unlocks new buildings. The growth is visible in your own code. A single collect() call grows into a loop, that loop learns to check whether stock is actually there, and the check gets wrapped into a function, until eventually four heroes are running four separate programs that share their work through a common database. If coding is new to you, the story assumes nothing: chapters are short, the Code School gives you runnable examples, hints appear when you get stuck, and every chapter comes with a solved version to check your work against. The whole story takes roughly eight hours for someone starting from zero, which is plenty of time to go from your first line to a town that runs itself.

Townsfolk you can script
Once the town runs itself, the people move in and start living in it. Newcomers fill the jobs at your workplaces, take home pay, spend it in the market and hand a share back as tax, so the economy you scripted now has faces. Life carries on around it: conversations happen on street corners, romances start and end in marriage, children arrive and eventually grow old, and not all of it is wholesome. Thieves work the town while members of the watch accept bribes, and anyone who dies keeps strolling around as a cheerful ghost until you put up a graveyard. You can script them too. Each trade runs on a shift program of your own, which decides where farmers lend a hand, when they haul and when they get to rest, and town.people() reads the whole town so you can see who is doing what. From there you can lock up a suspect, play matchmaker with town.match() or issue decrees. Deeper still, a person's character is nothing but six little Python functions covering love, work, hands, conscience, warmth and temper. A child picks up each function from one parent or the other, and now and then something new turns up, so a rule you write can spread through generations.

Trading across six islands
A town that produces more than it consumes needs somewhere to sell, and beyond your shore lie six islands sharing one market. Build the Trade Guild and you can deal with all six neighbours, watching prices move live as storms, strikes and festivals shift supply and demand. That leaves you a choice of how to trade. Either way the islands push back. They send commissions your way, and if you switch git on, they send pull requests to your scripts as well, so a foreign request can arrive in your repository. Check what the incoming change actually does before you accept it, because it will run in your kingdom too.

A coding desk over the island
By this point you are writing real code, so the game gives you a real desk to write it on. The console goes further than printing: ps, top, kill and cron all work there, since anything running in your kingdom, crabs included, counts as a process you can inspect. Git is built in as well: you make commits, work across branches and merge them, and a test run stands between you and any commit that lands. The libraries are the real thing too: numpy, pandas and matplotlib are all there, and requests works as well, though the messages go out by pigeon rather than over a wire. There is an algorithms room where ten standard algorithms step through their work beside your own version, so you can compare them move for move. And your scripts stay plain .py files on disk, which means you can open them in VS Code, edit them there, and have the game pick the change up when you return.
Questions about Kingdom.py?
How do you start if you have never coded before?
The story is written for newcomers. Chapters are short and introduce Python step by step, from variables and loops through functions and modules, while a Code School gives you examples you can run yourself. Hints are there when you get stuck, and every chapter has a reference solution to compare your work against. The full story takes about eight hours for someone starting from zero.
How does the economy work in Kingdom.py?
Everything runs on the programs you write. Houses only pay taxes when someone is sent to collect, lumberyards stop once their groves run out, and fields must be sown and harvested before the grain rots. Grain and wood go to bakeries for bread, miners are paid in that bread, and smithies turn iron into tools. Bandits can rob homes before your guard arrives, and merchant ships leave without your goods if they never reach the pier, so your scripts have to cover those gaps too.











