Agahnim's Blue Balls Statistics


The fight with Agahnim is more than just a fight; it's a gimmick in ALTTP speedruns across all categories. The main reason? It's completely random. So, if you're lucky, it can be very fast, but if you're less lucky, you can lose a whole minute, and if you're REALLY unlucky, it can even go up to almost 2 minutes!!

This entire page is an improved version of the Google Sheet I created in February 2018. Building this document required a lot of research (especially on how RNG works in ALTTP) and mathematical knowledge, and I discovered a much more complex mathematical model than I initially thought.

How many blue balls for this fight...?

How does it work?

The explanation is very simple, however, the resulting math is quite complicated. Agahnim can send 3 different attacks to Link:

Energy Balls
These are large energy balls that Link can reflect with his sword or the Bug-Catching Net. You need to send 6 of them back to Agahnim to end the fight.
Blue Balls
The famous blue balls that Link cannot reflect. They split into 6 when they hit an obstacle.
Lightning bolts
Agahnim will position himself at the top center of the room and fire a lightning bolt that will spread across the entire room in front of him. You can guess he's going to launch this attack because he doesn't turn towards Link before launching it, unlike with his other attacks.

Agahnim's attack pattern is cyclical and consists of 5 attacks interspersed with random movement in the combat arena (except for the lightning, where he systematically returns to the top center). The 5 attacks in a cycle are distributed as follows:

  1. 100% chance of sending an Energy Ball
  2. 50% chance of sending an Energy Ball / 50 % chance of sending a Blue Ball
  3. 50% chance of sending an Energy Ball / 50 % chance of sending a Blue Ball
  4. 50% chance of sending an Energy Ball / 50 % chance of sending a Blue Ball
  5. 100% chance of sending a lightning bolt

Thus, if you're lucky, Agahnim will only send Energy Balls and the fight will be short. But if you're unlucky, he'll spam Blue Balls and the fight will drag on. At high level, more than 3 and it's run over. For your information, one blue ball makes you lose about 6 seconds, and if Agahnim launches an additional lightning bolt, that also makes you lose 6 seconds.

It's also important to know that in ALTTP, as of writing (February 2023), RNG is still not manipulable and changes every frame, which means that to manipulate it, you would need to be sure of your inputs every frame from the start of the game. The fight against Agahnim occurs after 27~30 minutes into a run, making it humanly impossible.

The Data

The Table

Number of blue balls Probability Time lost (in seconds) Number of cycles Probability of number of cycles
0 6.25% 0 2 cycles 34.375%
1 12.5% 6
2 15.625% 12
3 31.25% 24 3 cycles 56.640625%
4 11.71875% 30
5 8.203125% 36
6 5.46875% 42
7 7.03125% 54 4 cycles 8.6669921875%
8 0.87890625% 60
9 0.48828125% 66
10 0.2685546875% 72
11 0.29296875% 84 5 cycles 0.3143310546875%
12 0.01220703125% 90
13 0.006103515625% 96
14 0.0030517578125% 102
15 0.0030517578125% 114 6 cycles 0.0030517578125%

The Graphs

Do your own calculations!

The above data isn't enough for you? Do your own calculations! Use the calculator below to see the probabilities of getting more or less than X blue balls.

The 15 blue balls

As you can see above, getting 15 blue balls is an infinitesimal chance. And no, I haven't forgotten to multiply by 100; this 0.003% is indeed the probability of getting 15 blue balls at the start of the fight, roughly one chance in 33,333.

Only one runner has ever managed to get these 15 blue balls while recording the video clip. And this, TWICE. This extremely unlucky runner is named Screevo (or Stephen to his friends), and here are the video clips of the two times Agahnim really messed him up:

The first time a recording was available (only game audio)
When he got them again (his reaction is priceless)

You may have noticed that the probability of getting 14 blue balls is the same as for getting 15 blue balls. This is normal, and the explanation will be given in the section below. Similarly, there is currently only one recording of a player who did not reach 15 blue balls, but stayed at the 14th. Misfortune within misfortune!

iLunix1006's 14 blue balls

For the nerds: the math behind it all

The theory behind Agahnim's blue ball probabilities is made somewhat complex by its semi-scripted pattern. In the paragraphs below, I explain the method I used to derive the formulas you'll see shortly. It goes without saying that all this math is completely useless for speedrunning; understanding the formulas and explanations that follow will not make your future battles faster since it's full RNG (and RNG is, among other things, based on a frame counter that we don't control), but personally, I believe they are interesting enough to be written here.

The Formulas

We place ourselves in a situation where the combat has not yet begun. If we define \(n\) as the number of blue balls, we have the following two formulas, where \(\left \lfloor x \right \rfloor\) is the integer part of \(x\), and \(\binom{n}{k}\) is the binomial coefficient "k choose n":

Probability of having n blue balls

$$p_{bb}(n) = \frac{\binom{n + 3 - \left \lfloor \frac{n}{4} \right \rfloor}{n}}{2^{n + 4 - \left \lfloor \frac{n+1}{4} \right \rfloor}}$$

Time lost for n blue balls

$$t_{loss}(n) = 6 \left (n + \left \lfloor \frac{n+1}{4} \right \rfloor \right )$$

Detailed explanations

