In Minecraft (sandbox video game made of blocks,written in Java), I have recently created a flying machine (assemble of blocks which moves on its own) and I have trouble calculating its speed, I hope someone can help me. Topic : probabilities
Context [vocab and general context]:
Minecraft runs on a clock, steping 20 times per second. There are 20 'game ticks' (gt for short) in a second, 72 000 gt per hour. Thunderstorm is a weather in the game and only during this weather, lightning bolts can appear. A chunk is a 16 wide *16 long *256 high piece of the world.
The duration of thunderstorms is between 3 600 and 15 600 gt (3 mins to 13 mins) with a pseudorandom uniform distribution [for details it is drawn with java.util.Random.nextInt(int bound = 12000)+3600]
The duration of 'clear' weather (time between thunderstorms) is similarly drawn but with bound of 168000 and added 12000 making it from 12 000 to 180 000 gt. It is assumed that the player don't sleep(=drawn time is the actual time between thunders).
During (only) thunder weather, there is a 1/(100 000) chance per gt of a lightning bolt occuring in a chunk.
A lighting bolt position in a chunk is randomly selected using a LCG (linear congruential generator) [with parameters $a=3,c=1013904223$ and $m=2^{32}$ for formula $X_{n+1} = (a*X_n + c) \mod m$] and can (I think) be associated with a uniform distribution for the coordinates of the position along the two horizontal axis [given basically by ((LCG >> 2) & 15) for one axis and ((LCG >> 2) >> 8 ) & 15 ] and the vertical coordinate is given by the block at the highest position (top-most block vertically).
There is then a $\dfrac{1}{100\, 000} * \dfrac{1}{16*16} = \dfrac{1}{25\, 600\, 000} $ chance per gt of a lighting bolt hitting a block (my block is placed to be the highest in its column of blocks) when it is thundering. [these probabilities are independant, therefore multiply them to get the proba of both happening, the target block can only be in 1 chunk at a time]
My flying machine need, to progress 1 block forward, 1 lighting bolt hit on 1 block [a piston that reacts to the lightning bolt] and to move 2 blocks forward, it requires 2 lightning bolts, spaced in time by 9 gt and the second lightning bolt (bolt for short) needs to happen at a different coordinate than the previous one (1 block offset in a horizontal direction). The targeted block may have moved to a different chunk (I don't think it changes the results).
If the second bolt did not happen at the right place/time, then the flying machine flies back in the other direction with a speed of 10gt per block (as opposed to the 9gt per block of the +X movement). We have these two 'forces' opposing : the random lightning bolts pushing the flying machine forward (let's say in the +X direction) while another circuit pushes the flying machine backwards (-X direction) if bolts are not received at the right time and place.
Problem
Based on the context, you probably think that the flying machine mostly goes in the -X direction seeing how rare thunderstorms and lightning bolts are (its true !), the problem formulates as follows :
What is the probability that this machine travels 30 M(million) blocks in the +X direction ?
Resolution attemp :
We'll start by seeing a few usefull observations then formulate more clearly then I will describe my attempt.
Observations
The flying machine is faster in the +X direction (9gt per block) than in the -X direction (10gt per block).
There is a lot more time on average where it is not thundering as the average off thunder (no thunderstorms) is 96 000 gt (consecutive)(80 mins) while the average thunderstorm duration is only 9 600 gt(consecutive)(8 mins).
The maximum distance traveled during a thunderstorm (+X direction) (15 600gt) is $\frac{15600 }{9} = \frac{5200}{3} \approx 1\, 733.\overline{3}$ blocks while the minimum distance traveled during clear weather (-X direction(dir for short)) is $\frac{12000 }{10} = 1200$ blocks which is less than the maximum +X dir distance, with a maximum overall forward distance of $\frac{5200}{3}-1200=\frac{1600}{3} \approx 533.\overline{3}$ blocks ==> it is possible to overall go forward.
For the maximum thunderstorm duration, the given clear weather duration that moves the same distance (but opposite direction) is $\frac{15600 }{9}*10 = \frac{52000}{3} \approx 17333.\overline{3}$ gt (which is an integer in reality). This means that any clear weather duration over this number will result in a total (during a cycle thunder, no thunder) distance in the -X direction no matter the thunderstorm duration.
Oppositely, for the maximum clear weather duration, the maximum number of blocks progressed in the -X direction is $\frac{180 000}{10} = 18 \,000$ blocks as, even during a thunderstorm, it is not garanted to go forward at all (no lightning bolts)
Mathematical formulation
A parameter $F$ (forward) is given initialy by a random uniform distribution (integers) $U(3\, 600,15 \, 600)$
A parameter $B$ (backward) is given initialy by a random uniform distribution (integers) $U(12\, 000,180 \, 000)$
A parameter $L$ (lightning bolt) is given by a descrete probability $p_L = \dfrac{1}{25\, 600 \, 000}$
A parameter $T$ (thundering) that is true or false (1 or 0) that says when it is thundering
A parameter $x_n$ (position from the origin ($x_0=0$)) of the flying machine with conditions that $x_n>0,\forall n \in \mathbb{N}$
The pseudo algorithm of the process is described here
When T switches from 0 to 1 : draw F
When T switches from 1 to 0 : draw B
If T is 1: (thunderstorm)
cycle F number of times:
if cooldown is 0:
draw L (lightning bolt occur ?)
otherwise :
subtract 1 from cooldown
if L is 1 (success):
cooldown is set to 9 gt
x_n is increased by 1
L is to 0
if cooldown is -1 :
x_n is decreased by 1
cooldown is set to 10
set T to 0 once cycle is finished
if T is 0 : (clear weather)
x_n is decreased by min(x_n,B/10)
(min to not become negative
set T to 1
The goal is to calculate the time taken on average for x_n to reach 30 000 000.
My resolution attempt
I tried to bound the minimum time : from the previous observations, we can travel forward (+X dir) as maximum of 533 blocks every thunder and clear weather cycle, so every 27 600 gt. This gives us the shortest time possible with perfect luck of $ \frac{27600}{533}\times 30\, 000 \, 000 = 1 553 470 920$ gt (59.1 years (fast!))
Then I tried to estimate it using gambler's ruin but am not sure at all if I used it corectly. There are 6 480 000 couples (thunder, clear) with a positive amount of ticks (thunder gt-clear gt) out of the 2 016 000 000 couples possible, giving a probability of 0.32142857 % to have a couple with more thunder gt than clear gt.
Doing the sum of the values of all the couples (thunder gt-clear gt) gives a value of 7 782 481 200, which I after multiplied it by probability of it beeing positive to give the overal expected value of positive couples : $p =25\, 015\, 118$.
then using this formula I found online, we can calculate the expected nb of gt to have to wait to have 9*30M gt : $ p+ \dfrac{\left(p\right)^{9*30*10^6-1}-1}{p-1}$ Which gives a result of around $10^{(10^{9.3})}$
That is the expected time to wait before the thunder/clear weather cycle give the right conditions to reach the goal with perfect lighting bolts luck.
To take into account I use the same formula but swapping the $p$ for the $1/p_L$ (average time between good lighting bolts and with the time calculated above, giving the formula
$ \dfrac{1}{p_L}+ \dfrac{\left(\dfrac{1}{p_L}\right)^{10^{(10^{9.3})}-1}-1}{\dfrac{1}{p_L}-1}$ Which gives a result of (around) $10^{(10^{(10^{(9.3)})})}$ gt
Which is very slow !
Conclusion
I am really not sure about these calculations and would like if anyone could guide me to find the speed of this machine. It is expected to take a lot longer than $7*10^{9*10^7}$ but the upper bound has no estimate. I would gladly answer any questions about details or general questions to help resolve this problem.
Thank you for reading !