(tl;dr at bottom if you hate maths)
Hi All,
Thanks for coming to my post! I am currently developing a system in my game where player’s can upgrade their abilities (e.g., More Money, Lower Cooldown etc.). The premise of the game isn’t too important here, but in the game, players will be able to amass absolutely behemoth amounts of money (up to amounts like 10^1000000).
Each item in the shop has its own cost function which takes in the current level of that upgrade and returns the amount of money that it would take to upgrade it. For example, this is the cost function for cooldown, where C(x) is the cost to upgrade at a level x:
To avoid players with enormous amounts of cash repeatedly clicking upgrade (perhaps even forever), it’s essential that a “Max Upgrade” button is included to automatically max out the level given the player’s money. This is where the problem comes in.
For a max upgrade button, it seems that I have to calculate the series for every function for every item in the shop individually (which is a lot of series), and it seems to be that any method for determining how many levels a user can buy is extremely inefficient. I’m going to spare the details, but it’s in theory possible to calculate the series for any function like this, then use Newton-Raphson on it to get the maximum possible purchasable levels. However, because some of my functions can have extremely large gradients, Newton-Raphson barely moves and it can sometimes, with huge values, take millions if not billions of iterations to get the correct number of levels that the user can buy. Terrifying .
I’ve recently scrapped trying to use the aforementioned series method. Instead, I have tried to unify the max levelling algorithm under a singular function, and thought about using Riemann Sums / other similar methods to approximate a series given a cost function. I’ve unfortunately had a hard time implementing this. Even if I could approximate these series I would still have to approximate how many levels the user can buy using Newton-Raphson, which as explained earlier is something I just can’t do.
I’m honestly not entirely sure what to do, I’m thinking about changing this system to just avoid this problem altogether. I also know that I can make use of inverse functions if I make my functions less crazy. I have also found this Wikipedia Page on root-finding algorithms that might help me replace Newton-Raphson, but I don’t think any stand out to me.
tl;dr players can have huge amounts of money to buy upgrades, need a max levelling algorithm to find the amount of levels a player can buy given their money. each upgrade has a different cost function, want to just put it all under one max level calculating function. ideally want methods for series approximation and something other than newton raphson (because large gradients of functions) to find how many levels a user can afford.
Any help is greatly appreciated
Thanks!