1. Overview: the game, its mechanics and the build plan
Adventure Capitalist: the game, its mechanics and the build plan
By the end of this lecture you will know what we are going to build today, which parts of Odoo Game Studio it is made from, in which order we will build it, how we will know each step is finished, and where every one of the next seven lectures fits. No code is written yet. This is the map, and it is a detailed one.
7
mechanics used
6
businesses
133
records of data
0
lines of new framework code
What is in this lecture
- The game in plain words
- Why this game comes first
- The core loop
- The mechanics it uses
- The records at a glance
- The build plan, layer by layer
- The numbers that make an idle game work
- Big numbers past 1e308
- Risks and design decisions
- Version 1 and version 2
- How lectures 2 to 8 map onto the build
- Your progress checklist
- Glossary and quick answers
Read it once from the top. Each part ends with a short recap, so you can come back later and re-read only the recaps. Everything quoted from the real code carries its file path and line numbers, and every number comes from the game's own data files or from the live site, read on the day this lecture was written (27 November 2026).
The game in plain words
You own a lemonade stand and four coins. Everything else you earn.
Adventure Capitalist belongs to a family of games called idle games or incremental games. In an idle game you do very little and the numbers go up by themselves, and that is the whole attraction: the game is a machine for making a number grow, and your job is to decide how to make it grow faster. The game in this course is built in the style of the best-known game of that family, and we say so openly: it is an educational reference. The name, the six businesses and the artwork are our own, and every rule is written as data in Odoo, so you can read it, change it and test it.
Here is a complete play session, told in the order you will meet things on the screen.
The first minute
You start with four coins and nothing else. The first business, a Lemonade Stand, costs exactly four coins, so you buy it. You now own one stand. A stand makes one coin when it finishes a cycle, and a cycle takes one second. But nothing happens until you press Run (the tap): a business without a manager only works when you start it. So you press Run, a bar fills for a second, a coin arrives, and you press Run again. This is the only moment in the whole game when your fingers do real work.
With the coins you buy a second stand. It costs 4.28 coins, not four: every unit of a business costs 7% more than the one before. That is the first thing to notice about the game, because it is the rule that makes everything else interesting. You will see in Part 7 that this single multiplier, 1.07, is what gives the game its shape. A third stand costs 4.58, a tenth 7.35, a hundredth about 3,200.
The first hour
Soon the coins pile up faster than you can spend them on stands, and the second business becomes affordable: a Newsstand at 60 coins. It makes 60 coins per cycle, but a cycle takes three seconds, and it is the first time you face a real choice. Is it better to buy another cheap stand, or to save for the dearer newsstand? The game never tells you. Part 7 shows that the answer is a ratio, the price divided by the income per second, and that a good player (or a bot) keeps buying whatever has the smallest ratio.
Then comes the first great relief: the manager. For 1,000 coins you hire a manager for your lemonade stands, and from that moment the stands restart their own cycles forever. You no longer press Run. The money flows, and you have become what the game is named after: a capitalist, someone whose money works without them. The other five businesses each have a manager too, at 15,000, 100,000, 500,000, 1.2 million and 10 million coins.
Along the way, round numbers reward you. When you own 25 of a business its profit doubles. At 50 it doubles again, then at 100 and at 200. Each business also has a profit upgrade, a one-time purchase that triples what it earns. And when you own at least 25 of every one of the six businesses, a hidden milestone gives you another doubling on everything. These are not decorations: they are the game's way of pulling you towards owning more.
The first day
After a while the prices outrun the income. Each new unit costs a little more, but each new unit adds the same amount, so progress slows down and the game feels stuck. That is the moment the game has been waiting for. You press Sell up (hold the P key). Everything you own is sold: your coins, your businesses, your managers, your upgrades. All of it goes. In exchange you receive angel investors, and you keep them forever. Each angel adds 2% to the profit of every business. The number of angels you get depends on the coins you have earned in your whole life: the square root of that number, divided by a hundred (a million lifetime coins gives 10 angels; a hundred million gives 100).
Now the second run begins from four coins again, but it goes faster, because every business earns more than before. You reach the same point sooner, you sell up again, you have more angels. That is the long loop of the game, and you can repeat it for ever. Your lifetime coin total goes on a leaderboard, so other players can see how far you have got.
An idle game is a number that grows, plus a few rules that decide how fast. The player makes a handful of choices (what to buy next, when to sell up) and the machine does the rest. Because the rules are small and exact, the game is ideal to build from data.
The six businesses at a glance
These are the real numbers, read from the recipe's data file by the build script that made this page (addons_recipes/game_recipe_adventure_capitalist/data/game.xml).
A cycle is how many seconds one round of work takes; the flow is what one unit makes per cycle before any multiplier.
| Business | Base price | Price rate | Cycle | Flow per cycle | Manager | x3 upgrade |
|---|---|---|---|---|---|---|
| Lemonade Stand | 4 | 1.07 | 1 s | 1 | 1,000 | 250 |
| Newsstand | 60 | 1.15 | 3 s | 60 | 15,000 | 5,000 |
| Car Wash | 720 | 1.14 | 6 s | 540 | 100,000 | 50,000 |
| Pizza Van | 8,640 | 1.13 | 12 s | 4,320 | 500,000 | 500,000 |
| Donut Shop | 103,680 | 1.12 | 24 s | 51,840 | 1,200,000 | 5,000,000 |
| Shrimp Boat | 1,244,160 | 1.11 | 96 s | 622,080 | 10,000,000 | 50,000,000 |
Notice the pattern before you read any further: each business is much dearer than the one before (about twelve times from the third on), earns far more per cycle, and works more slowly (cycles of 1, 3, 6, 12, 24 and 96 seconds). The price rate is 7% for the lemonade stand and then falls from 15% to 11% as you go up the list. These are the dials a designer turns, and all of them are fields on a record.
Where to play it, and what you will see
There are three ways to meet the game, and all of them show the same session on the same server:
- The player page at
/game/play/adventure_capitalist(the button at the top of this lecture). A full screen game with a title screen, a pause menu, settings and save slots. This is what a player sees. - The Play Console in the Game Studio app (admin side). It starts sessions of any course game, shows the raw state and lets you step through moves. This is what a game designer uses to check a rule.
- The Games list in the Game Studio app. The game is one record with a version, seat limits, offline rules and its mechanics. This is the design side.
The title screen
Continue, New game, Load, Settings, Leaderboards, How to play and Credits. None of this was written for Adventure Capitalist: it is the shared game shell (module game_shell_web) and every course game gets it. Part 4 and Lecture 6 return to it.
The same game, on a phone
The game is designed phone first. On a 390 px wide screen the six businesses stack into a column, and every button is large enough for a thumb. The screenshot was taken with a phone-sized browser window against the live site. (You will also notice that the layout still has rough edges: in the narrow column the owned count wraps awkwardly. Lecture 7 is where we fix that kind of thing, and we show it here honestly rather than hide it.)
- An idle game is a number that grows; you decide how fast.
- Run (tap), buy units that cost 7 to 15% more each, hire managers, cross milestones at 25, 50, 100 and 200 owned, sell up to angels for +2% profit each.
- Six businesses, from the Lemonade Stand to the Shrimp Boat, with prices, cycles and profits that are all fields on records.
- The same session shows on the player page, in the Play Console and in the Games list.
Why this game comes first
The first game should teach the method, not just the game.
Odoo Game Studio will build thirty games in thirty days. Day 1 has a heavy job: it must teach you the method that the other twenty-nine days repeat. Adventure Capitalist was chosen for that job after we compared it with the alternatives, and the reasons are worth knowing, because they show you how to choose the first game of your own.
Reason 1: the rules are all numbers
In a card game or a board game, the rules are about objects and positions. In an idle game, almost every rule is a number and a formula: a price is a base times a rate to the power of how many you own; an income is an amount times a count times some multipliers divided by a time; an angel reward is a square root. Numbers are the easiest rules to put in a database, to chart, to test and to argue about. You will see all of them plotted in Part 7.
Reason 2: it needs almost no new code
Day 1 adds no new framework code. Everything the game needs already exists as one of the mechanics of the studio (there are 54 mechanic modules in the repository today), and the game is a recipe: a data file of 133 records that selects and tunes those mechanics. That is the central claim of the whole course (a game is data), and Day 1 is the cleanest way to prove it. Whatever you learn here applies to the other days, because the other days are the same kind of file, only with other mechanics.
Reason 3: it shows time
Idle games are the only common game genre in which the game keeps running while the player is away. That forces you to face questions that every online game must answer, and that beginners usually skip: what is the clock of the game? Who owns it, the player or the server? What happens when the player comes back after ten hours? How do you prevent cheating by changing the clock of the phone? We answer these questions in Part 9, and you will meet the answers in code in Lecture 4.
Reason 4: it is already a playable product after one day
A game that needs six months of art and level design cannot be finished in a day. A game of six businesses, drawn with eight small icons, can. By the end of the day the game is live, has a title screen, sound, a leaderboard and a phone layout. That feeling of finishing something real is part of the method, because it shows what the framework is for.
Reason 5: it can be upgraded, which is how real games are built
The repository already contained an older idle game, a Bakery Tycoon. Day 1 does not start from a blank page: it audits the old game, finds what is stale, and upgrades it into Adventure Capitalist without throwing it away. Part 10 compares the two versions. Real projects are almost always upgrades of something, so Day 1 teaches the upgrade path first.
The alternatives we did not choose
| Alternative | Why it is tempting | Why not first |
|---|---|---|
| A puzzle game (match three, Sokoban) | Small boards, clear rules | Needs a grid kernel and level design; it belongs to days 10 to 12, where those are the lesson. |
| A card or board game (Monopoly style) | Everyone knows the rules | Many mechanics at once (dice, board, trade); it is day 5, when you can read recipes fluently. |
| An idle game with phases (Universal Paperclips style) | A famous, beautiful idea | Its pacing leans on a long story and phase gates that do not exist as mechanics yet. Adventure Capitalist shows more of the studio in one day. |
| A trading game (Harbour Trader) | Prices and events | It is day 2: prices there come from a seed, which needs the random tables you meet after this day. |
| An action game | Immediate feedback | Needs real-time kernels and a physics-free but frame-based client; days 4 and 20 and later. |
What the day teaches, in one list
- Model first: look at the records before the rules. The game is its records.
- Reuse before writing: every need was met by an existing mechanic or by a small, tested addition to one.
- Curves: how a price, an income and a reward are written as a formula you can plot.
- Time: cycles, managers, offline earnings, and the server as the only clock.
- Big numbers: what happens past the largest number a computer can hold, and how the framework handles it.
- Iteration: versions, includes, parameters and patches, so a published game is never edited in place.
- Proof: a bot plays the whole economy and the tests fail if any claim is wrong.
This course is also the plan of the build
Every course in this programme is both what you learn from and the plan for building its game. The progress bar at the top of the course page is the progress of the build: when all eight lectures are complete, the game is built, tested and shipped. Part 12 gives you the checklist to tick.
We teach Adventure Capitalist first because its rules are numbers, it needs no new framework code, it makes you think about time, it is playable in a day, and it can be an upgrade. It teaches the method that every other day repeats.
- Five reasons: numbers as rules, no new code, time and the server clock, a finished product in a day, an upgrade rather than a blank page.
- Five alternatives were compared and each belongs later in the programme, for a reason.
- The method: model first, reuse, curves, time, big numbers, iteration, proof.
The core loop
Every game is a loop. If you cannot draw the loop, you cannot build the game.
Before any record or any line of code, game designers draw the core loop: the cycle of actions the player repeats, with what they put in and what they get out. A good loop has a small number of steps, each step has a reward, and one reward feeds the next step. Here is the loop of Adventure Capitalist.
In words: Six boxes in a column, joined by arrows going down. 1: run a business (tap, or a manager restarts it). 2: coins arrive when the cycle ends. 3: spend them on a unit, a manager or an upgrade. 4: crossing 25, 50, 100 or 200 owned doubles profit. 5: growth slows because prices climb faster than profit. 6: sell up to angels, who add 2% profit each. A dashed arrow on the left goes from box 3 back to box 1 and is labelled "manager: no tap needed". A dashed arrow on the right goes from box 6 back to box 1 and is labelled "next run is faster (angels)".
Reading the diagram
Step 1, run a business. A business works in cycles. A cycle starts when you press Run, or when its manager restarts it. In the database, a cycle is a start time stored on the business row: the game does not count seconds in a timer, it only remembers when the cycle began, and works out how many cycles have finished whenever somebody looks. This is the same trick that makes offline earnings possible (Part 9).
Step 2, coins arrive. When a cycle ends the business pays flow x owned x multipliers. For the lemonade stands, with 10 owned and no multipliers, that is 1 x 10 = 10 coins per cycle. The coins go into a balance, and every coin that arrives is also written as a line in a ledger, so the game can always explain where the money came from.
Step 3, spend. There are three ways to spend, and they pull in different directions. A unit gives permanent extra income, but gets dearer. A manager gives no extra income at all in the first minute, but removes the need to press Run. An upgrade triples one business at once, for a price that is a one-time jump. The art of the game is choosing the cheapest way to raise the income per second.
Step 4, milestones. At 25, 50, 100 and 200 owned, a business doubles its profit. These are free: they cost nothing, they just reward you for owning more. Because they are doubling, they make the cost of the 25th unit worth paying even when the 24th seemed poor value. Milestones are what turns a smooth curve into a staircase and what gives the player small goals to aim at.
Step 5, growth slows. Prices grow exponentially. Income grows linearly with the number of units. Sooner or later, the exponential wins and the next unit takes longer and longer to afford. Designers call this the seesaw: on one side cost goes up, on the other side multipliers push income up, and the player's job is to keep the seesaw level. When it tips, the game offers the way out.
Step 6, sell up. The prestige: you give up everything for a lasting bonus. This is what makes the game last for weeks instead of an afternoon, and it is the biggest idea of the genre.
The loop at three time scales
One reason this loop is so good is that it is really three loops nested inside each other. Choose a tab to see each.
Run, collect, buy. The loop you play in the first minutes: tap a business, watch its bar fill, collect the coins, buy another unit. A turn lasts one to ten seconds. Each press gives immediate feedback (a bar, a sound, a number going up). The server records one producer.buy move per purchase; running a business is only a client action until the server settles it.
Save, hire, upgrade. After the first few stands, you stop pressing Run and begin to save. Hiring the first manager is the first big decision, followed by the first x3 upgrade, then the next business. A decision now takes a minute or more of income to afford. The player thinks about the ratio of price to income and about which milestone is close.
Sell up, again. The big loop: after an hour or so of play the income stalls, so you sell up, collect angels and start again. Each run is faster than the last. Between runs the player can close the game: the managers keep earning for up to 12 hours while the player is away, and the server catches up when the player returns.
What the player controls, and what the game controls
| The player decides | The rules decide | Nobody decides (the clock does) |
|---|---|---|
| What to buy next | The price of the next unit (a curve) | When a cycle ends |
| When to hire each manager | What a milestone gives | How much the managers earn while you are away |
| When to sell up | How many angels a sale gives | What the leaderboard shows |
| Whether to play, or to leave and come back | Whether a move is legal at all | The order of moves (the server numbers them) |
This table is more useful than it looks. It is the boundary between design (what the rules say) and play (what the player chooses), and the whole data model of the game follows it: the left column is move payloads, the middle column is design records, the right column is the clock and the kernel. Part 5 draws that boundary as an entity-relationship diagram.
A good loop has one clear reward per step
If you ever add a feature to this game and cannot say which step of the loop it improves, do not add it. This is how idle games stay clean. All of the mechanics in the next part serve one of the six steps.
- The core loop has six steps: run, coins arrive, spend, milestone, growth slows, sell up.
- It is three loops in one: seconds (run, collect, buy), minutes (hire, upgrade) and hours (sell up).
- The seesaw of exponential cost against linear income is what makes the game stall, and prestige is what un-stalls it.
- The boundary between what rules decide and what the player decides is the boundary between design records and play records.
The mechanics it uses
A game is seven building blocks and a data file that tunes them.
Adventure Capitalist has no module of its own that contains rules. Its recipe module, game_recipe_adventure_capitalist, contains only data (and tests). The
rules live in seven reusable modules, which the studio calls mechanics. This is the longest part of the lecture, because it is the heart of the framework: if you
understand what a mechanic is and what each of these seven does, you can read any recipe in the studio.
What a mechanic is
A mechanic is one Odoo module (named game_mechanic_<something>) that gives games one ability, such as "things that produce over time" or "a score table that outlives the
session". It always has the same four parts, and learning them once is enough:
- Models. Hand-written Odoo models, split into design records (what the game's author configures, shared by every session) and play records (the state of one session, one seat). We meet the split again in Part 5.
- Contracts. Declarations of what the mechanic lets a player or a rule do. There are three kinds. A move (
@game_move) is something a seat can do on its turn: buy, tap, sell up. An effect (@game_effect) is a change a rule can make: give coins, double a profit. A condition (@game_condition) is a yes or no question a rule can ask: do you own at least 25? Each declaration says what it needs (its payload or its fields) and which events it can emit. - Implementations. The Python that actually does the work, as a method on a model. The framework refuses to start if a declared type has no real handler: a test
(
game_core/tests/test_contracts.py) fails when a move, effect or condition has no code behind it. - Tests. Each mechanic plays itself in tests. A mechanic is not finished until they pass on a fresh install with every module installed.
Two further properties matter. First, a mechanic only depends on the kernel and on the mechanics it truly uses, and never on a recipe, so a recipe can pick any set of mechanics.
Second, a mechanic extends the kernel's tables instead of changing them: it adds its own move types, event types, effect types and condition types with Odoo's selection_add, so
rules written as records can use whatever is installed. The mechanics a recipe uses are simply a many2many field on the game record.
A mechanic is a reusable Odoo module with models (design and play), contracts (moves, effects, conditions), real code and tests. A recipe is a data file that chooses mechanics and sets their numbers. Day 1 chooses seven.
The seven, in one table
| Mechanic (module) | What it gives this game | Moves it adds | Events it emits | Day 1 records |
|---|---|---|---|---|
game_mechanic_resource | Coins and angels, balances, the ledger, prices | (none used) | resource.changed, resource.insufficient | 2 types, 18 cost lines |
game_mechanic_production | Businesses, cycles, managers, milestones, offline earnings | producer.buy, .start_cycle, .settle, .automate | producer.bought, .produced, .milestone | 6 types, 6 flows, 24 milestones |
game_mechanic_upgrade | The x3 profit upgrades and the shared milestone | upgrade.buy | upgrade.ranked_up | 7 upgrades |
game_mechanic_prestige | Selling up to angel investors | prestige.reset | prestige.reset | 1 layer, 14 reset lines |
game_mechanic_achievement | Two medals | (none) | achievement.earned | 2 achievements |
game_mechanic_leaderboard | The "Richest players" board | leaderboard.submit (unused: rules post) | leaderboard.rewarded | 1 board, 2 triggers |
game_variation (core) | A parameter and a mutator | (none) | (none) | 1 parameter, 1 mutator |
Underneath these seven sit the kernel (game_core: games, sessions, seats, moves, events) and the rules engine (game_rule: curves, conditions, effects, triggers), and the number
type game_bignum. We read them last in this part, because they are what makes seven independent modules behave like one game.
4.1 Resource: coins, angels and the ledger
What it does. The resource mechanic is the studio's money. A resource type is a named kind of amount (Coins, Angel investors) and a seat holds a balance of each. In Adventure Capitalist coins start at 4 and angels at 0. That is all the game's data says about them:
18 <record id="coins" model="game.resource.type"><field name="template_id" ref="template"/><field name="name">Coins</field><field name="code">coins</field><field name="starting_amount">4</field></record> 19 <record id="angels" model="game.resource.type"><field name="template_id" ref="template"/><field name="name">Angel investors</field><field name="code">angels</field><field name="starting_amount">0</field></record>
Which records. Besides the type there are three play records. game.resource.balance holds one row per resource per seat (and one for the bank) with four numbers:
amount (what you hold), lifetime_earned (everything ever received), run_earned (received since the last reset) and peak_amount (the highest you reached). Two of those four numbers are
exactly what the angels formula needs: lifetime for the reward, and run for "best run" bases that other games use. game.resource.transaction is the ledger: every movement of resources is a line with a source balance, a
target balance, an amount, a reason and the move that caused it. The bank is a balance with no seat, so coins that a business creates come "from the bank", and coins spent go "to the bank". A database
constraint says that ledger amounts must be positive and that a line has at least one side, so the ledger cannot contain nonsense.
Price lines. The third record is game.cost.line: a price. A price is a resource type plus either a fixed amount or a curve. Every mechanic that sells anything reuses this one
record by adding its own many2one to it: the production mechanic adds producer_type_id (the price of a unit) and automation_producer_type_id (the price of a manager), the upgrade mechanic adds
upgrade_id. That is why Day 1 has 18 cost lines and only one price model: 6 unit prices, 6 manager prices and 6 upgrade prices. A group of lines for one thing is all-or-nothing: either every line can be paid,
or nothing is.
Which moves and events. The mechanic adds one move, resource.transfer (give coins to another seat), which this game does not use, plus five effects for rules to use
(resource.gain, pay, pay_each, collect_each, set) and two conditions (resource.amount, resource.lifetime). When any resource changes it emits
resource.changed; when someone cannot pay it emits resource.insufficient, which is the event the game's "not enough" sound listens to. Day 1 needed one addition here: an effect could not read
a resource as its amount, so a rule could not post "lifetime coins" to the leaderboard. We added two amount sources, resource.amount and resource.lifetime, with tests (it is the only change Day 1
made to a mechanic's rules, and the first thing the iteration log in Part 6 mentions).
Why reused, not written new. Every game in the studio has some kind of money, points, wood, health or energy. If each game wrote its own, nothing could be shared: no price record, no ledger, no leaderboard feed, no client that draws a counter. Because resources are one mechanic, a price written for a Lemonade Stand can also be a price for a sword in an RPG, and the client can draw any balance with the same code.
- A resource type is a currency; a balance is how much one seat holds, with lifetime, run and peak totals.
- Every change is a ledger line; the bank is a balance with no seat.
- A cost line is the studio's one price record, reused by production, upgrades and others.
- Day 1 added two small amount sources so a rule can post lifetime coins.
4.2 Production: businesses, cycles, managers and milestones
What it does. The production mechanic is the engine of every idle game. A producer type is a business: it has a price, a cycle length, what it makes (its flows) and what you get for owning many. A producer is the play row that says how many of a type a seat owns. You can see all of this in three ways at once: the model in Python, the data in XML, and the live game.
The model that stores the idea of a business. Read the field names as the vocabulary of the genre: a price (cost_line_ids), a cycle length, flows, milestones, a manager price (automation_line_ids).
23 _name = 'game.producer.type' 24 _description = 'Producer Type' 25 _inherit = ['game.definition.mixin', 'game.picture.mixin'] 26 27 cost_line_ids = fields.One2many('game.cost.line', 'producer_type_id', string='Price', 28 help='Use an exponential curve: x = number already owned.') 29 cost_count_basis = fields.Selection( 30 [('total', 'All owned'), ('purchased', 'Only purchased (not generated)')], 31 default='total', required=True, 32 ) 33 cycle_seconds = fields.Float(default=1.0, required=True) 34 flow_ids = fields.One2many('game.producer.flow', 'producer_type_id', string='Inputs & Outputs') 35 milestone_ids = fields.One2many('game.producer.milestone', 'producer_type_id', string='Milestones') 36 max_count = fields.Integer(help='0 means no limit.') 37 unlock_condition_id = fields.Many2one('game.condition', string='Unlocked When', ondelete='restrict') 38 automation_line_ids = fields.One2many('game.cost.line', 'automation_producer_type_id', string='Automation Price', 39 help='Price to hire a manager so cycles restart by themselves.') 40 starts_automated = fields.Boolean() 41 production_mode = fields.Selection( 42 [('cycles', 'In cycles (whole cycles are collected)'), ('continuous', 'Continuously (per second, fractions count)')], 43 default='cycles', required=True, 44 help='Continuous producers earn every second, also what they make of other producers: a chain of them grows as '
The Lemonade Stand as the recipe writes it: a price curve, the business, its price line, its flow of one coin, its manager price of 1,000 and the four milestones.
23 <!-- 3.1 Lemonade Stand --> 24 <record id="lemonade_price" model="game.curve"><field name="template_id" ref="template"/><field name="name">Lemonade Stand price</field><field name="code">lemonade_price</field><field name="curve_type">exponential</field><field name="base">4</field><field name="rate">1.07</field></record> 25 <record id="lemonade" model="game.producer.type"><field name="template_id" ref="template"/><field name="name">Lemonade Stand</field><field name="code">lemonade</field><field name="sequence">10</field><field name="cycle_seconds">1</field></record> 26 <record id="lemonade_cost" model="game.cost.line"><field name="producer_type_id" ref="lemonade"/><field name="resource_type_id" ref="coins"/><field name="curve_id" ref="lemonade_price"/></record> 27 <record id="lemonade_flow" model="game.producer.flow"><field name="producer_type_id" ref="lemonade"/><field name="resource_type_id" ref="coins"/><field name="amount">1</field></record> 28 <record id="lemonade_manager" model="game.cost.line"><field name="automation_producer_type_id" ref="lemonade"/><field name="resource_type_id" ref="coins"/><field name="amount">1000</field></record> 29 <record id="lemonade_m25" model="game.producer.milestone"><field name="producer_type_id" ref="lemonade"/><field name="count">25</field><field name="output_multiplier">2</field></record> 30 <record id="lemonade_m50" model="game.producer.milestone"><field name="producer_type_id" ref="lemonade"/><field name="count">50</field><field name="output_multiplier">2</field></record> 31 <record id="lemonade_m100" model="game.producer.milestone"><field name="producer_type_id" ref="lemonade"/><field name="count">100</field><field name="output_multiplier">2</field></record> 32 <record id="lemonade_m200" model="game.producer.milestone"><field name="producer_type_id" ref="lemonade"/><field name="count">200</field><field name="output_multiplier">2</field></record> 33 <record id="fx_lemonade_x3" model="game.effect.group"><field name="template_id" ref="template"/><field name="name">Lemonade Stand profit x3</field><field name="code">fx_lemonade_x3</field></record> 34 <record id="fx_lemonade_x3_1" model="game.effect"><field name="group_id" ref="fx_lemonade_x3"/><field name="effect_type">producer.multiply_output</field><field name="producer_type_id" ref="lemonade"/><field name="amount">3</field></record> 35 <record id="up_lemonade" model="game.upgrade"><field name="template_id" ref="template"/><field name="name">Lemonade Stand profit x3</field><field name="code">up_lemonade</field><field name="effect_group_id" ref="fx_lemonade_x3"/></record> 36 <record id="up_lemonade_cost" model="game.cost.line"><field name="upgrade_id" ref="up_lemonade"/><field name="resource_type_id" ref="coins"/><field name="amount">250</field></record>
The same record in the shop. The business name, the owned count, "1 every 1s" (flow per cycle), the Run button, the price of the next unit and the manager price all come from the fields above.
Which records. Four models. game.producer.type (design) is the business. game.producer.flow (design) says what one unit makes or uses per cycle: here one output flow of
coins, with an amount of 1, 60, 540, 4,320, 51,840 and 622,080. A flow can also be an input, so that a business can consume (a factory burning coal), and an output can be another business instead of a currency (a farm making
farms), but Day 1 uses neither. game.producer.milestone (design) says "at this many owned, multiply output by so much": 24 rows, four for each business. game.producer (play) is the state, and a database
constraint allows exactly one row per type per seat per session.
The state row is worth reading, because it shows how an idle game avoids a timer. It has purchased_count, generated_count, output_multiplier, is_automated (the manager flag),
cycle_started_at, last_settled_at and carry_seconds. There is no counter of coins made. When anything asks "what has this business earned?", the code looks at last_settled_at and the
clock, works out how many cycles fit, pays them, and keeps the remainder in carry_seconds. That operation is called settling, and it is the single idea that makes offline earnings,
catch-up and fairness possible.
Which moves and events. Four moves. producer.buy takes a business and a count (a count of 0 means "as many as I can afford", which is the "Max" button), and emits
producer.bought, producer.milestone and resource.changed. producer.start_cycle starts one cycle by hand; producer.automate hires the manager; producer.settle collects what is due, for one
business or for all. The contract of the first three, copied from the real file:
148 @game_move('producer.buy', payload={'producer_type': 'game.producer.type', 'count': 'int?'}, 149 emits=['producer.bought', 'producer.milestone', 'resource.changed'], turn='any') 150 def _move_producer_buy(self, ctx, producer_type, count=None): 151 """Buy producers. Each one costs more the more you own. ``count`` 0 or missing buys as many as you can afford.""" 152 row = producer_type._buy(ctx, ctx.actor, count or 0) 153 ctx.move.write({'producer_id': row.id, 'buy_count': count or 0}) 154 155 @game_move('producer.start_cycle', payload={'producer': 'game.producer'}, emits=['resource.changed'], turn='any') 156 def _move_producer_start_cycle(self, ctx, producer): 157 """Start one production cycle by hand (a producer that is not automated).""" 158 self._own_producer(ctx, producer) 159 producer._start_cycle(ctx)
Read it as plain words: the move producer.buy accepts a payload with a producer_type (a record of game.producer.type) and an optional integer count; it promises to emit three kinds of event; and
turn='any' says there is no turn order, because an idle game has none. The body is one line, and it delegates to the model: producer_type._buy(ctx, ctx.actor, count or 0). This is the pattern of
the whole framework: a thin contract in front, a rule method on the model behind. Lecture 4 reads the body of _buy line by line: it settles first so earlier production is paid at the old rate, prices the units together with a closed
form instead of a loop (a "Max" of a million units is one sum), pays, counts, and announces any milestone crossed.
The manager and the offline rules. A manager is the second price of a business plus the move producer.automate. After it, is_automated is true and cycles restart by themselves, so settling a
managed business while you are away pays all the cycles that fit in the time away. How much time counts is three fields on the game itself: offline_after_seconds = 60, offline_efficiency_percent = 100 and offline_cap_seconds = 43,200.
In words: a gap of less than a minute is just play; a longer gap counts as time away, at full profit, for at most 12 hours. The function that turns a gap into earned seconds is short enough to show:
296 def _earned_time(self, start, end): 297 """Seconds of production the stretch ``start`` to ``end`` is worth for this seat. 298 299 The offline rule is measured from the seat's last activity (its last move), not from the last settle: 300 the first ``offline_after_seconds`` after it count fully, the rest at the offline efficiency, and nothing counts once 301 ``offline_cap_seconds`` have passed. Because it is a running total, ``worth(start, end)`` is the sum of 302 ``worth(start, middle)`` and ``worth(middle, end)``: a cron job settling in the middle earns exactly the same as no settle.""" 303 template = self.session_id.template_id 304 anchor = self.seat_id.last_active_at or end 305 306 def worth_since_activity(moment): 307 seconds = (moment - anchor).total_seconds() 308 if seconds <= 0: 309 return seconds # before the last activity the seat was playing 310 full = min(seconds, template.offline_after_seconds, template.offline_cap_seconds) 311 rest = max(min(seconds, template.offline_cap_seconds) - full, 0) 312 return full + rest * template.offline_efficiency_percent / 100.0 313 314 return max(worth_since_activity(end) - worth_since_activity(start), 0.0)
It is a running total, worth_since_activity(moment), and the answer for a stretch is the difference of two values of it. That is not a detail: because of it, settling in the middle changes nothing, so a
cron job that settles a sleeping player at the 12 hour mark pays exactly what a settle at the end would have paid. The code comments say so, and a test proves it.
Rules and effects. Besides moves, production adds effects that rules can use (producer.multiply_output, producer.speed, producer.grant, producer.automate) and two conditions
(producer.count, resource.income). The profit upgrades of the game are literally an effect producer.multiply_output with an amount of 3, pointed at a business; the shared milestone is that same effect with an amount of 2, six times.
Why reused, not written new. Production is the one mechanic the whole idle genre needs, and it is also the biggest reason the framework is worth having: the studio's idle-math notes catalogue 33 patterns from the published articles on idle game maths
(exponential cost, bulk buying, milestone multipliers, offline progress, generators that make generators, four kinds of prestige formula), and every one of them is expressible as records of this mechanic and its neighbours. A Farm game, a Factory game or a Space
Colony game is the same mechanic with other names, and the four lab games in game_recipe_idle_math_lab prove it with data alone.
- A producer type is a business (price, cycle, flows, milestones, manager price); a producer is a seat's row of it.
- There is no timer: the row stores a start time and the clock; settling pays the cycles that fit and keeps the remainder.
- Four moves (buy, start a cycle, settle, hire a manager), three events, and the offline rule is three fields on the game.
- The contract is a thin declaration; the real code is a method on the model.
4.3 Upgrade: the x3 buttons and the hidden milestone
What it does. An upgrade is something you buy for coins that changes the game for you: here, tripling the profit of one business. In other games the same mechanic is a skill tree, a research tree or a
shop of permanent boosts. It adds a small, general model, game.upgrade, with a few fields that are worth knowing even though Day 1 uses only some of them:
| Field | Meaning | Used in Day 1? |
|---|---|---|
max_rank | How many times it can be bought (each rank applies the effect again) | Left at 1 |
cost_line_ids | The price, a cost line (with a curve, x is the current rank, so every rank can cost more) | Yes: 250, 5,000, 50,000, 500,000, 5 million, 50 million |
effect_group_id | What each rank gives: a group of effects | Yes: producer.multiply_output x3 |
unlock_condition_id | When it appears in the shop (a condition tree) | Once: the hidden milestone uses "never" |
prerequisite_ids, excludes_ids | Tree structure: requires these, cannot combine with those | No |
research_seconds | A waiting time after paying (the rank applies later) | No |
Play state. One row, game.upgrade.state, per upgrade per seat: its rank and, when there is a research time, when the research completes. Rank 0 means you do not own it.
Moves, effects, conditions. upgrade.buy pays for the next rank and applies it (or starts research); upgrade.finish_research collects a finished one. Rules can also
grant a rank for free (effect upgrade.grant_rank) and ask about ranks (condition upgrade.rank). The contract of the buy move is, again, a thin declaration over a model method:
59 @game_move('upgrade.buy', payload={'upgrade': 'game.upgrade'}, 60 emits=['upgrade.ranked_up', 'upgrade.research_started', 'resource.changed'], turn='any') 61 def _move_upgrade_buy(self, ctx, upgrade): 62 """Buy the next rank of an upgrade: its price is paid, and it applies now or after its research time.""" 63 ctx.move.upgrade_id = upgrade 64 upgrade._buy(ctx, ctx.actor)
The clever one: the shared milestone. The seventh upgrade of the game is not for sale. "Every business at 25" is an upgrade whose price is nothing and whose visibility is the condition never (the
negation of "always"), so no player can ever buy it, and the shop does not show it. What gives it? A trigger (Part 4.8) that waits for a business to cross a milestone, checks whether all six are at 25, and then
grants rank 1 of the upgrade. Why build it from an upgrade at all? Because a rank is something the prestige reset can wipe, so the milestone is earned again in the next run, and because the six multiplications are an effect group the
engine already knows how to apply. A single new "global milestone" mechanic would have duplicated all of that, and the design notes record that we chose not to write one.
Why reused. Every progression system in every genre is "pay, get an effect". Because upgrades are a mechanic, the same model gives Adventure Capitalist its x3 buttons, a role-playing game its talent tree, and a strategy game its research queue. It is also the first place where you will see the framework's most useful trick: an effect is data, so a designer changes what an upgrade does by editing a record, not code.
- An upgrade is a priced, ranked bundle of effects; the play state is just its rank.
- Day 1 uses seven: six x3 profit buttons and one hidden milestone granted by a trigger.
- A price of nothing plus the condition "never" is how a rule-granted upgrade stays out of the shop.
4.4 Prestige: selling up to angel investors
What it does. Prestige is the genre's defining idea: you give up your progress for a permanent bonus. The mechanic calls the thing you do a layer (games such as Egg, Inc. have several layers, each with its own reward and its own list of what resets). A layer is a design record that answers six questions:
- What is measured? The basis: lifetime earnings, earnings this run, the highest balance, the best single run, or producers bought. Day 1 measures
lifetimecoins. - What does it give? A reward resource (angels) from a reward curve applied to the measurement.
- How much, exactly? A power curve with a base of 0.01 and an exponent of 0.5, rounded down:
floor(0.01 x sqrt(lifetime coins)). Because the layer subtracts what it already paid (subtract_previous_rewards), the second sale only pays for what is new. - Is it worth it? A
minimum_rewardof 5: below five angels, the move is refused. - What does a reward unit do?
bonus_per_reward_percentof 2: each angel adds 2% to all production. - What is reset? A list of reset lines, one per thing: coins, the six businesses, the seven upgrades. 14 lines in all.
140 <record id="angel_curve" model="game.curve"><field name="template_id" ref="template"/><field name="name">Angels from lifetime coins</field><field name="code">angel_curve</field><field name="curve_type">power</field><field name="base">0.01</field><field name="exponent">0.5</field><field name="rounding">floor</field></record> 141 <record id="sell_up" model="game.prestige.layer"><field name="template_id" ref="template"/><field name="name">Sell to angel investors</field><field name="code">sell_up</field><field name="reward_resource_type_id" ref="angels"/><field name="basis">lifetime</field><field name="basis_resource_type_id" ref="coins"/><field name="reward_curve_id" ref="angel_curve"/><field name="minimum_reward">5</field><field name="bonus_per_reward_percent">2</field></record>
Everything not on the reset list survives, and that is how the angels survive: they are simply not listed. The manager flag is a field on the business row, so when the row goes, the manager goes with it. That is a deliberate design decision, recorded in the Day 1 design notes with its backlog item (DAY1-02): after selling up, you hire your managers again.
How the reward is computed. The mechanic reads the measure, evaluates the curve, subtracts what was already paid and never returns less than zero:
59 def _reward(self, ctx, seat): 60 """What resetting right now would give the seat.""" 61 self.ensure_one() 62 total = big(self.reward_curve_id._evaluate(self._measure(ctx, seat))) 63 if self.subtract_previous_rewards: 64 total -= self._state(ctx, seat).total_rewarded 65 return compact(max(total, 0))
The reset itself is a careful sequence, and its order matters. It first settles every business, because the reset deletes the producers, and what they made since the last collection counts towards the reward (a test named
"selling up counts what the managers earned but had not collected" proves it). Then it refuses if the reward is below the minimum. Then it applies every reset line, restores the effects of any kept upgrade onto fresh rows, zeroes the run counter, pays the reward, records the reset
count and the total paid, and emits prestige.reset. The whole move is one savepoint, so a failure halfway leaves nothing half-sold.
Moves, conditions. One move, prestige.reset (payload: the layer), and two conditions, prestige.count and prestige.reward (so a rule can say "show this hint when selling up would give 100 angels or more"). The play row is
game.prestige.state: resets so far, total rewarded, best run, last reset time.
Why reused. The studio's idle-math notes catalogue four published prestige formulas (a square root of lifetime earnings, a cube root, a triangular root of the best run, and a small exponent of this run's earnings), and the mechanic supports all of them as data. Ours is the square root family, the same shape as the classic game's, with constants (0.01 and a minimum of 5) chosen for a small game; the classic game's published constants are different (150 and 1e15), and the mechanic can express those too. Any other game with a "start over for a bonus" loop, whether a roguelike's meta-progress or a farm's "new season", is this mechanic with other names.
Selling up deletes things, so the order of the code matters
The most common bug in a hand-written idle game is paying the reward after the reset has deleted what earned it. The mechanic settles first for exactly that reason, and the comment in the code says so. When you read Lecture 4, look for it.
- A prestige layer: a measurement, a reward curve, a minimum, a bonus per unit and a list of what resets.
- Angels = floor(0.01 x sqrt(lifetime coins)) minus what was already paid; at least 5; each adds 2% profit.
- What the layer does not list survives; the order of the reset (settle first) is what keeps the reward honest.
4.5 Achievement: two medals
What it does. An achievement is a goal that is earned once. The game has two: First business (own a lemonade stand, 5 points) and Millionaire (earn a million lifetime coins, 20 points). The mechanic is the smallest of the seven, only about 150 lines of Python, and it is a perfect example of how little a mechanic needs to be useful.
Which records. game.achievement (design) has a name, a description, points, an is_secret flag, a scope (this seat only, or this player across every game, which is how
"achievements that follow you" work), and an unlock rule of one of two kinds: a condition becomes true, or an event happens a number of times (event_count, with a target_count). It can also run a reward effect group when earned. game.achievement.earned
(play) holds the progress count and the moment it was earned.
How the two Day 1 medals work. Both use the condition kind, and both conditions are records of game_rule: "producer.count of lemonade at least 1" and "resource.lifetime of coins at least 1,000,000". The mechanic hooks into the end of every move (an Odoo-style _after_move override that calls super()): for every medal not yet earned, it asks the condition; the moment the answer is yes, it writes the earned row and emits achievement.earned, which is what plays the medal sound. The condition type resource.lifetime is one of the two things Day 1 added to the resource mechanic. Notice that nothing in
the achievement mechanic knows what a lemonade stand is: it only knows conditions. That is the whole composition idea in miniature.
Why reused. Every game wants medals, and nobody wants to write the same table twice. Because the medal's unlock rule is a condition, it can be about anything any installed mechanic can ask: cards held, tiles cleared, a story flag, a rank on a leaderboard.
- An achievement is an unlock rule (a condition, or an event count) plus points, secrecy and an optional reward.
- Day 1 has two medals, both condition based, and the mechanic knows nothing about lemonade.
4.6 Leaderboard: the one table that outlives the session
What it does. A session score answers "who won this sitting". A leaderboard answers "who is ahead across sittings", and for an idle game that never ends it is the only way to compare players. It is also the studio's answer to a rule of its North Star document: all games are multi-user by design, which means a game has either several seats or at least a platform-wide leaderboard that the rules post to (a verified score, never a number the client sends).
How Day 1 sets it up. One board called Richest players, configured by five choices that are worth reading as a design lesson:
| Field | Value | What it means |
|---|---|---|
write_mode | best | A new score replaces the old one only if it is higher. (Other modes: add to the score, or replace it.) |
key_mode | player | One row per player (their contact), across every session. (The other mode keys rows by a name the game sends, such as a team or a level.) |
submit_policy | rules | Only the game's rules may post. A client cannot write a score, so a cheater cannot post a million. |
period | none | The board never resets. A day or week board is one field away and is built into the mechanic, with reward claims, but unused here. |
top_count | 10 | A player sees the top 10, plus their own row if they are lower down. |
Who posts? Two triggers (Part 4.8): after every producer.bought event and after every prestige.reset, run the effect leaderboard.submit with the amount source resource.lifetime of coins. Because the lifetime counter is not
reset by a prestige, the score only ever goes up. In plain words: after you buy something, the server looks at your lifetime coins and offers that number to the board. You never send a score.
158 <record id="richest" model="game.leaderboard"><field name="template_id" ref="template"/><field name="name">Richest players</field><field name="code">richest</field><field name="write_mode">best</field><field name="key_mode">player</field><field name="submit_policy">rules</field><field name="top_count">10</field></record> 159 <record id="fx_post_score" model="game.effect.group"><field name="template_id" ref="template"/><field name="name">Post lifetime coins</field><field name="code">fx_post_score</field></record> 160 <record id="fx_post_score_1" model="game.effect"><field name="group_id" ref="fx_post_score"/><field name="effect_type">leaderboard.submit</field><field name="leaderboard_id" ref="richest"/><field name="resource_type_id" ref="coins"/><field name="amount_source">resource.lifetime</field><field name="amount">1</field></record> 161 <record id="post_after_buy" model="game.trigger"><field name="template_id" ref="template"/><field name="name">Post the score after a purchase</field><field name="code">post_after_buy</field><field name="event_type">producer.bought</field><field name="effect_group_id" ref="fx_post_score"/></record> 162 <record id="post_after_reset" model="game.trigger"><field name="template_id" ref="template"/><field name="name">Post the score after selling up</field><field name="code">post_after_reset</field><field name="event_type">prestige.reset</field><field name="effect_group_id" ref="fx_post_score"/></record>
Which records. game.leaderboard (design); game.leaderboard.entry (the rows: player, name, score, achieved at, period key); game.leaderboard.period and .claim and .reward for day and week boards. The numbers are stored with the framework's big
number field, so a board can rank scores past 1e308 in SQL: a test puts a score of 1e300 next to one above 1e400 and checks the order. (Part 8 explains.)
Why reused. Games 1 to 30 all need a "who is ahead" table, in different forms: highest score, fastest time, longest streak. This one mechanic gives the choice of "best, add or replace", per player or per name, rules-only or player-posted, with periods. The client reads the top rows from the public state, so a leaderboard widget is written once.
- A leaderboard outlives sessions: rows per player, written by a mode (best, add or replace).
- Day 1 lets only the rules post, after every purchase and every sell-up, so a score can only be real.
- The board stores big numbers, so it ranks any score the game can reach.
4.7 Variation: one parameter, one mutator and a way to make a different game
What it does. A published game never changes (Part 9), yet designers want to try variants: a head start, a harder economy, a seasonal edition. The variation module, game_variation, gives four ways to do it, each a separate record:
- A parameter (
game.param): a named number a rule can read, with a default and optional limits. A session may override it. - A mutator (
game.mutator): a named bundle of parameter overrides (and optionally triggers) a session can switch on. - An include: a game that includes another one copies all its records under a code prefix, then changes some. (Lecture 7 uses this.)
- A patch (
game.design.patch): one change of one field on one included record, applied once.
What Day 1 uses. One parameter, head_start (a float with limits of 0 to a billion, default 0), read by an effect that runs when the session starts and gives that many coins to every seat; and one mutator, Trust fund, which sets head_start to 1,000. A session with the
mutator switched on starts with 1,004 coins instead of 4 (a test checks exactly that), and every other record of the game is untouched. The data is five records. It is also the first time you see a trigger run on the event session.started, which is how a game does anything at the start.
Why reused. Parameters and mutators are how the studio makes modes out of one design: a tutorial mode, a hard mode, a daily challenge. They also keep the number of games small, because a variant is a few records rather than a copy of the game.
- Parameters are tunable numbers, mutators are bundles of them, includes and patches make a derived game.
- Day 1 has one of each parameter and mutator: the Trust fund adds 1,000 coins at the start.
4.8 The glue: curves, conditions, effects and triggers
The seven mechanics would be a pile of parts without game_rule, the module that lets a game author write rules as records. It has four building blocks, and Day 1 uses all four.
Curves: a number that depends on another number
A game.curve turns an input x into an output y. The types are constant, linear, exponential, power, logarithm, triangular root and table. Day 1 has seven curves: six exponential (base x rate^x, where x is how many you own) for the prices, and one power curve (base x x^exponent) for the angels. Curves can be rounded, floored and capped.
The same record serves a price, a reward, a difficulty ramp and a damage table; that is why curves are the most reused record in the studio.
Conditions: a yes or no question
A game.condition is a node in a tree: all, any, not, always, or a leaf supplied by a mechanic (producer.count, upgrade.rank, resource.lifetime). Day 1 has 12. The shared milestone's condition is a tree of seven children: six
"producer.count of this business at least 25" and one "upgrade.rank of the milestone equals 0" (so it fires only once).
Effects: a change
A game.effect is one change, and an effect group is a named bundle of them. Day 1 has 10 groups and 15 effects: six "multiply this business by 3", one group of six "multiply by 2" for the shared milestone, "grant the milestone", "post the score" and "give the head start".
Triggers: when this happens, if that is true, do this
A game.trigger reacts to an event. It has an event type, an optional condition and an effect group. The kernel runs triggers when moves emit events, so a mechanic never calls another mechanic: it emits an event, and a rule written as data does the rest. This is the one indirection that keeps the
mechanics apart. Here is the trigger of the shared milestone, one line of data that ties three modules together:
130 <record id="on_all_25" model="game.trigger"><field name="template_id" ref="template"/><field name="name">A business reached a milestone: is everything at 25?</field><field name="code">on_all_25</field><field name="event_type">producer.milestone</field><field name="condition_id" ref="all_25"/><field name="effect_group_id" ref="fx_give_all_25"/></record>In plain words: when a business reaches a milestone (producer.milestone), and the condition "every business at 25 and the milestone not yet given" is true, apply the effect group that grants rank 1 of the hidden upgrade. Production emits the event, the condition tree reads production and upgrade state, the effect uses the upgrade mechanic, and none of those modules knows about the others.
- Curves are numbers as functions; conditions are yes or no trees; effects are changes in bundles; triggers connect an event to an effect group.
- Day 1: 7 curves, 12 conditions, 10 effect groups with 15 effects, 4 triggers.
- Triggers are why six mechanics can work together without knowing about each other.
4.9 The kernel: sessions, seats, moves and events
Beneath all of it is game_core, which knows nothing about businesses or coins. It knows four ideas:
- A game (
game.template): a name, a code, a version, a state (draft or published), seat limits and the list of mechanics. A published game is frozen; a new version is a copy. - A session (
game.session): one play of a game. It has a state (setup, running, finished, aborted), a revision that goes up by one for every move, and a seed for randomness (Adventure Capitalist uses none; Lecture 7 adds some). - A seat (
game.seat): a participant. Every play record of Day 1 belongs to a seat, so four friends at one table are four separate empires with one leaderboard. - A move and its events (
game.move,game.event): every change to a session is a move, stored with the payload it was sent with, and moves write events. The move log is the truth: the state is what you get by replaying it.
The only way to change a session is submit_move. Here is the beginning of its pipeline, copied from the file:
61 def _submit_move(self, move_type, seat=None, payload=None, revision=None, idempotency_key=None): 62 """Python entry point: same as ``submit_move`` but returns the move.""" 63 self.ensure_one() 64 # One move at a time per session. Waiting here is what makes 65 # "check the revision, then change state" safe. 66 self.env.cr.execute(SQL('SELECT id FROM game_session WHERE id = %s FOR UPDATE', self.id)) 67 self.invalidate_recordset() 68 session = self.sudo() 69 70 if idempotency_key: 71 prior = session.env['game.move'].search( 72 [('session_id', '=', session.id), ('idempotency_key', '=', idempotency_key)], limit=1) 73 if prior: 74 if prior.move_type != move_type: 75 raise GameRuleError('idempotency_conflict') 76 return prior 77 78 handler = session._move_handler(move_type) 79 spec = handler._game_move 80 seat = session._browse_seat(seat) 81 82 if session.state not in spec.states: 83 raise GameRuleError('wrong_state', f'"{move_type}" is not allowed while the session is {session.state}.') 84 if revision is not None and revision != session.revision: 85 raise GameRuleError('stale_revision') 86 87 if spec.acts == 'seat': 88 if not seat: 89 raise GameRuleError('bad_payload', f'"{move_type}" must be made by a seat.') 90 if seat.state != 'active': 91 raise GameRuleError('illegal', 'That seat is no longer in the game.') 92 session._check_caller(seat, spec) 93 limits = getattr(handler, '_game_limits', None) or {} # a bulk move may raise the list size and the event budget 94 kwargs = session._normalize_payload(spec, payload or {}, limits.get('max_items'))
Read the steps in order: lock the session row so only one move runs at a time; return the earlier answer if the same idempotency key was sent twice (a double tap or a network retry does not buy twice); find the handler; check the session state; compare the client's revision with the server's (a stale client is refused); check who is acting; normalise the payload against the contract. Only then does the handler run, inside a savepoint. The next figure shows the same journey from the player's side, from a tap to a redraw.
In words: Eight boxes in a column: the player presses Buy; the client posts to the move route of the API; the kernel locks the session and checks replay and revision; the contract validates the payload; the mechanic handler runs; events are written; triggers react; the revision rises by one and the public state returns to the client.
Three properties of this design are worth stating, because they are why a game built on it is dependable: moves are atomic (one savepoint), replayable (the same moves give the same game), and idempotent (a key makes a retry safe). Adventure Capitalist's economy has no randomness, so replay is easy; the other days bring the seed and the cursor in.
- Game, session, seat, move, event: the five words of the kernel.
- One entry point, submit_move: lock, replay check, revision check, contract check, handler, events, triggers, revision plus one, in one savepoint.
- Moves are atomic, replayable and idempotent.
4.10 What is not a mechanic but the game cannot live without
Seven mechanics and the kernel make a game that plays. A game that people want to play needs what the studio calls engine services: modules that every game uses and no game rewrites. They hold data in Odoo too, and Day 1 attaches to each of them with a few records.
| Service (module) | What it does for this game | Which records or files | Taught in |
|---|---|---|---|
Big numbers (game_bignum) | A number type that keeps working past 1.8e308, stored as PostgreSQL numeric | The BigFloat field on balances, prices, flows, scores | Part 8 of this lecture; Lectures 3 and 4 |
Media (game_media, game_art_adventure_capitalist) | Eight icons (six businesses, coins, angels), a style with a 16 colour palette, a skin whose slots follow the record codes | 29 records and eight 64 px PNG files | Lectures 6 and 7 |
Input (game_input, _keyboard, _gamepad, _web) | Keys 1 to 6 buy, Shift plus a key runs, hold P sells up; an Xbox controller scheme; touch | Actions, payloads, bindings, a scheme, in data/input.xml (67 lines) | Lecture 6 |
Sound (game_audio, audio_core, game_audio_course_kit) | A sound cue per event: bought, coins, milestone, upgrade, sell up, achievement, "not enough", reward; gameplay music | 9 cue records for this game, from a kit of CC0 clips | Lectures 6 and 7 |
Game shell (game_shell, game_shell_web) | The title screen, pause, settings, save and load, leaderboard screen, how to play | A few shell options on the game; the player page /game/play/<code> | Lecture 6 |
Client kit (game_client_kit) | Browser services: the server clock, number formatting, tweens, audio, haptics | Services used by the client; no records | Lecture 6 |
The game client (game_adventure_capitalist_ui) | The one screen of this game: businesses, upgrades, angels, leaderboard | 433 lines of JavaScript and an 86 line template; it holds no rules | Lectures 6 and 7 |
The principle of this table is in the studio's client services document, in a sentence worth remembering: a game client asks the services; it never reads the gamepad, creates an audio context, compares server times with the local clock, or formats numbers itself. That is why the Adventure Capitalist client, with 433 lines of JavaScript, can draw bars, play sound, take a controller and show a number like 4.32M without any of that code being in it.
The client holds no rules
The client sends moves and draws the state it is given. It can predict (a bar fills smoothly between server answers, a Buy button greys out when the predicted balance cannot afford it), but the server decides. This is why the game cannot be cheated from the browser, and why the same game can later get a Godot or Unity client with no change to its rules.
- Big numbers, media, input, sound, shell and client kit are services every game uses.
- Day 1 attaches to each with a few records and one 433 line client that holds no rules.
The records at a glance
A game is two sets of records: the design you write once and the play you create every session.
Before the build plan, one more picture, and it is the most important one of the day. Every table in the game's database falls into one of two groups, and the whole framework is organised around the difference. Look at the diagram, then read the explanation under it.
In words: Two columns of seven boxes. The left column, DESIGN, lists game.template, game.resource.type, game.producer.type, game.upgrade, game.prestige.layer, game.achievement and game.leaderboard. The right column, PLAY, lists the matching records game.session, game.resource.balance, game.producer, game.upgrade.state, game.prestige.state, game.achievement.earned and game.leaderboard.entry. An arrow runs from each play box to its design box and reads "is an instance of".
Design records
The design records describe the game as an author wrote it. They exist once, whatever the number of players. They are what you see in the Games list and in the recipe's XML file. Once a game is published they are frozen: a database guard refuses to change them, and an improvement is a new version, a draft copy of the game that you edit and publish. This is how a game with players in the middle of a run can be improved without breaking them: their sessions keep pointing at the version they started on.
Play records
The play records describe one session. A session belongs to one game version and has one or more seats, and almost every play record belongs to a seat: the balance of coins, the row for each business, the rank of each upgrade, the prestige state, the medals earned. They are created by the game as it is played, never by an author. The leaderboard entry is the only play record that is not per session: it is per player, and it lives across every session of that game.
The two rules that follow
- A play record points at a design record, never the other way round. A balance knows its resource type; a resource type knows nothing about balances. This is what lets the same design serve a thousand sessions.
- Players read designs; they do not write play. A player can read the design (to draw prices and names) but cannot touch the play tables directly: all changes go through the server's
submit_move. The access rules are tested with real player users, not just with the administrator.
How many records is Adventure Capitalist?
The recipe's data file, game.xml, holds 133 design records of 19 models. Here is the full count, read from the file by the script that built this page:
| Model | Records in game.xml |
|---|---|
game.producer.milestone | 24 |
game.cost.line | 18 |
game.effect | 15 |
game.prestige.reset.line | 14 |
game.condition | 12 |
game.effect.group | 10 |
game.curve | 7 |
game.upgrade | 7 |
game.producer.type | 6 |
game.producer.flow | 6 |
game.trigger | 4 |
game.resource.type | 2 |
game.achievement | 2 |
game.template | 1 |
game.prestige.layer | 1 |
game.leaderboard | 1 |
game.param | 1 |
game.mutator | 1 |
game.mutator.param | 1 |
Add the input scheme (input.xml), the art module (29 records) and the audio cues (9 for this game), and the whole game is a little over two hundred records. That is the entire game design. It is also why the game's tests can play it from data alone, and why the
Day 1 course can claim that no framework code was written: every one of these rows is configuration of a mechanic that already existed.
What a seat has after five minutes of play
To see the play side, imagine a seat that has been playing for five minutes. It has two balances (coins, angels) and a ledger of a few hundred lines; one producer row for each business it owns (never one for a business it has not yet bought: rows are created on first use); a state row for each upgrade it has touched; one prestige state; perhaps one medal; and, after its first purchase, one leaderboard entry. Roughly twenty rows. A busy player after a month of play has the same twenty rows: the numbers inside them are larger, but the number of rows stays the same, which is why an idle game is cheap to host. The ledger and the move log are the only things that grow.
Design records: written once by the author, frozen when published, shared by every session. Play records: created as the game is played, one set per seat, each pointing at its design record. Adventure Capitalist is 133 design records and about twenty play rows per player.
- Design (left) is the game as written, frozen when published; play (right) is one session and one seat.
- Adventure Capitalist is 133 design records of 19 models in game.xml.
- Players read designs and send moves; they never write play records directly.
The build plan, layer by layer
One layer at a time, and no layer is done until a test says so.
The studio builds every game, and every mechanic inside every game, in the same order. The order is not a preference; it is a rule written in the project's rules file: finish and test a mechanic's contracts and implementations before starting another; if a task needs a layer that is not there yet, stop and say so. Here is the order, as a stack, and then as a timeline with what "done" means at each step.
In words: A stack of nine boxes. From the bottom: 0 kernel, rules and numbers (game_core, game_rule, game_bignum), already built; 1 models; 2 contracts; 3 implementations; 4 the API; 5 the recipe, the game as data, 133 records; 6 the client with shell, sound, input and art; 7 polish; 8 ship. Mint boxes are built from existing parts or code; amber boxes are the last two layers, built at the end of the day.
Why this order
Each layer needs the one below it, and mistakes get more expensive as you go up. A wrong field in a model costs a minute to fix before anything uses it, and a day to fix after a recipe, an API and a client have been built on it. That is why models come first. It is also why the recipe is written before the client: a client built on a rule set that is still changing will be rewritten, and the Day 1 iteration log (below) records that the client was written last, from the public state, for that reason.
The timeline, with "done" at each step
Read it from top to bottom: it is the order you will build in, and it is the order of the lectures.
Models
Hand-written Odoo models: fields, relations, constraints, design versus play.
Done means: the models install, the constraints hold (one producer row per type per seat, positive ledger amounts), the design and play split is respected.
Proved by: installing on an empty database and the model constraint tests.
Day 1 status: complete for every mechanic.
Taught in: Lecture 3.
Contracts
The @game_move, @game_effect and @game_condition declarations.
Done means: every type has a payload, needs and emits, and a real handler behind it.
Proved by: game_core/tests/test_contracts.py, which fails if any declared type has no handler.
Taught in: Lecture 4.
Implementations
The handler bodies and the tests that play each mechanic.
Done means: each mechanic plays itself in tests from a fresh install.
Proved by: 117 test methods in the six mechanics (resource 36, production 40, upgrade 9, prestige 13, achievement 4, leaderboard 15), plus 86 for the rules engine, 40 for the kernel and 7 for big numbers.
Taught in: Lecture 4.
API
Controllers that call submit_move and project the public state.
Done means: a client can create a session, send a move, read the state, the media manifest and the input scheme, and the state hides what a player must not see.
Proved by: game_api tests and the client contract test, which replays the client's calls over HTTP.
Taught in: Lectures 4 and 5.
Recipe
The game as data, composed from mechanics.
Done means: it installs alone and with every module; it passes the publish check (template.validate()); a bot plays from the first stand to selling up.
Proved by: 40 test methods in the recipe module, including the bot, the big number run, the version tests and the calculations.
Taught in: Lecture 5.
UX: shell, sound, input
The game's own screen, wrapped in the shared shell, with sound cues and an input scheme.
Done means: a player can reach the game from the title screen, play it with mouse, keys, controller or touch, hear it, pause and save it, on a 390 px phone and on a desktop.
Proved by: 3 client contract tests, 4 art tests, the input tests (5), and a real browser run on the live site (the screenshots in this lecture).
Taught in: Lecture 6.
Polish
Feedback, animation, art, sound design and a balance pass with bots and charts.
Done means: every action has visible and audible feedback; the economy has been plotted and tuned; the phone layout has no rough edges.
Proved by: before and after screenshots, the bot run, and the balance charts.
Taught in: Lecture 7.
Ship
Publish, version, share, leaderboards, and the personalisation exercise.
Done means: the game is published, new sessions start the newest version, running sessions are untouched, and a share link works.
Proved by: the version tests (a published version is frozen, the next one is a draft copy) and a published game on the live site.
Taught in: Lecture 8.
How Day 1 actually went
Day 1 was an upgrade of a game that already existed, so its history is a useful second plan. This is the iteration log, in order, taken from the Day 1 iteration notes in the course folder.
| # | Change | Why in this order |
|---|---|---|
| 1 | Keep the before: rename the module to game_recipe_adventure_capitalist; the old bakery data becomes version 1; remove one setting that stopped it installing alone. | Nothing else is safe to change until the old game is preserved and installs by itself. |
| 2 | Resource mechanic: two amount sources so a rule can read a balance, with two tests. | The leaderboard rule in step 3 needs them. A missing piece of a mechanic is added before the recipe that uses it. |
| 3 | Version 2 as data: six businesses, prices, managers, milestones, upgrades, the shared milestone, medals, angels, leaderboard, parameter and mutator, with 16 tests. | Model first, then rules, then tests that play it. |
| 4 | A bot that plays to a prestige; version, diff and include tests. | Prove the economy plays end to end and that two versions live side by side. |
| 5 | Art module and the keyboard input scheme. | Presentation comes after rules. |
| 6 | Public state additions in four mechanics (cycle timing, manager price, shop prices, prestige quote), each tested; a fix to the upgrade shop. | Found by asking what a client needs to draw, before writing the client. |
| 7 | The OWL client and its contract test. | Last, because it holds no rules. |
| 8 | Lucky Day: the personalisation solution (an include and a random table). | Lecture 7 needs a working answer. |
| 9 | Docs updated in place, backlog items filed, exercise solutions as tests. | Docs last, so they claim only what the tests show. |
After that log, three more things happened that you will see in later lectures: the game was made to work past 1e308 (Part 8), it was given the shared game shell, sound and controller support, and it was deployed to the live site, where this lecture's screenshots were taken.
What "tests prove each step" really means
Here are the counts of test methods in the files that matter, counted from the repository on the day this lecture was written (a count of def test_ lines, not of a test run):
| Where | Test methods | What they prove |
|---|---|---|
game_mechanic_production | 40 | cost curves, bulk buy, cycles, managers, milestones, offline time, continuous production |
game_mechanic_resource | 36 | balances, the ledger, prices, amount sources |
game_mechanic_prestige | 13 | reward formulas, reset lines, minimum, kept bonuses |
game_mechanic_upgrade | 9 | ranks, prerequisites, research, the shop |
game_mechanic_leaderboard | 15 | write modes, periods, claims, ranking big numbers |
game_mechanic_achievement | 4 | earning, event counts, scope |
game_bignum | 7 | exact arithmetic past 1.8e308, the column migration |
game_rule and game_core | 86 + 40 | curves, conditions, effects, triggers; moves, replay, idempotency, contracts |
game_recipe_adventure_capitalist | 40 | the game plays: prices, managers, milestones, selling up, offline, the leaderboard, versions, the bot, 1e400 |
| client and art modules | 3 + 4 | the client's calls work over HTTP; the art pack is complete |
Be honest about what the tests do not show
The test suite replays the client's calls over HTTP and checks that the template is well formed, but it does not drive a real browser. That is why this lecture also shows the live game running in a real browser: a claim about the screen needs a screenshot, and a claim about the rules needs a test. Lecture 6 says which is which.
A layer is done when the thing it promises is true and a test proves it. We build in order (models, contracts, implementations, API, recipe, UX, polish, ship) because mistakes get more expensive as you go up. Day 1 adds no framework layers: it climbs layers 5 to 8 on top of layers 1 to 4 that already exist.
- Eight layers, built in order: models, contracts, implementations, API, recipe, UX, polish, ship.
- Each layer has a "done means" and a test or a screenshot that proves it.
- Day 1's own log: keep the old game, add what a mechanic lacks, write the recipe, prove it with a bot, then art, input, client, variants and docs.
- Test counts are counted from the repository today and printed with what they prove.
The numbers that make an idle game work
An idle game is a handful of formulas. Plot them and the game stops being mysterious.
Everything in this part is computed from the numbers in the recipe's data file, with a short script that is kept in the lecture folder (src/economy.py), which parses game.xml instead of retyping a single value. Where a chart shows a model of the bot rather than a measurement, the text says so.
7.1 Prices: why 1.07 is the most important number in the game
The price of the next unit of a business is base x rate ^ owned. For the lemonade stand the base is 4 and the rate is 1.07, so the price goes 4, 4.28, 4.58, 4.90, and so on. A price that grows by a fixed percentage is an
exponential curve. The first chart shows it for the lemonade stand, the second shows all six businesses on one chart in a trick designers use constantly: the logarithm of the price. On a log chart, every exponential
curve is a straight line, and the steepness of the line is the rate. You can read the whole price structure of the game from it.
The price of the next Lemonade Stand, by how many you own
A line chart. The horizontal axis is how many stands you own, 0 to 100. The vertical axis is the price of the next one in coins. The line is almost flat at first (4 coins at 0 owned, about 8 at 10 owned, about 20 at 25 owned) and then bends sharply upward, reaching about 3,250 coins at 99 owned. This is what an exponential curve looks like on a normal axis.
Data: addons_recipes/game_recipe_adventure_capitalist/data/game.xml (read by economy.py); price = 4 x 1.07^owned.
Price of the next unit on a log scale, all six businesses (log10 of coins)
A line chart with six straight lines rising from left to right, one for each business. The vertical axis is the base-10 logarithm of the price, so 6 means a million coins. The Shrimp Boat line starts highest (about 6.1, which is 1.24 million) and the Lemonade Stand line starts lowest (about 0.6). The Newsstand line is steepest (rate 1.15) and the Lemonade Stand line is shallowest (rate 1.07); the lines converge towards the right, and the Newsstand would overtake the Shrimp Boat near 280 owned.
Data: addons_recipes/game_recipe_adventure_capitalist/data/game.xml (read by economy.py); each point is log10(base x rate^owned) at 0, 10, 20 ... 200 owned.
Two things to notice in that chart. First, the lines converge: the first Shrimp Boat costs about 20,000 times more than the first Newsstand, but the Newsstand's rate is 1.15 and the Shrimp Boat's only 1.11, so the Newsstand line is steeper. By 200 owned the gap has shrunk from a factor of 20,000 to about 17 (log10 of 13.9 against 15.2), and if the chart went on, the lines would cross near 280 owned. Nobody buys 280 newsstands, but the slope shows what the rate controls: how long a business stays worth buying. A high rate means "buy a few and move on", a low rate means "keep buying". The six rates, 1.07, 1.15, 1.14, 1.13, 1.12 and 1.11, are the main way the designer gives each business its personality. Second, the plot stays a line all the way to 200 owned. That straightness is a promise you can test: it says that no price ever jumps, and that prices stay finite for any count you can reach, which Part 8 returns to.
7.2 Income, payback, and the question every player asks
What is worth buying? The question has a precise answer, and it is the number we call payback: the price of a unit divided by the extra income per second it adds. The income per second of one unit is flow / cycle. At the start the paybacks are:
Payback of the first unit of each business (seconds of its own income to earn its price)
A bar chart with six bars: Lemonade Stand 4 seconds, Newsstand 3 seconds (highlighted), Car Wash 8, Pizza Van 24, Donut Shop 48, Shrimp Boat 192. The Newsstand has the shortest payback even though it is the second business, and the paybacks then rise steadily up the list.
Data: addons_recipes/game_recipe_adventure_capitalist/data/game.xml (read by economy.py); payback = base price / (flow / cycle), no multipliers.
The Newsstand, at 3 seconds, pays itself back faster than the Lemonade Stand at 4, the first one you can afford. That is not an accident: it is how the designer tells a new player that the next business is the better deal, even before they can afford it. The paybacks then rise (8, 24, 48 and 192 seconds) because high-level businesses are meant to be long-term investments. A bot that always buys the unit with the smallest payback plays well, and it is exactly what the recipe's bot test does.
7.3 The seesaw, in numbers
Payback also explains why the game stalls. As you own more of a business, the price of the next unit climbs by its rate, while the income the unit adds stays the same (apart from milestones). The payback of the next unit therefore grows exponentially. The table shows it for the Lemonade Stand (the milestone factor is the number the game applies to all units at that count):
| Owned | Price of next | Income now | Milestones | Payback of the next unit | Time to afford it at this income |
|---|---|---|---|---|---|
| 1 | 4.28 | 1.00 / s | x1 | 4.28 s | 4.28 s |
| 10 | 7.87 | 10.00 / s | x1 | 7.87 s | 0.79 s |
| 25 | 21.71 | 50.00 / s | x2 | 10.85 s | 0.43 s |
| 50 | 118 | 200 / s | x4 | 29.46 s | 0.59 s |
| 100 | 3,471 | 800 / s | x8 | 434 s | 4.34 s |
| 200 | 3.01 M | 3,200 / s | x16 | 188,233 s | 941 s |
Read the payback column: 4 seconds for the first stand, 8 at 10 owned, 11 at 25, 30 at 50, about 7 minutes at 100, and about 52 hours at 200. The last row is the stall: the 201st stand would need two days of its own income to repay itself. The player's coins are then better spent elsewhere, on another business or on selling up. Without the milestones it would be far worse: look at the milestone column, which shows x2, x4, x8 and x16 appearing at 25, 50, 100 and 200 owned. They are the seesaw's counterweight, and they keep the next unit worth buying for a long time: the 25th stand doubles the profit of the 24 before it. The last column explains why the game still feels fast: at every row you can afford the next stand within seconds, so you keep buying, while the payback quietly sags. This is called bumpy progression, and it is a deliberate design: the player always has a nearby goal.
Lemonade Stand income per second, by how many you own
A line chart of income per second against stands owned, 0 to 220. Both lines climb in steps: each time the count reaches 25, 50, 100 or 200, the whole line jumps up because every stand now earns double. The upper line, with the x3 upgrade, is three times as high everywhere. At 200 owned the income is about 3,200 coins per second, or about 9,600 with the upgrade.
Data: addons_recipes/game_recipe_adventure_capitalist/data/game.xml (read by economy.py); income = flow x owned x 2^(milestones reached) x (3 with the upgrade) / cycle.
The staircase is the milestones. At 25, 50, 100 and 200 owned the entire stack of stands suddenly earns twice as much, and the income jumps up in one step. A smooth chart would be boring to play; a staircase gives the player a reason to keep buying one more unit.
7.4 Managers and upgrades: a one-time price for a lasting effect
A manager costs 1,000, 15,000, 100,000, 500,000, 1.2 million and 10 million coins, and an upgrade costs 250, 5,000, 50,000, 500,000, 5 million and 50 million. Both are much higher than the price of the first unit, so they unlock only once you have a base of income. A manager gives no income, but it gives you time, which is worth more than coins; an upgrade triples one business at once, which only pays if you own enough of it.
The replica of the bot (below) shows what a sensible order looks like: it buys the Lemonade Stand's x3 upgrade at 640 seconds and the manager at 720, the Newsstand's upgrade at 760 and its manager at 820, the Car Wash's at 860 and 900, hires the Pizza Van's manager at 960 and buys its upgrade at 980, and hires the Donut Shop's manager at 1,060 seconds. For the first three businesses the upgrade comes first, simply because it is cheaper than the manager (250 against 1,000, 5,000 against 15,000, 50,000 against 100,000); the Pizza Van's two prices are equal at 500,000, so the order is the bot's own habit. It never reaches the Shrimp Boat in the first run.
7.5 Angels: how much is a reset worth?
The angel reward is floor(0.01 x sqrt(lifetime coins)). Because of the square root, to double your angels you must earn four times as many coins. That one fact is the whole shape of prestige: the first reset is cheap and the next ones get slower, so the game rewards you for going further in each run, and does not reward you for resetting too early.
Angels from lifetime coins (the prestige curve)
A line chart of angels against lifetime coins in millions, 0 to 100 million. The curve rises fast at first and then flattens, which is the shape of a square root: 10 angels at 1 million, 22 at 5 million, 31 at 10 million, 50 at 25 million, 70 at 50 million and 100 at 100 million.
Data: addons_recipes/game_recipe_adventure_capitalist/data/game.xml (read by economy.py); angels = floor(0.01 x sqrt(lifetime coins)).
| Lifetime coins | Angels | Profit bonus | Profit factor |
|---|---|---|---|
| 250,000 | 5 | +10% | x1.10 |
| 1,000,000 | 10 | +20% | x1.20 |
| 25,000,000 | 50 | +100% | x2.00 |
| 100,000,000 | 100 | +200% | x3.00 |
| 1,000,000,000 | 316 | +632% | x7.32 |
| 1,000,000,000,000 | 10,000 | +20,000% | x201.00 |
The minimum of five angels (250,000 lifetime coins) is a guard: below it the move is refused, because the player would trade a run for a few percent. By 25 million lifetime coins you have 50 angels and double profit. By a trillion lifetime coins the curve gives 10,000 angels, a bonus of 20,000%, or a factor of 201. Each sale only pays new angels (the layer subtracts what it paid), which is why selling again at the same total gives nothing and why the lifetime counter is never reset.
7.6 Putting it together: a bot plays the whole economy
The recipe has a bot test that plays from four coins to a sale, using only moves the rules accept: it taps, hires managers, buys the x3 upgrades and then buys the business with the smallest payback, in steps of 20 seconds. I replicated its policy in plain Python in the lecture folder, so the next chart is a model of the bot (it counts a manual business as one cycle per step and treats each angel as +2% additive profit), not a measurement from the test. In the replica, the first run reaches 50 angels' worth of lifetime coins in 60 steps (20 minutes, 27.16 M lifetime coins). The real bot test logged 64 steps for the same target in the Day 1 iteration notes: close enough to confirm the model, different enough to remind you that it is one.
Lifetime coins over time for two runs of a bot (log10), replica of the bot test
A line chart with two curves, minutes on the horizontal axis and the log of coins earned in the run on the vertical axis. Both rise steadily. The run-two curve (after selling up for 52 angels) rises faster, so it reaches the same height in fewer minutes. In the replica, run one needs about 20 minutes to earn what makes about 52 angels, and run two needs about 12 minutes to earn another 50 angels' worth.
Data: a plain-Python replica of the policy in tests/test_bot.py (src/economy.py); the horizontal axis is minutes of play, the vertical axis is log10 of coins earned in the run.
In the replica, the second run needs 12 minutes to earn the next 50 angels' worth of coins, against 20 minutes for the first. That is the prestige promise, in a picture: each run is shorter than the last, even though each run has to reach a higher total. If the second run were not faster, the game would have no reason to exist. And if it were much faster, the game would end in an afternoon. Tuning the 2% per angel, the 0.01 and the exponent of 0.5 is how the designer sets the pace; Lecture 7 does it with a bot and a chart like this one.
7.7 Time away: the offline curve
The last formula is the one that matters most to a player who closes the app. The production mechanic counts the first offline_after_seconds after your last move at full rate, then the rest at the offline efficiency, up to the cap. Adventure Capitalist sets 60 seconds, 100% and 12 hours:
Production time earned while away (hours of production against hours away)
A line chart of hours of production earned against hours away, 0 to 24. The green line rises at one hour per hour until 12 hours away and then goes flat at 12: you never earn more than 12 hours of work, however long you stay away. The red what-if line rises at half that speed and goes flat at about 6 hours.
Data: the formula in _earned_time (addons_mechanics/game_mechanic_production/models/production.py) with the recipe's three offline fields; the 50% line is a what-if for comparison.
The flat part is a design decision (Part 9): it stops a player who is away for a month from coming back to a number that makes everything else irrelevant, and it gives the player a reason to return every day.
Prices are base x rate^owned (an exponential). Income is flow x owned x multipliers / cycle. The payback of a unit is price over extra income per second, and it grows exponentially, so the game stalls. Milestones and prestige push back. Angels grow with the square root of lifetime coins, so doubling them takes four times the coins. Time away counts fully up to 12 hours. Six formulas, and the whole game.
- Price = base x rate^owned; the rate is each business's personality (1.07 to 1.15).
- Payback = price / income per second: the Newsstand is the best first buy at 3 seconds; the Shrimp Boat is the long game at 192.
- Milestones turn a smooth curve into a staircase and keep the seesaw level; prestige resets it.
- Angels = floor(0.01 x sqrt(lifetime)); four times the coins for double the angels. Offline: full rate up to 12 hours.
- Every chart here is computed from game.xml or from the formula in the code; the bot chart is a replica and says so.
Big numbers past 1e308
A computer can hold a number up to 1.8e308. An idle game goes past it in a few days.
This is the part of the lecture that surprises beginners, so we go slowly. A normal decimal number in a computer is a float: a 64-bit format that has about 15 to 17 significant digits and an exponent. It can hold numbers up to about
1.8 x 10^308, which is a 1 with 308 zeros after it. For almost every program that is more than enough; the number of atoms in the universe is about 10^80. But an idle game multiplies, and multiplication gets you there quickly: a price that grows by 15% per unit
passes 10^308 after about 5,000 units, and a profit that gets a x1e8 multiplier on every rank passes it in a handful of ranks.
What happens when you go past it
The float format has a special value, Infinity. When a calculation exceeds the maximum, the result is not an error: it is Infinity, silently. In Python, 1e308 * 10 is inf. And infinity breaks everything that follows: infinity minus anything is infinity, a price of infinity can never be
paid, an income of infinity makes every purchase free, and PostgreSQL stores it as a special value that cannot be compared sensibly. The framework's own early version of this game had exactly that failure: a column stored Infinity, and nothing in the game could be bought. The famous incremental game Cookie Clicker shows the same thing to this day: past
about 2^1024 cookies it displays "Infinity" and prices become unpayable.
This is not a rare edge case
An idle game is built to grow without bound. If your numbers can overflow, some player will overflow them, and the failure is silent: no error, just a game that has stopped working. Plan for it from the first day.
How other games handle it
| Who | Representation | Limit | Cost |
|---|---|---|---|
| Plain float (Cookie Clicker) | one 64-bit number | 1.8e308, then Infinity | fast; the game breaks at the limit |
| break_infinity.js (Antimatter Dimensions) | a mantissa and an exponent, each a number | about 1e9e15 | much faster than exact arithmetic; fewer exact digits |
| break_eternity.js | sign, layer, magnitude | towers of powers | for games that exponentiate exponents |
| The original of our game | a double shown with names (million ... centillion) | about 1e303 | the naming scheme our clients use |
Python decimal | arbitrary precision, in C | exponent to about 1e18 on 64-bit | exact; microseconds per operation |
PostgreSQL numeric | arbitrary precision, in the database | about 1e131072 | exact, sortable in SQL; slower than float |
What the studio chose
A Big is a Python decimal.Decimal with 17 significant digits and an exponent up to 131,000, stored in PostgreSQL numeric. Below 1.8e308 every amount is a plain float. The reasons are exactly the four properties a game needs:
- Exact enough. 17 digits is what a float holds, so a value reads back as written and the precision does not change at the 1.8e308 line. Sums of many prices are computed at 40 digits and rounded once, so "can this seat pay?" is decided as if the maths were exact.
- Fast enough. The arithmetic runs in C at about 1.5 microseconds per operation, next to milliseconds of database work per move. "Max" buys use closed forms (a geometric series), not loops.
- Storable and comparable in SQL.
ORDER BY score DESCworks at 1e400. A leaderboard can rank any score the game can reach, in the database, without loading rows. - The common case is unchanged. Fields hand out ordinary floats while a float can hold the value, so the thirty-odd mechanics that never grow past it see exactly what they always saw. Only the idle mechanics do their arithmetic with
big().
The price of the choice is a limit: past 1e131,000 an operation raises an error (a price that large is simply never affordable), and past 17 digits, small additions vanish: 1e400 + 100 is 1e400, exactly as in a float at its own scale.
Numbers on the wire, and how a player reads them
JSON has no number past 1.8e308 either, so the API sends an amount as a JSON number when it is finite and below 1e15, and as a text otherwise, in scientific notation: "1.234567890123456e400". The client's numbers service reads both forms. A player does not want to read 1.5e400, so the client shows names:
| Suffix | Name | Value |
|---|---|---|
| K | thousand | 1e3 |
| M | million | 1e6 |
| B | billion | 1e9 |
| T | trillion | 1e12 |
| Qa | quadrillion | 1e15 |
| Qi | quintillion | 1e18 |
| Sx | sextillion | 1e21 |
| Sp | septillion | 1e24 |
| Oc | octillion | 1e27 |
| No | nonillion | 1e30 |
| Dc | decillion | 1e33 |
After Dc (decillion, 1e33) the scheme continues with aa, ab, ... zz, and then with scientific notation; amounts are rounded down when drawn, and a value that rounds to zero shows "0", never "-0.00". Scientific notation everywhere is a player's choice in the settings. This is why the live game shows prices such as 8.64K and 1.24M in the screenshots of this lecture.
The proof: a bot plays past 1e400
The recipe has a test whose name is its claim: the bot plays past 1e400 and every number stays right. Its header says how, in the author's own words:
1"""Adventure Capitalist played past 1e400 coins: prices, income, "Max", angels and the leaderboard keep working above 1.8e308. 2 3The recipe's own economy levels off (angels grow with the square root of earnings), as early Adventure Capitalist does before 4its angel upgrades. The test adds the missing piece the way the real game does: an angel upgrade, bought with angels, that 5multiplies every business's profit (x1e8 per rank, priced 1, 2, 4... angels). It is kept through a reset like any upgrade the 6layer does not list, so the run compounds. Everything else is the recipe's data and the bot only plays moves the rules accept. 7"""
Read it as a recipe for a test you will write yourself: use the economy's own data, add one missing piece (an angel upgrade that multiplies profit by 1e8 per rank, so the run keeps compounding), let the bot play with random time skips of 30 seconds, 10 minutes, 2 hours or 13 hours, and after every step check that no number is negative, infinite or smaller than before. At the end it checks that a price beyond 1.8e308 is still above the previous one, that "Max" left less than the next price, that the leaderboard ranks 1e300 below a score above 1e400, and that the wire format reads back exactly. Our own value for "the largest number the game can reach" is 1e400, and it is tested, not claimed.
A float stops at about 1.8e308 and then silently becomes Infinity. An idle game must not. The studio stores amounts as exact decimals with 17 digits in PostgreSQL numeric, sends big ones as text, and shows them with names (K, M, B ... Dc, then aa, ab ...). A test plays the whole game past 1e400.
- A float overflows to Infinity at about 1.8e308, silently; an idle game will reach it.
- The studio's
Big: 17 digits, exponent to 131,000, stored as PostgreSQLnumeric; plain floats below the line. - Big values travel as text and are shown with names; leaderboards rank them in SQL.
- The 1e400 bot test is the proof, and it is part of the recipe.
Risks and design decisions
Every design decision is a risk you chose to take, or one you chose to remove.
Before building anything, a good designer writes down what could go wrong, and what was decided about it. The Day 1 design document, written before the build, has fifteen numbered decisions. Here are the ones with the most consequence for a beginner, as an accordion: open the ones you are curious about. Each has the risk, the decision and what we would watch.
The risk. Too little and players feel punished for leaving; too much and the game is over before it began, or players rush back to farm the cap. The decision. The game counts a gap over 60 seconds as time away, at 100% profit, for at most 12 hours, and only for businesses with a manager (a business waiting for your tap has nothing to earn while you sleep). The three numbers are fields on the game record, so they are tunable without code, and tested, including the cap. What we would watch. The share of players who come back inside the 12 hours; if it is low, the cap is too short.
The risk. If the client says what time it is, a player sets the phone forward a day and collects a day of income. The decision. The only clock that counts is the server's. Every move is stamped by the server, every API answer carries server_time, and the client's clock service estimates the offset between the two, never going backwards, only to draw smooth bars. It never decides anything. A bar can fill a fraction early on screen; the server settles the real cycles when the player acts. Tests move a game clock (clock_override) instead of waiting.
The risk. A leaderboard is worth nothing if anyone can post anything. The decision. The board is set to rules only: the client cannot post, a trigger posts lifetime coins after every purchase, and lifetime coins are a number the server keeps. Moves are validated against a contract, replays are idempotent, and the whole API is rate limited per user (240 calls per minute by default, a system parameter overrides it). We met the limit by accident while capturing this lecture's screenshots. A scripted client tapping Run once every 1.1 seconds made 139 API calls in about 45 seconds, roughly 3 a second or 185 a minute, because every tap is a move plus a state refresh on top of the two second poll. That is already close to the limit of 240, and a few extra purchases tipped it over: the server answered "Too many requests" and the client showed it as a generic Odoo error dialog. The limit worked as designed; an enthusiastic human tapping faster than once a second could hit it too, and a friendlier message is a polish item for Lecture 7.
The risk. The same player opens the game on a phone and a laptop and buys on both at once. The decision. The kernel locks the session row for one move at a time, compares the client's revision with the server's (a stale client is told to refresh), and each move is one savepoint. The game polls the state every two seconds, so a second tab catches up quickly.
The risk. A game you cannot replay cannot be tested, debugged or audited. The decision. Every move is stored with its payload, and randomness (not used by this game yet) comes from the seed. The same moves on the same version give the same game, which is also what lets the save slots in the shell work as bookmarks rather than copies.
The risk. A tuning mistake in one number can make the early game endless or the late game instant. The decision. Prices and rewards are curves in records, so tuning is a data change; a bot plays the economy and the test fails if it cannot reach a sale; and Lecture 7 draws the balance charts. The numbers of this game are the published public values of the classic game, tuned only so that a manager is bought with coins.
The risk. Silent overflow (Part 8). The decision. An exact decimal type stored as numeric; a 1e400 bot test; a hard error past 1e131,000 rather than a wrong answer.
The risk. You fix a price while a player is mid-run, and their next purchase costs something unexpected. The decision. A published game is frozen. An improvement is a new version (a draft copy), new sessions start the newest published version, and a session already running finishes on the version it began with. A diff test shows exactly what changed between version 1 and version 2.
The risk. A game that runs for months writes a ledger line for every coin. The decision. Postings are netted per move (one ledger line per resource, not one per business), and the number of play rows per player stays fixed (about twenty). Only the ledger and move log grow, and both are indexed. A retention policy for old ledger lines is an open point, and we say so rather than hide it.
The fifteen decisions at a glance
This is the list from the Day 1 design notes, shortened. A decision is only useful if it can be reversed or defended, so each has a short reason.
| # | Decision | Reason |
|---|---|---|
| 1 | One game family, two versions (the module was renamed, version 1 kept) | A version is cheaper than a memory of what the game was. |
| 2 | No new game_core code | The point of the day: a game is data. |
| 3 | Click-to-earn is a producer without a manager | The tap already existed as producer.start_cycle; a manager is the price to stop tapping. |
| 4 | Milestones: per business as rows, the shared one as upgrade + condition + trigger | A new milestone module would duplicate what exists. |
| 5 | One real gap fixed: two amount sources on the resource mechanic | So a rule can post lifetime coins; small, tested, in the mechanic not the kernel. |
| 6 | Prestige resets coins, businesses, managers and upgrades; angels survive | Angels are simply not on the reset list. |
| 7 | Offline: 60 s, 100%, 12 h, only managed businesses | As in the original; three template fields. |
| 8 | One leaderboard, per player, "keep the best", rules only | A verified score. |
| 9 | A parameter and a mutator; an include for a variant game | Variations are records, not copies. |
| 10 | Art in a separate module; the recipe never mentions it | A skin can change without touching rules. |
| 11 | Input as data: keys 1 to 6 buy, Shift runs, hold P sells | A client reads the scheme; it hard-codes nothing. |
| 12 | One OWL client, no rules in it | The server decides; a Godot client could replace it. |
| 13 | The hub (library and share links) pending at design time | Lecture 8 lists what has since landed. |
| 14 | Seats one to four, each with its own empire | A table of friends is four games with one leaderboard. |
| 15 | Six businesses, not ten | Enough to teach curves, payback and the shared milestone; more is a data change. |
The pattern behind all fifteen
Whenever the choice was between writing code and writing a record, we wrote a record. Whenever the choice was between trusting the client and trusting the server, we trusted the server. Learn those two reflexes and you can predict most of the decisions of any game in this studio.
- Offline: 60 s, 100%, 12 h, managed businesses only. Time: the server's clock only. Verification: rules post scores; moves are validated; the API is rate limited.
- Published games are frozen; improvement is a version. Concurrency is a lock plus a revision check.
- Open points are stated, not hidden: ledger retention, the client's generic error on a rate limit.
Version 1 and version 2
A good game has a history. Day 1 keeps the old game and builds the new one next to it.
You will meet the word version constantly in this studio, and Day 1 is where it is learnt, because Adventure Capitalist did not start from nothing. The repository already contained an older idle game called Bakery Tycoon. The course is partly the story of how it became Adventure Capitalist, without ever being deleted.
Both exist today as two published versions of one game family: they share the code adventure_capitalist, version 2 points back at version 1 through previous_version_id, and the game list shows version 2 because new sessions always start the newest published version. A session that was running on version 1 finishes on version 1.
What version 1 was
A bakery with two businesses (an Oven and a Bakery that unlocks at three ovens), coins, cakes and "franchise stars"; one upgrade (Better flour, three ranks); a timed crafting job (a wedding cake that takes 30 seconds); a franchise that is the prestige; two medals; nine tests. In data it is 31 records (41 lines of XML), and today it is still in the repository, unchanged apart from one line that lets it install on its own.
What the audit found
The first job of Day 1 was not to write; it was to audit. An audit compares what exists with what a good game needs, and writes down every gap. The full table is in the Day 1 design notes, so here are the findings that taught the most:
- It did not install on its own. It used a setting that belongs to a mechanic it did not depend on, and so it only worked on a database where something else had installed that mechanic. The finding came from the simplest possible test: installing it alone on an empty database.
- The first business ran by itself. With no tap and no manager, the idle loop's very first decision (should I buy a manager?) did not exist.
- No version history, no variants, no art, no input, no leaderboard. Everything that makes a game a product and not a prototype was missing.
- The offline settings were defaults nobody had tested. "Offline earnings" was a claim with no test.
- The shop could suggest an upgrade nobody may buy. A free, locked upgrade showed as a button. That is a real bug, found when asking what a client needs to draw.
- Four documents named the old game or claimed less than the code did. Docs are part of the product.
The same idea, twice
The two versions are best compared side by side, in the same four fields. Choose a tab:
The old Bakery Tycoon: an Oven that costs 10 coins at a rate of 1.15, runs by itself from the first purchase (starts_automated), makes one coin every two seconds, and doubles at five owned.
7 <record id="v1_oven_price" model="game.curve"><field name="template_id" ref="v1_template"/><field name="name">Oven price</field><field name="code">oven_price</field><field name="curve_type">exponential</field><field name="base">10</field><field name="rate">1.15</field></record> 8 <record id="v1_oven" model="game.producer.type"><field name="template_id" ref="v1_template"/><field name="name">Oven</field><field name="code">oven</field><field name="cycle_seconds">2</field><field name="starts_automated" eval="True"/></record> 9 <record id="v1_oven_cost" model="game.cost.line"><field name="producer_type_id" ref="v1_oven"/><field name="resource_type_id" ref="v1_coins"/><field name="curve_id" ref="v1_oven_price"/></record> 10 <record id="v1_oven_flow" model="game.producer.flow"><field name="producer_type_id" ref="v1_oven"/><field name="resource_type_id" ref="v1_coins"/><field name="amount">1</field></record> 11 <record id="v1_oven_milestone" model="game.producer.milestone"><field name="producer_type_id" ref="v1_oven"/><field name="count">5</field><field name="output_multiplier">2</field></record>
Its descendant: a stand that costs 4 coins at a rate of 1.07, does not run by itself (you tap it, or hire the 1,000 coin manager), makes one coin every second, and doubles at 25, 50, 100 and 200 owned.
24 <record id="lemonade_price" model="game.curve"><field name="template_id" ref="template"/><field name="name">Lemonade Stand price</field><field name="code">lemonade_price</field><field name="curve_type">exponential</field><field name="base">4</field><field name="rate">1.07</field></record> 25 <record id="lemonade" model="game.producer.type"><field name="template_id" ref="template"/><field name="name">Lemonade Stand</field><field name="code">lemonade</field><field name="sequence">10</field><field name="cycle_seconds">1</field></record> 26 <record id="lemonade_cost" model="game.cost.line"><field name="producer_type_id" ref="lemonade"/><field name="resource_type_id" ref="coins"/><field name="curve_id" ref="lemonade_price"/></record> 27 <record id="lemonade_flow" model="game.producer.flow"><field name="producer_type_id" ref="lemonade"/><field name="resource_type_id" ref="coins"/><field name="amount">1</field></record> 28 <record id="lemonade_manager" model="game.cost.line"><field name="automation_producer_type_id" ref="lemonade"/><field name="resource_type_id" ref="coins"/><field name="amount">1000</field></record> 29 <record id="lemonade_m25" model="game.producer.milestone"><field name="producer_type_id" ref="lemonade"/><field name="count">25</field><field name="output_multiplier">2</field></record> 30 <record id="lemonade_m50" model="game.producer.milestone"><field name="producer_type_id" ref="lemonade"/><field name="count">50</field><field name="output_multiplier">2</field></record> 31 <record id="lemonade_m100" model="game.producer.milestone"><field name="producer_type_id" ref="lemonade"/><field name="count">100</field><field name="output_multiplier">2</field></record> 32 <record id="lemonade_m200" model="game.producer.milestone"><field name="producer_type_id" ref="lemonade"/><field name="count">200</field><field name="output_multiplier">2</field></record>
| Version 1: Bakery Tycoon | Version 2: Adventure Capitalist | |
|---|---|---|
| Records in the data file | 31 | 133 |
| Businesses | 2 (Oven, Bakery) | 6 (Lemonade Stand to Shrimp Boat) |
| Price rates | 1.15 (Oven); the Bakery is a flat 500 | 1.07, 1.15, 1.14, 1.13, 1.12, 1.11 |
| Does a business run by itself? | Yes, from the first purchase | No: a tap, or a manager you buy |
| Milestones | x2 at 5 Ovens | x2 at 25, 50, 100 and 200 for each business, plus a shared one |
| Upgrades | 1 (three ranks) | 7 (six x3 buttons and a hidden milestone) |
| Prestige | Franchise stars: floor(0.1 x sqrt(lifetime coins)) | Angels: floor(0.01 x sqrt(lifetime coins)), minimum 5, +2% each |
| Crafting a cake | Yes: 50 coins, 30 seconds | No (dropped; mechanics crafting and timer are unused) |
| Leaderboard, parameter, mutator | None | One board, one parameter, one mutator |
| Mechanics used | resource, production, upgrade, crafting, timer, prestige, achievement | resource, production, upgrade, prestige, achievement, leaderboard, variation |
The diff is a test
"What changed between the versions?" is a question the framework answers with code, and the answer is checked by a test. This is the real test, copied from the file:
31 def test_the_diff_between_the_versions(self): 32 old, new = design_codes(self.v1), design_codes(self.v2) 33 removed = {model: old[model] - new.get(model, set()) for model in old if old[model] - new.get(model, set())} 34 added = {model: new[model] - old.get(model, set()) for model in new if new[model] - old.get(model, set())} 35 self.assertEqual(removed['game.blueprint'], {'cake'}) # cake crafting was dropped 36 self.assertEqual(removed['game.producer.type'], {'oven', 'bakery'}) 37 self.assertEqual(added['game.producer.type'], {'lemonade', 'newsstand', 'carwash', 'pizza', 'donut', 'shrimp'}) 38 self.assertEqual(added['game.leaderboard'], {'richest'}) 39 self.assertEqual(added['game.param'], {'head_start'}) 40 self.assertEqual(added['game.mutator'], {'trust_fund'}) 41 self.assertEqual(added['game.trigger'], {'on_all_25', 'post_after_buy', 'post_after_reset', 'on_start_head_start'}) 42 self.assertEqual(old['game.resource.type'] & new['game.resource.type'], {'coins'}) # the one thing both keep 43 dropped = (self.v1.mechanic_ids - self.v2.mechanic_ids).module_id.mapped('name') 44 self.assertEqual(sorted(dropped), ['game_mechanic_crafting', 'game_mechanic_timer']) # no cakes, no timer 45 self.assertEqual(sorted((self.v2.mechanic_ids - self.v1.mechanic_ids).module_id.mapped('name')), ['game_mechanic_leaderboard', 'game_variation'])
Read it as a changelog that cannot go stale: the cake was dropped, the oven and bakery were removed, six businesses were added, a leaderboard, a parameter, a mutator and four triggers were added, and the one thing both versions keep is the coin. If someone edits the recipe and the story changes, the test fails.
Prefer a version, a parameter or an include to a copy
When you want a different game, do not copy the module. Make a new version (a draft copy of the records), or switch on a mutator, or write a recipe that includes this one and patches a number. Lecture 7 writes one: Lucky Day is an include plus one mixed-in mechanic.
- Two published versions of one family: version 2 points back at version 1; new sessions start version 2, old ones finish on version 1.
- The audit came first: it did not install alone, the first business ran itself, no history, art, input or leaderboard, untested offline rules.
- The diff between versions is a test, so the changelog cannot go stale.
How lectures 2 to 8 map onto the build
Seven more lectures, and each one finishes one layer.
Every Day course in the studio has the same eight lectures in the same order, so what you learn on Day 1 about how to read a course applies to every other day. This lecture is the first and the only one that does not build a layer: it makes the plan. The other seven each own a layer of the build plan from Part 6, and each ends with something you can check.
| # | Lecture | What it covers | Build layer | Done when |
|---|---|---|---|---|
| 2 | Design document: mechanics, recipes, diagrams | The full design on paper: rules, tuning tables, the ERD, a UML class diagram, sequence diagrams for the key moves, state diagrams, charts of the economy. | Before layer 1: the design that the layers implement | Every mechanic broken down into inputs, state, events and effects; diagrams that you can check against the code |
| 3 | The models: fields and relationships | Every model the game touches: every key field, the relations and their reasons, design versus play, access rules, versioning, with real code excerpts. | Layer 1: models | You can read any model file of the six mechanics and say what each field is for |
| 4 | Mechanics and the engine: methods, events, contracts in code | submit_move step by step, each handler used, events and triggers, determinism, offline time, big numbers, with real code and how it is tested. | Layers 2 and 3: contracts and implementations; layer 4: the API | You can trace one buy move from tap to new state, and run the mechanic tests |
| 5 | Recipes and contracts: how the subsystems come together | The recipe file read top to bottom; how mechanics plug together; the game in design mode (Play Console, demonstrators); parameters, mutators, variations; the tests that prove the game plays. | Layer 5: recipe | The game installs alone, passes the design check, and a bot plays it to a sale |
| 6 | The UX: the full game MVP | The shell, the game screen, input (keyboard, controller, touch), sound, phone layout; how the client reads state and sends moves; screenshots of every screen. | Layer 6: UX, shell, sound, input | A player reaches the game from the title screen and plays it on desktop and phone |
| 7 | Polish: juice, art, sound and balance | Feedback, tweens, art and skins, sound design, balance passes with bots and charts; before and after. | Layer 7: polish | Every action has feedback; the economy is tuned with evidence |
| 8 | Ship it: share, publish and what's next | Versions, publishing, share links, leaderboards, the personalisation exercise and a preview of the next game. | Layer 8: ship | The game is published; new sessions get the newest version; a variant exists |
How the course tracks the build
Each lecture is an eLearning slide, and finishing a slide completes it on your progress bar. Because each lecture finishes one layer, the progress bar of the course is, quite literally, the progress of the game's build: after Lecture 5 the game is playable in design mode; after Lecture 6 it is playable by a player; after Lecture 8 it is shipped. The checklist in Part 12 is the same thing in a form you can tick.
What each lecture reuses from this one
- Lecture 2 turns Part 3 (the loop) and Part 7 (the numbers) into a full design document, and redraws Part 5's ERD with every field.
- Lecture 3 opens each model of Part 4 and reads its fields, with line numbers.
- Lecture 4 follows the move of Part 4.9, and reads the code behind the contracts of Parts 4.2 to 4.6, including the order of the prestige reset and the offline function.
- Lecture 5 reads
game.xmlin the order of the records of Part 5, and runs the bot of Part 7.6. - Lecture 6 opens the services of Part 4.10, and the shell, and the screens shown in Part 1.
- Lecture 7 tunes the numbers of Part 7 with bots, and polishes the rough edges (like the phone layout) we pointed at.
- Lecture 8 publishes a new version, using the lessons of Part 10, and sets up the share link and the leaderboard of Part 4.6.
Where to be careful
Lectures 3 and 4 contain the most code. If you are new to Python or to Odoo, read this lecture again first, in particular Part 4 and Part 5, and keep the glossary in Part 13 open in another tab. You do not need to be able to write the code to follow: the course shows how to read it.
- Lectures 2 to 8 each finish one layer: design, models, mechanics and engine, recipe, UX, polish, ship.
- The course progress bar is the build's progress.
- Every later lecture reuses a part of this one.
Your progress checklist
If you cannot tick it, you have not finished the lecture.
This course is also the build plan, so progress has two parts: what you understand, and what is built. Here are both. The boxes are for you to tick in your own notes (a web page cannot remember a tick, and we do not want it to guess); copy the list into your notes and tick as you go. Each item says where to look if you cannot.
Lecture 1: the overview (this lecture)
- I played the game and bought a businessOpen
/game/play/adventure_capitalist, press New game, buy a Lemonade Stand and run it. - I can draw the core loop from memorySix steps and two return arrows; compare with the diagram in Part 3.
- I can name the seven mechanics and one move, event or record of eachTable in Part 4: resource, production, upgrade, prestige, achievement, leaderboard, variation.
- I can explain design versus play recordsPart 5: written once and frozen versus created per seat per session.
- I can list the eight layers in order and say what "done" means for onePart 6: models, contracts, implementations, API, recipe, UX, polish, ship.
- I can say why the price rate is 1.07 and what the payback of a unit isPart 7: price = base x rate^owned; payback = price / income per second.
- I can explain what happens to a float past 1.8e308 and what the studio does about itPart 8: Infinity; exact decimals in
numeric; text on the wire. - I can give two reasons the server owns the clockPart 9: cheating by changing the phone clock; fair offline earnings.
Do these six things in the studio before Lecture 2
Ten minutes of clicking will make the next seven lectures far easier, because you will recognise what they talk about.
- Open the Game Studio app as the demo admin and the Play Console. Menu: Game Studio, then Play Console. Day 1 is the first card. "New session" starts a human session; "Play vs computer" adds a bot seat.
- Open Games and find Adventure Capitalist. Menu: Games, then the row. Notice version 2, state Published, seats 1 to 4, course day 1, and the buttons Check design, New version, Duplicate game and Export as XML.
- Press Check design. The design check reports problems and warnings; a good game has none. Remember what it says: Lecture 5 explains each check.
- Open Mechanic Gallery. The studio's catalogue of mechanics, each with a demonstrator. Find production, upgrade and prestige.
- Play for ten minutes and sell up if you can. You need 250,000 lifetime coins for the first five angels. Press and hold P to sell up. Check the leaderboard after.
- Write down three numbers you noticed. The price of your tenth unit, the payback of your favourite business, and what you gave up when you sold. They are the questions of Part 7.
What the Games form looks like
This is the design record of Adventure Capitalist in the Game Studio app: name, code, version 2, state Published, seat limits, course day, description, and the buttons for the design check, a new version, duplicate and export. The Sessions list under it shows who has played. (We cropped the screenshot at the top of the form so that no player's session is shown.)
The build, lecture by lecture
These seven are the rest of the course. They are listed here so that you can see the whole shape of the day, and so that this page is the one place to come back to when you ask "where am I?".
- Lecture 2: the design document is writtenTuning table, ERD, UML, sequence diagrams and the economy charts.
- Lecture 3: every model and key field readYou can say what each of the fields of a business and a balance is for.
- Lecture 4: a buy move traced from tap to new stateYou ran the production mechanic's tests and read the order of the reset.
- Lecture 5: the recipe read and the bot runThe game installs alone, passes the design check and the bot plays it to a sale.
- Lecture 6: the game plays from the title screen on desktop and phoneWith sound, a keyboard scheme and a controller scheme.
- Lecture 7: polish and balance done with evidenceA before and after screenshot, a balance chart, a tuned number.
- Lecture 8: version published and sharedA new session starts the newest version; a share link works; your score is on the board.
How you know the whole day is done
When all eight boxes are ticked and the eLearning progress bar of the course shows 100%, the game is built, tested, polished and shipped. That is the definition of done for Day 1, and it is the same for the other twenty-nine.
- Two lists: what you understand (this lecture) and what is built (Lectures 2 to 8).
- Six ten-minute actions in the studio make the next lectures easy to follow.
- Day 1 is done when all eight lectures are complete and the game is published.
Glossary and quick answers
If a word is new, it is in this list.
The glossary is alphabetical. Every term here was used in this lecture, and every one will come back in a later lecture.
| Term | Plain meaning |
|---|---|
| Achievement | A goal that is earned once, with points. Day 1 has two. |
| Angel investor | The reward currency of selling up. Each adds 2% to all profit and survives the reset. |
| API | The server's doors: addresses under /game/api/ that a client calls to send moves and read state. |
| Balance | How much of one resource one seat holds, with lifetime, run and peak totals. |
| Big number | A number that can pass 1.8e308; stored exactly as a decimal in PostgreSQL numeric. |
| Condition | A yes or no question a rule can ask, such as "does the seat own at least 25?". |
| Contract | A declaration (@game_move, @game_effect or @game_condition) of what a mechanic allows: payload, needs, emits. |
| Curve | A record that turns one number into another: constant, linear, exponential, power, log, triangular root or table. |
| Cycle | One round of a business's work; it ends with a payment. Lasts 1 to 96 seconds in this game. |
| Design record | A record written by the game's author; shared by every session; frozen once published. |
| Effect | A change a rule can make, such as "multiply this business's output by 3". Grouped into effect groups. |
| Event | A fact written by a move, such as producer.bought. Triggers react to events. |
| Flow | What one unit of a business makes (or uses) per cycle. |
| Idle game | A game where numbers grow while you are away and the player's main decisions are what to buy and when to reset. |
| Include | A game that copies another game's records under a code prefix and then changes some. |
| Kernel | game_core: games, sessions, seats, moves and events. It knows nothing about any one game. |
| Layer (build) | One step of the build order: models, contracts, implementations, API, recipe, UX, polish, ship. |
| Layer (prestige) | A design record that says what is measured, what is rewarded and what resets when a player starts over. |
| Ledger | The list of every movement of a resource, one line each. The bank is a balance with no seat. |
| Manager | A one-time purchase that makes a business restart its cycles by itself, also while you are away. |
| Mechanic | A reusable module that gives games one ability: models, contracts, code and tests. |
| Milestone | A free doubling of one business's profit at 25, 50, 100 and 200 owned; or the shared one at 25 of all six. |
| Move | Something a seat does, sent to the server and stored; the only way state changes. |
| Mutator | A named bundle of parameter overrides a session can switch on, such as the Trust fund. |
| Offline earnings | What managed businesses earn while the player is away: after 60 seconds, at 100%, for at most 12 hours. |
| Parameter | A named number a rule can read, with a default and optional limits. |
| Payback | The price of a unit divided by the extra income per second it adds. |
| Play record | A record created by playing: one set per seat per session. |
| Prestige | Giving up progress for a permanent bonus: here, selling up to angels. |
| Recipe | A module that is only data: it chooses mechanics and tunes their numbers. |
| Revision | A counter on the session that goes up by one with every move; a stale client is refused. |
| Seat | One participant of a session; every play record of this game belongs to one. |
| Seesaw | The balance between exponential cost and multipliers that keeps an idle game level. |
| Session | One play of a game: state, revision, seed and seats. |
| Settle | Work out and pay the cycles that fit between the last settle and now, keeping the remainder. |
| Trigger | A rule: when this event happens, if this condition holds, apply this effect group. |
| Version | A frozen copy of a game's design; improvements are new versions; new sessions use the newest. |
Quick answers
No. This lecture assumes neither. Lectures 3 and 4 show real Python, but they read it: each excerpt comes with its file and line numbers and a reading in plain words. If a word is new, it is in the glossary above.
No. It is built in the style of that game as an educational reference. The names, the six businesses, the artwork and the sound are our own, and every rule is written as data in Odoo. We use the public shape of the genre (exponential prices, managers, milestones, angels) because you already know it and can spend the day on how Odoo models it.
Because it holds no rules. It sends moves, draws the state it gets back and predicts smoothly in between. The server decides everything that matters, which is why the game cannot be cheated from the browser, and why a Godot or Unity client could replace it later with no change to the rules.
Yes, and that is the point of the studio. A price, a cycle, a reward is a field on a record. A published game is frozen, so you make a new version (a draft copy), change the record, and publish it; or you make a parameter, or write an include that patches one number. Lecture 7 does all three.
In the sense of the studio's North Star, yes: it has one to four seats (each with its own empire, so a table of friends is four separate games) and a platform-wide leaderboard to which only the rules can post. It is not real-time or competitive between players; that comes in other days.
The economy is deterministic: given the same moves and the same clock, it gives the same state. That makes it easy to test and to chart. Lecture 7 adds a "lucky customer" with a random table, and the seed makes even that replayable.
Nothing is lost. The game state lives on the server, in the database, not in the browser. When you come back, the client asks for your running session, and the server settles what your managers earned while you were away (up to 12 hours). The shell also keeps autosave slots as bookmarks.
The lectures are written to be read in a sitting each, and the build for a day is designed to be done in a day, one layer after another. Take the first lecture slowly: it is the one the other seven rely on.
Next: the design document
You now have the map: the game, its loop, its seven mechanics, its records, its numbers, its risks and its build plan. Lecture 2 turns the map into a design document, with diagrams of every kind, and the economy as charts you can read.
8
layers of the build
7
mechanics
6
businesses
13
parts in this lecture
Before you go on, play the game once more, and this time try to name which step of the core loop you are in.
Play Adventure Capitalist Back to the top
Sources of this lecture, all in the repository: courses/DAY_COURSE_SPINE.md, courses/day_01_adventure_capitalist/DESIGN.md and ITERATION.md, addons_recipes/game_recipe_adventure_capitalist/, the six mechanics under addons_mechanics/, docs/BIG_NUMBERS.md, docs/IDLE_MATH.md, docs/GAME_SHELL.md, docs/CLIENT_SERVICES.md, docs/INPUT_WEB.md and docs/NORTH_STAR.md. Screenshots were taken on 27 November 2026 from the live site.
The game in plain words, its core loop, every mechanic it uses and the build plan layer by layer.
There are no comments for now.