Online game programming issues.

In summary: The formula I gave you in my previous post tells us how many more buildings we can buy for $\$20,000$ by substituting $NrOwned=50$ and $AvailableMoney = \$20,000$.So there are actually two different formulas at work here, and both are correct. The one I gave you in the previous post tells us how many more buildings we can buy for a given amount of money. The one you gave yourself tells us how much more money we need to buy a given number of buildings.
  • #1
danielmchugh
3
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
  • #2
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}
 
  • #3
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
$$
 
  • #4
Thank you so much this is exactly what i needed! :)
 
  • #5
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?
 
  • #6
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: \(\displaystyle $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:
  • #7
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: \(\displaystyle $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$.
 

1. What programming languages are commonly used for online game development?

The most commonly used programming languages for online game development are C++, Java, and JavaScript. Other languages that are also used include Python, C#, and HTML5.

2. What are some common challenges faced in online game programming?

Some common challenges in online game programming include optimizing network performance, managing server load, and dealing with security issues such as cheating and hacking. Another challenge is ensuring cross-platform compatibility.

3. How do online game developers handle real-time gameplay?

Real-time gameplay in online games is usually handled through client-server architecture, where the game logic is run on the server and the client devices send and receive data to keep the game in sync. This allows for multiplayer gameplay and prevents cheating.

4. How do online games handle large amounts of data?

Online games handle large amounts of data by using databases to store and retrieve information such as player profiles, game progress, and in-game items. Advanced data management techniques such as sharding and caching may also be used to improve performance.

5. What are some common techniques for optimizing online game performance?

Some common techniques for optimizing online game performance include using efficient algorithms and data structures, minimizing network traffic, and implementing client-side prediction. Caching, load balancing, and server clusters can also help improve performance for large-scale online games.

Similar threads

  • General Math
Replies
2
Views
896
Replies
9
Views
2K
Replies
26
Views
2K
Replies
2
Views
793
  • General Math
Replies
13
Views
1K
Replies
10
Views
952
  • General Math
Replies
1
Views
2K
  • General Math
Replies
16
Views
2K
Replies
1
Views
1K
  • Computing and Technology
Replies
2
Views
1K
Back
Top