I am building an agent-based simulation of a full economy using real economic formulas. The world is a procedurally generated grid with land and ocean climates, heatmaps of local desirability, and population clusters that grow into towns. Inside this world, thousands of people (agents) live. They age, form families, have children, hold jobs, earn income, shop, and migrate when opportunities look better somewhere else. Prices emerge from supply and demand rather than being hard-coded, and the whole system evolves minute by minute on an in-game clock.
Each person has a job and a daily rhythm. Work hours matter: when someone is at work they are not out shopping, and paydays directly affect what they can afford. Budgets are real constraints, so shopping choices depend on current wealth, prices, and what is already at home. Demand responds to price changes, so elasticity is accounted for in how people adjust their purchase plans. Households consume essentials first, and if food runs short there are consequences. Over time, people may switch professions, move homes, or start families if age and resources allow.
The map itself is generated and updated procedurally. Climates gate where people can live, heatmaps score local desirability, and clusters reveal where towns naturally form. Migration is not random wandering. People sample nearby locations and choose moves that trade off attractiveness and temperature, so large shifts tend to flow toward better jobs, safer resources, or denser markets. As towns grow, they pull in more people and trade, which feeds back into prices and availability. Towns can also fall apart under coded-in stressors, for example droughts, supply shocks, disease, or policy changes, forcing people to reorganize, relocate, or rebuild.
Markets are designed to be sophisticated rather than scripted. There is a catalog of goods with baseline values, and every person has a downward-sloping demand curve, so price elasticity is accounted for at the household level. Prices are not set by hand: they adjust toward market clearing, the point where total demand matches total supply. To get there, the simulator uses stable, well-behaved numerical routines, for example bisection or damped log-price steps with caps, that steer prices steadily instead of letting them oscillate or spike. Trades happen on a schedule, respect inventory and budgets, and play out differently across towns as local conditions change.
Data and analysis:
If you want to analyze results outside the simulation, you can save data to a database. This includes a detailed trade log and selected time series so you can inspect the market at the transaction level. You can query trades by time, buyer and seller, resource, price, quantity, town, and available wealth at the moment of purchase. This makes it simple to build charts of price trends, turnover, inventory levels, household spending, or the effects of shocks on different towns. Saving is optional and can be enabled when you want to do data visualization or research later.
Under the hood:
The simulator uses real economics and probability: price elasticity for household demand, Cobb-Douglas style production and utility where it fits, Poisson processes for the timing of rare events like career changes, moves, and births, and stable numerical routines for price adjustment so convergence is reliable. Time advances in fixed minute steps with an in-game calendar, so behavior like “after work, go shopping” is natural, not scripted.
Inspiration:
I’ve often seen video games praised for having “realistic” economies, and it made me wonder what would it actually take to build one from the ground up? That question became the spark for this project.
As I dug deeper, I realized the potential went beyond just a single simulation. By making the system configurable, I could turn my project into a flexible economy engine. This is something that developers could plug into their own games to bring dynamic, believable economic behavior to their worlds.
Dependencies:
SDL2 + SDL2 - TTF
Toml++
Fast C++ CSV Parser
Possibly SQLite
Screenshot from 9/5/25. I will attach a legend below to help users make sense of what they are seeing. Do note that the GUI will be the last thing being worked on and will look much cleaner in final release builds.
WARNING: THIS PROJECT IS A WORK IN PROGRESS. SOURCE CODE IS NOT YET AVAILABLE TO THE PUBLIC.
Copyright 2024 Tyler Pittman
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.