Online game programming issues.

Click For Summary

Discussion Overview

The discussion revolves around calculating the cost of purchasing multiple buildings in an incremental game, where the price of each building increases based on the number already owned. Participants explore different formulas to determine costs and seek clarification on how to compute the total cost for buying multiple buildings at once.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Debate/contested

Main Points Raised

  • One participant presents a formula to calculate the cost of buying a set number of buildings, incorporating the price increase based on the number already owned.
  • Another participant provides a specific example using the formula, showing how to derive the number of buildings that can be purchased with a given amount of money.
  • A later participant expresses gratitude for the assistance but notes that their original formula is not functioning as intended and seeks a new formula for calculating the cost of multiple buildings at once.
  • Clarification is requested regarding the meaning of the price increase per building, leading to a discussion about the cost of subsequent buildings based on the number already owned.
  • One participant calculates the cost of purchasing additional buildings using the exponential price increase formula and confirms that it aligns with their budget.
  • Participants discuss the implications of the formulas and calculations, with one suggesting that the initial formula could be adapted to find the total cost for a larger number of buildings.

Areas of Agreement / Disagreement

Participants generally agree on the need for a formula to calculate the total cost of multiple buildings, but there is no consensus on the best approach or formula to use, as some participants express uncertainty about the original formula's effectiveness.

Contextual Notes

There are unresolved aspects regarding the assumptions behind the formulas, particularly how the price increases are calculated and the implications of purchasing multiple buildings simultaneously. The discussion reflects varying interpretations of the pricing model.

danielmchugh
Messages
3
Reaction score
0
Okay so i am building an incremental game and have a formula to work out how much it will cost to buy a set amount of buildings.

This is required as each time you buy a building the price for that building goes up.This formula is as follows:

((BaseCost * (1.07^b - 1.07^a)) / 0.07)BaseCost = Starting cost of buildings.

a = number of buildings i already own.

b = number of buildings i will own after buyingThis formula will give me a cost if i give it a set amount i want to buy.

But i need to work out how many i can buy with a finite amount of money, say 20000 if the base cost is 200 each and i already own 50.
 
Mathematics news on Phys.org
danielmchugh said:
Okay so i am building an incremental game and have a formula to work out how much it will cost to buy a set amount of buildings.

This is required as each time you buy a building the price for that building goes up.This formula is as follows:

((BaseCost * (1.07^b - 1.07^a)) / 0.07)BaseCost = Starting cost of buildings.

a = number of buildings i already own.

b = number of buildings i will own after buyingThis formula will give me a cost if i give it a set amount i want to buy.

But i need to work out how many i can buy with a finite amount of money, say 20000 if the base cost is 200 each and i already own 50.

Hi danielmchugh! Welcome to MHB! ;)

Filling in your numbers, we get:
\begin{aligned}\frac{200\times (1.07^b - 1.07^{50})}{0.07} &= 20000 \\
1.07^b - 1.07^{50} &= \frac{20000 \times 0.07}{200}\\
1.07^b &= \frac{20000 \times 0.07}{200} + 1.07^{50} \\
\ln\left(1.07^b\right) &= \ln \left(\frac{20000 \times 0.07}{200} + 1.07^{50}\right) \\
b \ln 1.07 &= \ln \left(\frac{20000 \times 0.07}{200} + 1.07^{50}\right) \\
b &= \frac{\ln \left(\frac{20000 \times 0.07}{200} + 1.07^{50}\right)}{\ln 1.07}
\end{aligned}
 
More generally, the formula is:
$$NrToOwn = \left\lfloor\frac{\ln \left(\frac{AvailableMoney \times 0.07}{BaseCost}+ 1.07^{NrOwned}\right)}{\ln 1.07}\right\rfloor$$

In your specific example, it's:
$$NrToOwn = \left\lfloor\frac{\ln \left(\frac{20000 \times 0.07}{200}+ 1.07^{50}\right)}{\ln 1.07}\right\rfloor
= \left\lfloor\frac{\ln 36.457}{\ln 1.07}\right\rfloor
= \left\lfloor 53.15\right\rfloor
= 53
$$
 
Thank you so much this is exactly what i needed! :)
 
danielmchugh said:
Thank you for replying again to the post it is exactly what i needed, after putting it in everything worked well but it has highlighted that my original formula is not working properly.

If each time you buy a building the price increases by baseCost * 1.07^N, what formula should i be using to find out the cost if i were to buy for instance 20 buildings in one go.

What do you mean exactly by "the price increases by baseCost * 1.07^N"?

Suppose you already own $N$ buildings and you've paid $Cost_N$ for the last building, what will you pay for the next building $N+1$?
And what will you pay for the one after if you buy both of them at the same time?
 
Sorry I ment to say:

Cost of building = BaseCost * 1.07 ^ Number already owned.

So if the base cost was 200 and i already owned 50 buildings.

Cost of one more building: $$$200 * 1.07 ^50 = $5891.4$$

So rather then running this multiple times over to find out how much it would cost to buy say 20 buildings at once, is there a formula i can use to get that answer directly?
 
Last edited:
danielmchugh said:
Sorry I ment to say:

Cost of building = BaseCost * 1.07 ^ Number already owned.

So if the base cost was 200 and i already owned 50 buildings.

Cost of one more building: $$$200 * 1.07 ^50 = $5891.4$$

So rather then running this multiple times over to find out how much it would cost to buy say 20 buildings at once, is there a formula i can use to get that answer directly?

Okay, so 3 more buildings would cost:
$$\$200 \cdot 1.07^{50} + \$200 \cdot 1.07^{51} + \$200 \cdot 1.07^{52}
= \$5,891.4 + \$6,303.8 + \$6,745.1 = \$18,940.3
$$
which is exactly what you can buy for $\$20,000$.
It brings you up to the $53$ buildings that the formula I gave earlier predicted.

The formula you gave yourself in the opening post tells us how much 20 more buildings will cost by substituting $a=50$ and $b=50+20=70$.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
1K
  • · Replies 26 ·
Replies
26
Views
3K
  • · Replies 7 ·
Replies
7
Views
5K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 9 ·
Replies
9
Views
5K
  • · Replies 16 ·
Replies
16
Views
3K
  • · Replies 6 ·
Replies
6
Views
3K
Replies
2
Views
3K
Replies
1
Views
2K