 Hi everyone, it's Crypto Grounds here and welcome back to another idle game tutorial series. This is episode 7 and today we're going to begin working on the Biomax equation. So for this video I'm going to be discussing the math side of things just so everyone understands how the Biomax actually works instead of just pulling a random equation and throwing it at you guys and not really explaining it that well. So if you guys have seen the old series, the 2019 edition of this whole series, I did do a Biomax math explain video, however I kind of just had the cost equation and then came up with it out of the spot and not actually figure out how I got it because I personally didn't know how I was able to get this equation. I kind of just did some of the math and not explain everything. So this video is going to cover everything and if you're not really a math person this video may be a little tough for you so just I want to make sure you understand that this equation isn't just made up or anything and that there is some like mathematical reason behind them. But yeah, again, this is just going to be the math explain video. In the next one, 7.1, we're going to be actually and we're going to be implementing these equations in the code. One more heads up. I did make a promise recording the whiteboard clips that I would do an explanation for the exponential and linear equations. However, I wasn't able to figure out the linear ones. You'll see me explain why once I get there and I was only able to do exponential equations. So I hope this video ends up being helpful and I'll transition to the whiteboard. All right, so we are on the whiteboards and as you can see there is a lot of math. There's even another side for this. So if you're not a very good math person, this might be a little tricky to keep up with. Understanding fundamentally how the by max equation and all that stuff works is kind of important. So you just don't throw it into your game blindly, just not knowing what it does and how it works. And if you don't know how it works and if there's a bug for some reason, then you won't be able to fix it. So I'll be doing my best to explain how this by max equation works. So the first one to be talking about is the exponential equation. So after this, we will be talking about the linear one. So we'll start here. So assuming that our cost is equal to this exponential equation, which in our case it will be obviously, cost is equal to base times multiplier to the power of level. Then we're going to use the c equals b times m to the power of l to solve for various equations. So for one, we're going to start with here. So if we're buying just one upgrade at a time, then our equation is simple. Our cost is going to be b times m to the power of l. However, if we were to buy n amount of upgrades, so let's say we're buying two, three, sorry, people are playing with flutes outside of our house for whatever reason. I don't know. But anyways, let's say we were buying more than one upgrade and we're buying n amount of upgrades. So that just could be any amount, two, three, four, or a hundred or so on. Then our equation is going to be equal to the sum of b times m to the power of l plus k. So basically how this works is that if this n was a one, we are calculating the sum of this one time and k starts at zero. Now if n was two, and end up with k equals one, and we get some kind of addition down here, but let's just stick with the sum. So we're basically just adding up this based on whatever k is n amount of times. And the problem with this is that involves four loops, which we do not want. If we use four loops, we'll get an O and algorithm and that could be improved to O one, where we just got to run it once. We don't have to do any four loops and stuff like that. So let's expand this sum to something like this. So basically all I did was just pull out the k from the l plus k exponent, which m to the power of l plus k is equal to m to the power of l times m to the power of k. So it would look like that. And since there's no k inside b or m to the l, we can take this out of the sum because that's not going to change what our result is. So we're basically just multiplying this by the sum of m to the power of k. And if we were to expand this sum, you could see it looks something like this. So it's b times m to the power of l, and all that times m to the power of 0 plus m to the power of 1, and so on all the way up to m to the power of n. And so this is what I meant by sum. We're taking the sum of all of these based on whatever n is. All right, so for example, just ignore this equation here. We'll explain how we get here later on. But let's just say our n is equal to 4. For example, our cost for the four upgrades can be equal to b times m to the power of l, all that multiplied by m to the power of 0, and all the way to m to the power of 3. However, we can simplify this equation. So let's head to the other side. So this is kind of weird how I did this. It probably could have been done in a much easier fashion, probably with an integral or something like that. But I did it this way anyways, because that's just what came to mind. But basically, I set these two equations equally to each other. So we have our m to the power of 0 all the way to m to the power of 3. And that's going to be equal to our next cost multiplier, so m to the power of 4. So these are the cost molds from 0 to 3. And this is the next one. So let's say our cost multiplier, m, is equal to 3. So you basically just set m to all these 3's, which that's just m to the 0, m to the 1, m to the 2, m to the 3. And you add them up, and you get 40. And m to the 4 is 81. You can see that these are not equal to each other. But we want our m4 term to be equal to this term. We want to simplify this, because we don't want to take any sort of sums or use for loops in order to solve for what this is. So what we can do is we notice that if we subtract 1 from 81, we get 80. And then we can divide that by 2, and that's 40. I'll explain this in a second. Let's try m equals 4. So let's just see this works for any value of m. So we do m, so we get 1 plus 4 plus 16 plus 64, and it's equal to 256. And we know that 85 is definitely not equal to 256, so we can do the same thing. We subtract 1 from 256, and we divide this term, 255 by 3, and we get 85. So there's a cool pattern here. So if you may notice that this top numerator term for here, m equals 3, and m equals 4, is literally just m to the power 4 minus m0. So here, it's just 4 to the power 4 minus 1, which is just m to the power of 0. And it's the same thing up here, but with m is equal to 3. And for the denominator, it's just m minus 1. So now we can use this knowledge to say that m to the power 4 is equal to m to the power 4 minus 1 over m minus 1. And now this is nice because we know what our multiplier is, and we know what that is to the power of 4. And we have just 1, and it's m minus 1. So we don't need to add up anything. We don't need to do m0 plus m1 in all that junk. And therefore, our m to the power of n is equal to the same thing as above, but with n. So it's this very simple, friendly equation. So then what we can do is that we can substitute this long sequence here, or this potentially long sequence, with just a simple equation. So for our n equals 4 example, all we have here is just b times n to the power of l multiplied by m to the power of 4 minus 1 over m minus 1. And then therefore, we can say that our cost for however many upgrades we want to buy based on n is equal to this equation. So it's very nice. We don't need to take any sums. We just plug in a few numbers and we get our answer right away. So this is considered an O1 algorithm, so it only runs one time. And if we were to use this one above or this sum actually, we would just get On, which is less efficient than O1. That is our goal. We want to simplify our equations as much as possible, get rid of any form of for loops, and we did exactly just that. All right, so we have our total cost. We need to figure out what n is because we don't know what that is. And the purpose of the bymax is to see what is the highest n we could get. So that's where the second report comes into play. All right, so just to remind you guys that the cost for buying n amount of upgrades is this equation right here, where b is equal to the base cost, m is equal to cost molt, and l is equal to the current level. And n is how many upgrades we're buying. So we need to find what n is, which is the max amount of upgrades we can afford based on c. And we will use that by just rewriting our equation. So we first start off with this, and then we divide both sides by b times m to the power of l. And then we multiply both sides by n minus 1, and then we add 1 to both sides. And then we take the log base m to get rid of this exponent. And this right here is a basic log rule where basically, if we take any log with the base x, we can get rid of this x right here. So log base x of x to the power of y is just going to equal y. So then we have our n. But there's one more step we need to do, and that is to floor this entire equation. And the reason we want to do this is because we want round numbers only. Now if for some reason your upgrades are not rounded up to the next whole number, then you can ignore this step. But since my upgrades are always whole numbers, we floor this. So basically what this does is just round it down to the previous whole number. So floor 4.8 is going to equal to four. Now if we were to do the same thing for floor, I don't know, 5.2, we're going to get five. Now the ceiling will do the opposite. Ceiling will round it up to the next whole number. So now in the next episode, you're going to need this equation, that cost, and your maximum amount of upgrades you can buy equations. That's this one. And just to remind you what all these mean, there you go. And notice that C is not cost anymore. It's the currency you have. So it's the currency you're wanting to spend to get an amount of upgrades. So I know that was a lot of math, but hopefully you can understand that these equations don't come from nowhere. All right, now it's time to talk about the linear equations. So I tried doing bimax for linear, however, it's kind of not working out. It looks very ugly. And for some reason, this is much harder than the exponential equation. So I am going to skip the linear equation for bimax. I, yeah, sorry if it's an inconvenience for anyone, but I just don't have the skill level to be able to create a bimax equation from scratch using the linear cost equation. Basically equals lot times level. Yeah, anyways, I'm just not going to include this in code. So if you can somehow figure out, I'll be awesome. And yeah. Anyways, I hope this explanation was very helpful and you're excited to implement your first bimax if you haven't already. And if it was helpful and you enjoyed it, please leave a like as it really helps out the videos. Subscribe to my channel and turn on the notifications if you want to be notified for future videos. And YouTube recently added the thanks button to support creators like me. So if you're interested in that, hit that button below. And that is it for this video. So I will see everyone in the next episode of 7.1 and that will be implementing the bimax in the code. I hope you all have a wonderful day and I can't wait to see you guys in the next one. Peace. I'll see you guys in the next one.