For this explanation, you need to have a clear understanding of what an Agahnim pattern cycle looks like, which is explained in a paragraph above. The fight ends when Agahnim sends the 6th energy ball. The probability of having \(n\) blue balls depends on the 50% chance of attacks 2, 3, and 4 in a cycle. Naively, one might assume that having \(n\) blue balls in a fight is just the sum of \(1/2^n\) for all possible values \(n\) can take.

In reality, apart from 0 and 15, this hypothesis doesn't work well: since the first attack of each cycle is a 100% energy ball, calculating this way can yield a distribution of \(n\) blue balls that also includes those Agahnim releases after his 6th energy ball, which is not possible since the fight is already over at that point. Therefore, we need to take this into consideration for the calculation.

The way I proceeded with my calculations is very simple. But first, let's write all the attacks, represented by a number, including the energy ball that is necessarily released. Since lightning has no impact on the calculations (only on time lost), we will pretend it doesn't exist to simplify the explanation.

Cycle 1 Cycle 2 Cycle 3 Cycle 4 Cycle 5 Cycle 6
X X X X X X
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
The X above the attack number represents the 100% chance energy ball. The others are the 50/50 balls.

Let's first look at what happens for 0, 1, 2 and 3 blue balls and then try to generalize.

Case 0 blue ball

For 0 blue ball it's super simple: we know the fight ends at attack 6: indeed, all balls launched will necessarily be energy balls and it takes 6 to defeat Agahnim. So there's only one way to achieve this: attacks numbered 2, 3, 4, and 6 must be energy balls. This probability is \(1/2^4\) which gives \(1/16=6.25\%\) chance of happening.

Case 1 blue ball

For 1 blue ball, the fight will necessarily end at attack number 7. It cannot end at attack 6 as that is the 0 blue ball case, and ending at attack 8 would require 7 energy balls to do so, which is also not possible. The question now is which attack will be the blue ball.

Another thing we can mention is that the fight necessarily ends at attack 7, so the latter is necessarily an energy ball (it cannot end on a blue ball since Agahnim takes no damage from them). This remark removes the possibility for attack 7 to be a blue ball, which therefore leaves attacks 2, 3, 4, and 6 as potential blue balls.

The probability that one and only one of them is a blue ball is \(1/2^4\). But let's not forget attack number 7, which also has a 1 in 2 chance of being an energy ball, which is the case. Therefore, what we are looking for is the probability that one and only one of attacks number 2, 3, 4, and 6 is a blue ball, given that attack number 7 is an energy ball, which gives \(1/2^5\). Finally, we sum all these possibilities (the blue ball being either attack 2, attack 3, attack 4, or attack 6), which gives \(4/2^5=4/32=1/8=12.5\%\).

Case 2 blue balls

For 2 blue balls, I won't give you the full explanation again, but if you have read the previous paragraph, you will have understood that the fight ends at attack number 8, and that this attack number 8 is necessarily an energy ball. We must therefore choose two spots in the set \(\{2,3,4,6,7\}\), which will be our two blue balls.

The set above is a set of 5 elements and we must choose 2 from the pile: this is where the binomial coefficient comes in! If we write \(\binom{n}{k}\) as the binomial coefficient "k among n", then we have \(\binom{5}{2}\) possibilities for our two blue balls. All that remains is to combine this information with the probability of each possibility of having these 2 blue balls in the set \(\{2,3,4,6,7\}\) knowing that attack 8 is necessarily an energy ball, and that gives us the following result: \(\binom{5}{2}/2^6=10/64=15.625\%\) for 2 blue balls.

Case 3 blue balls

For 3 blue balls, the fight ends at attack 9. But this is where the calculation changes, because unlike cases 1bb and 2bb, attack 9 has a 100% chance of being an energy ball (see the table above). We still need to choose 3 spots for the blue balls in the set \(\{2,3,4,6,7,8\}\), which is equivalent to \(\binom{6}{3}\), however the probability by which we multiply this coefficient remains at \(1/2^6\) since attack 9 has a 100% chance of being an energy ball (technically it's also a probability "given that attack 9 is an energy ball", except that this probability is 1 this time). The probability of getting 3 blue balls in a fight is therefore \(\binom{6}{3}/2^6=20/64=31.35\%\).

Generalization

Let's conclude this series of examples with 4 blue balls. In this case, the fight ends at attack 10, which means it's an energy ball. But since attack 9 is also an energy ball, that leaves us with the 4 spots to choose from the same set as before, i.e., \(\{2,3,4,6,7,8\}\). The power of 2 in the probability will increment (and thus be \(1/2^7\)), given that attack 10 also had a 50% chance of being a blue ball, but in the binomial coefficient only the bottom number will be incremented, which gives \(\binom{6}{4}\).

From all this, we can generalize the process for each number of blue balls up to 15 (assuming the runner doesn't miss any energy balls to reflect, but that shouldn't happen anyway, right? 😇), the calculation being the same every 4 blue balls then changing with each new cycle due to this new attack having a 100% chance of being an energy ball.

And it's thanks to this that I obtained the formula above. Note, by the way, that the use of the floor function is there to adjust the probability for each new cycle. Otherwise, we would have obtained 5 different formulas, each corresponding to a different number of cycles.