Work out how many buildings the player can buy when each costs more
A buy-as-many-as-possible button is simple when every house costs the same, and wrong the moment each new house costs a little more than the one before. This entry finds the largest number the player can afford in every resource at once, and what that purchase will cost in total.
Why this works
The price of the next one depends on how many you hold, so buying ten is not ten times the first price. Because every extra unit only ever costs more, the affordable amount has a clear edge that can be found without buying one at a time.
When not to use it
Don't use it when prices jump in tiers, drop for bulk buys or change with the market during the purchase. A price that is not steadily rising breaks the shortcut; then simulate the purchases one after another and stop at the first refusal.
In the full entry
- What to build, step by step
- Starting values and the reason for each
- 4 common mistakes and the fix
- 29 lines of example code with 3 checks that pass
- How your AI shows you that it works
Say this to your AI
Use the Spielerando entry "Work out how many buildings the player can buy when each costs more" (read_entry buy-max-with-rising-unit-cost) in my game. Build it step by step, and show me how you checked that it works.Or skip this and connect the MCP: your AI then finds all of this by itself.Connect the MCP