# Math Help - Help! I can't figure out the expression i need for making a videogame.

1. ## Help! I can't figure out the expression i need for making a videogame.

ok, heres what needs to happen and what i got so far...
the game starts with 6 enemies (E) and after those 6 are dead, the next round starts, but this time with 9 enemies. the enemies are multiplied by 1.5 each round. also round up for example- 9 times 1.5 is 13.5(round up to 14) all of this will go at an infinite loop, but i dont know how id even write that out. let me know if i need to provide any more info!

its not necessarily an infinite LOOP, but an infinite CLIMB.

2. $E_1=6~\&~n\ge2,~E_n=\left\lceil {1.5 \cdot E_{n - 1} } \right\rceil$. That is the ceiling function.

3. what is N?

4. That is call a recursively defined function. $E_n$ is the number of enemies at the start of the $n^{th}$ game.
$E_1=6,~E_2=9,~\cdots~E_{10}=243$.

5. oh ok. and i really dont understand this. sorry, can you explain all the parts? like why you subtract a 1 or have n greaterthan or = to 2

6. Is this a game that *you* are making? If so, why does it have to be exactly 1.5? Why not just make it even like 2? Just curious.

Second here is some possible sudo code:

Integer num_enemies := 6
LOOP {
num_enemies := ROUND_UP(num_enemies * 1.5)
... cool game stuff goes here
}

The code just describes exactly what you said.

7. theres one problem with setting it to 2 instead of 1.5... the game would be impossible the enemies doubling each round is too hard for the player

8. Actually 1.5 * 1.5 = 2.25, so your enemies would more than double every two rounds anyway.
Anytime you multiply, you will get exponential growth.
If you want to make it easy, perhaps you can just add 6 enemies each round:
num_enemies := num_enemies + 6

9. ## Re: Help! I can't figure out the expression i need for making a videogame.

N is the nth battle. For example, if N is 1 then that's your first battle. On your second battle it requires another formula so that's why you have the second part of the mathematical equation. Note that the En-1 is the calculated number of enemies from the last battle because the Nth battle is the current battle and the Nth - 1 is the previous battle. Because that is subscripted under E then it is the Evaluated (aka calculated) result. You multiply that number by 1.5. And you perform a ceiling function on the new result.

I don't know what programming language is used so please excuse me if I am completely off here. I am a new member. I am also assuming that you can lose battles and then the next battles would be the same number of enemies.

You want to declare a global variable that stores the last calculated enemy count; call it enemyCount; Initialize that to 0 because you will have a first battle. You also want to declare a boolean variable to account for loses and wins; call it something like prevBattleLost; Initialize that to false because on your first battle you never lost before.

If a battle starts (like if your character is on a rpg type map and it just walked into a random tile that triggers battles) then call a function like battleStarted(). In that function use an if statement to check if enemyCount is 0 in which case you'd pass 6 to the enemy generator engine. There is an else statement that checks if prevBattleLost is true; If it were true then pass the enemyCount to the enemy generator engine because you did not win the previous battle so you will be fighting the same number of enemies in this battle. If not true, then send CEILING(enemyCount * 1.5) to the enemy generator engine because you won the previous battle so you will be fighting more enemies in this battle.

When the battle ends, you want to call either battleWon() or battleLost(). In the first function you would update prevBattleLost to false to account for the possibility of having had lost a battle, then also update enemyCount to the number of enemies defeated. In the second function, where you lost the battle, update prevBattleLost to true and leave enemyCount alone.

And please reconsider your old plan of multiplying by 1.5 because the enemies will become exponentially bigger. See:
6 x 1.5^(n-1) where n = which battle we are on from 1 to infinity

So that is similar to all solutions 1 x 2^0,1 x 2^1,1 x 2^2,1 x 2^3,1 x 2^4....; in other words, 1, 2, 4, 8, 16, 32, 64, 128, 256...

This kind of growth is exponential. Meanwhile, The player is getting into battles at a linear rate such as 1 battle a minute. Once the player levels up their stats enough to win a battle then the next battles will be lost too many times because it'd take forever to level up the stats. The player satisfaction will go down. However you could fix this by making leveling up stats at a exponential rate as well! Then it'd be one messy programming project.