# Finding the probability of going infinite with Nexus of Fate

Aug 6th, 2018
258
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. package nexusoffate;
2.
3. import java.util.Arrays.*;
4.
5. public class NexusOfFate {
6.
7.     public static void main(String[] args) {
8.
9.         //Declare variables
10.         int ExtraCardDrawPerTurn=2;
11.         double[][][][] TransitionMatrix = new double[21][41][21][41];
12.         int ExtraTurns; int CardsInDeck; int FROMExtraTurns; int FROMCardsInDeck; int TOExtraTurns; int TOCardsInDeck; int BETWEENExtraTurns; int BETWEENCardsInDeck;
13.         boolean WeGoInfinite;
14.         //Note that since we draw cards after casting Nexuses, we'll always have at least 4 cards in library at that point
15.         //State with 0 extra turns, 0 cards in library => Absorbing, opponent took a turn
16.         //State with 20 extra turns, 0 cards in library => Absorbing, we go infinite
17.
18.         TransitionMatrix[0][0][0][0]=1;
19.         TransitionMatrix[20][0][20][0]=1;
20.
21.         for ( FROMExtraTurns=0; FROMExtraTurns<=10; FROMExtraTurns++){
22.             for ( FROMCardsInDeck=4; FROMCardsInDeck<=40; FROMCardsInDeck++){
23.
24.                 WeGoInfinite=false;
25.                 if (FROMExtraTurns==20 || FROMExtraTurns*(1+ExtraCardDrawPerTurn)>FROMCardsInDeck) {WeGoInfinite=true;}
26.
27.                 if (ExtraCardDrawPerTurn==1 && !WeGoInfinite){
28.                     double ProbDrawFate1=4.0/FROMCardsInDeck;
29.                     double ProbDrawFate2=4.0/(FROMCardsInDeck-1);
30.                     TransitionMatrix[FROMExtraTurns][FROMCardsInDeck][Math.min(FROMExtraTurns+1,20)][FROMCardsInDeck]=ProbDrawFate1*ProbDrawFate1;
31.                     TransitionMatrix[FROMExtraTurns][FROMCardsInDeck][FROMExtraTurns][FROMCardsInDeck-1]=TransitionMatrix[FROMExtraTurns][FROMCardsInDeck][FROMExtraTurns][FROMCardsInDeck-1]+ProbDrawFate1*(1-ProbDrawFate1);
32.                     TransitionMatrix[FROMExtraTurns][FROMCardsInDeck][FROMExtraTurns][FROMCardsInDeck-1]=TransitionMatrix[FROMExtraTurns][FROMCardsInDeck][FROMExtraTurns][FROMCardsInDeck-1]+(1-ProbDrawFate1)*ProbDrawFate2;
33.                     if (FROMExtraTurns>0) {TransitionMatrix[FROMExtraTurns][FROMCardsInDeck][FROMExtraTurns-1][FROMCardsInDeck-2]=(1-ProbDrawFate1)*(1-ProbDrawFate2);}
34.                     if (FROMExtraTurns==0) {TransitionMatrix[FROMExtraTurns][FROMCardsInDeck][0][0]=(1-ProbDrawFate1)*(1-ProbDrawFate2);}
35.                }
36.
37.                if (ExtraCardDrawPerTurn==2 && !WeGoInfinite){
38.                     double ProbDrawFate1=4.0/FROMCardsInDeck;
39.                     double ProbDrawFate2=4.0/(FROMCardsInDeck-1);
40.                     double ProbDrawFate3=4.0/(FROMCardsInDeck-2);
41.                     //Hit-Hit-Hit
42.                     TransitionMatrix[FROMExtraTurns][FROMCardsInDeck][Math.min(FROMExtraTurns+2,20)][FROMCardsInDeck]=ProbDrawFate1*ProbDrawFate1*ProbDrawFate1;
43.                     //Hit-Hit-Miss
44.                     TransitionMatrix[FROMExtraTurns][FROMCardsInDeck][Math.min(FROMExtraTurns+1,20)][FROMCardsInDeck-1]=TransitionMatrix[FROMExtraTurns][FROMCardsInDeck][Math.min(FROMExtraTurns+1,20)][FROMCardsInDeck-1]+ProbDrawFate1*ProbDrawFate1*(1-ProbDrawFate1);
45.                     //Hit-Miss-Hit
46.                     TransitionMatrix[FROMExtraTurns][FROMCardsInDeck][Math.min(FROMExtraTurns+1,20)][FROMCardsInDeck-1]=TransitionMatrix[FROMExtraTurns][FROMCardsInDeck][Math.min(FROMExtraTurns+1,20)][FROMCardsInDeck-1]+ProbDrawFate1*(1-ProbDrawFate1)*ProbDrawFate2;
47.                     //Miss-Hit-Hit
48.                     TransitionMatrix[FROMExtraTurns][FROMCardsInDeck][Math.min(FROMExtraTurns+1,20)][FROMCardsInDeck-1]=TransitionMatrix[FROMExtraTurns][FROMCardsInDeck][Math.min(FROMExtraTurns+1,20)][FROMCardsInDeck-1]+(1-ProbDrawFate1)*ProbDrawFate2*ProbDrawFate2;
49.                     //Hit-Miss-Miss
50.                     TransitionMatrix[FROMExtraTurns][FROMCardsInDeck][FROMExtraTurns][FROMCardsInDeck-2]=TransitionMatrix[FROMExtraTurns][FROMCardsInDeck][FROMExtraTurns][FROMCardsInDeck-2]+ProbDrawFate1*(1-ProbDrawFate1)*(1-ProbDrawFate2);
51.                     //Miss-Hit-Miss
52.                     TransitionMatrix[FROMExtraTurns][FROMCardsInDeck][FROMExtraTurns][FROMCardsInDeck-2]=TransitionMatrix[FROMExtraTurns][FROMCardsInDeck][FROMExtraTurns][FROMCardsInDeck-2]+(1-ProbDrawFate1)*ProbDrawFate2*(1-ProbDrawFate2);
53.                     //Miss-Miss-Hit
54.                     TransitionMatrix[FROMExtraTurns][FROMCardsInDeck][FROMExtraTurns][FROMCardsInDeck-2]=TransitionMatrix[FROMExtraTurns][FROMCardsInDeck][FROMExtraTurns][FROMCardsInDeck-2]+(1-ProbDrawFate1)*(1-ProbDrawFate2)*ProbDrawFate3;
55.                     //Miss-Miss-Miss
56.                     if (FROMExtraTurns>0) {TransitionMatrix[FROMExtraTurns][FROMCardsInDeck][FROMExtraTurns-1][FROMCardsInDeck-3]=(1-ProbDrawFate1)*(1-ProbDrawFate2)*(1-ProbDrawFate3);}
57.                     if (FROMExtraTurns==0) {TransitionMatrix[FROMExtraTurns][FROMCardsInDeck][0][0]=(1-ProbDrawFate1)*(1-ProbDrawFate2)*(1-ProbDrawFate3);}
58.                }
59.
60.                if (WeGoInfinite){
61.                     TransitionMatrix[FROMExtraTurns][FROMCardsInDeck][20][0]=1;
62.                }
63.
64.             }
65.         }
66.
67.         double[][] StartingDistribution = new double[21][41];
68.         double[][] NewDistribution = new double[21][41];
69.
70.         for (int StartingDeckSize=4; StartingDeckSize<=40; StartingDeckSize++){
71.
72.
73.             for ( ExtraTurns=0; ExtraTurns<=20; ExtraTurns++){
74.             for ( CardsInDeck=0; CardsInDeck<=40; CardsInDeck++){
75.                 StartingDistribution[ExtraTurns][CardsInDeck]=0;
76.                 NewDistribution[ExtraTurns][CardsInDeck]=0;
77.             }}
78.             StartingDistribution[2][StartingDeckSize]=1;
79.
80.             for (int Turn=1; Turn<=60; Turn++){
81.                 for ( FROMExtraTurns=0; FROMExtraTurns<=20; FROMExtraTurns++){
82.                 for ( FROMCardsInDeck=0; FROMCardsInDeck<=40; FROMCardsInDeck++){
83.                 for ( TOExtraTurns=0; TOExtraTurns<=20; TOExtraTurns++){
84.                 for ( TOCardsInDeck=0; TOCardsInDeck<=40; TOCardsInDeck++){
85.                     NewDistribution[TOExtraTurns][TOCardsInDeck]=NewDistribution[TOExtraTurns][TOCardsInDeck]+StartingDistribution[FROMExtraTurns][FROMCardsInDeck]*TransitionMatrix[FROMExtraTurns][FROMCardsInDeck][TOExtraTurns][TOCardsInDeck];
86.                 }}}}
87.
88.                 for ( ExtraTurns=0; ExtraTurns<=20; ExtraTurns++){
89.                 for ( CardsInDeck=0; CardsInDeck<=40; CardsInDeck++){
90.                     StartingDistribution[ExtraTurns][CardsInDeck]=NewDistribution[ExtraTurns][CardsInDeck];
91.                     NewDistribution[ExtraTurns][CardsInDeck]=0;
92.                 }}
93.             }
94.             System.out.println(StartingDistribution[20][0]);
95.
96.         }
97.
98.     }
99. }
RAW Paste Data