### Introduction

We know that chaining pokemon while fishing increase the probability to find a shiny pokemon. Some people think the chain increase the probability until the 40th encounter, but like the dexnav until few days ago, the real probabilities are unknown. So to continue my work on probabilities to find shiny pokemons, I decided to investigate the chain fishing. I will not talk another time of how the game treats the shininess, and neither the base probability to find a shiny pokemon.

### How the chain fishing increases the probability

The game is actually able to compute multiple PID when the pokemon is generated, for each one it checks if it is shiny and if the PID is effectively shiny then it stops computing PIDs.

So basically it looks like that :

```
unsigned int n = ...;
...
unsigned int PID;
for(unsigned int i = 0; i < n; i++)
{
PID = randomPID();
if(isShiny(TID, SID, PID)) break;
}
```

So to increase the probability, the game just increases the value of n. The base value of n is 1 and with the shiny charm it is incremented by 2. When you do a chain fishing, the game counts the number of chained encounters and for each new chained pokemon, it increments n by 2. But is the probability increased until the chain is broken or is there a maximum value ?

### The maximum chain value

Analysing the heap memory I just located where the current chain count is stored. Then I manually edited this value, replaced it by something very big like 255, and looked how n was incremented. And here is the result, n is increased until the chain reaches the 20th pokemon. So n is computed like this :

```
unsigned int chain = ...;
...
unsigned int n = 1;
if(shiny_charm)
n += 2;
if(fishing)
{
if(chain > 20)
chain = 20;
n += 2 * chain;
}
```

Let A be the event : "the PID is shiny". We have P(A) = 1/4096. We repeat the experiment n times and X is the step when the event A is realized, if the event never happens then we consider X=0.

So finally we have :

```
P(X >= 1) = 1 - P(X = 0)
P(X = 0) = pow((1 - (1/4096)), n)
= pow(4095/4096, n)
P(X >= 1) = 1 - pow(4095/4096, n)
```

### Conclusion

We are now able to compute the probability to find a shiny pokemon when using the chain fishing method. We may remark that it is quite effective, here is my calculator allowing you to compute the probability based on your chain : 6th gen shiny calculator