Skip to content

Instantly share code, notes, and snippets.

@flyingmutant
Last active August 29, 2015 14:26
Show Gist options
  • Save flyingmutant/3c0af42110481451d33d to your computer and use it in GitHub Desktop.
Save flyingmutant/3c0af42110481451d33d to your computer and use it in GitHub Desktop.
package manabase;
import java.util.Arrays.*;
import java.util.Random;
public class ManaBase {
public static void main(String[] args) {
Deck deck=new Deck();
int NrIterations=1000000;
int NrGoodLandsNeeded=2;
int TurnAllowed=2;
int NrCards=99;
int NrLands=40;
int CardType;
int LandsInHand;
int GoodLandsInHand;
boolean Mulligan;
for (int NrGoodLands=6; NrGoodLands<=24; NrGoodLands++){
double CountOK=0.0;
double CountConditional=0.0;
for (int i=1; i<=NrIterations; i++){
//Draw opening 7
deck.SetDeck(NrLands, NrGoodLands, NrCards);
LandsInHand=0;
GoodLandsInHand=0;
for (int j=1; j<=7; j++){
CardType=deck.DrawCard();
if (CardType<3) {LandsInHand++;}
if (CardType==1) {GoodLandsInHand++;}
}
Mulligan=false;
if (LandsInHand<2) {Mulligan=true;}
if (LandsInHand>5) {Mulligan=true;}
//Mulligan to 6
if (Mulligan){
deck.SetDeck(NrLands, NrGoodLands, NrCards);
LandsInHand=0;
GoodLandsInHand=0;
for (int j=1; j<=6; j++){
CardType=deck.DrawCard();
if (CardType<3) {LandsInHand++;}
if (CardType==1) {GoodLandsInHand++;}
}
Mulligan=false;
if (LandsInHand<2) {Mulligan=true;}
if (LandsInHand>4) {Mulligan=true;}
}
//Mulligan to 5
if (Mulligan){
deck.SetDeck(NrLands, NrGoodLands, NrCards);
LandsInHand=0;
GoodLandsInHand=0;
for (int j=1; j<=5; j++){
CardType=deck.DrawCard();
if (CardType<3) {LandsInHand++;}
if (CardType==1) {GoodLandsInHand++;}
}
Mulligan=false;
if (LandsInHand<1) {Mulligan=true;}
if (LandsInHand>4) {Mulligan=true;}
}
//Mulligan to 4
if (Mulligan){
deck.SetDeck(NrLands, NrGoodLands, NrCards);
LandsInHand=0;
GoodLandsInHand=0;
for (int j=1; j<=4; j++){
CardType=deck.DrawCard();
if (CardType<3) {LandsInHand++;}
if (CardType==1) {GoodLandsInHand++;}
}
}
//Draw cards for the number of turns available
for (int turn=1; turn<=TurnAllowed-1; turn++){
CardType=deck.DrawCard();
if (CardType<3) {LandsInHand++;}
if (CardType==1) {GoodLandsInHand++;}
}
if (GoodLandsInHand>=NrGoodLandsNeeded) {CountOK++;}
if (LandsInHand>=NrGoodLandsNeeded) {CountConditional++;}
} // end of 1000000 iterations
System.out.println("With "+NrGoodLands+" good lands: Prob="+CountOK/CountConditional);
}
}
}
class Deck {
int NumberOfLands;
int NumberOfGoodLands;
int NumberOfCards;
void SetDeck (int NrLands, int NrGoodLands, int NrCards) {
NumberOfLands=NrLands;
NumberOfGoodLands=NrGoodLands;
NumberOfCards=NrCards;
}
int DrawCard (){
Random generator = new Random();
int RandomIntegerBetweenOneAndDeckSize=generator.nextInt( this.NumberOfCards)+1;
int CardType=0;
int GoodLandCutoff=NumberOfGoodLands;
int LandCutoff=NumberOfLands;
if (RandomIntegerBetweenOneAndDeckSize<=GoodLandCutoff) {CardType=1; this.NumberOfGoodLands--; this.NumberOfLands--; this.NumberOfCards--;}
if (RandomIntegerBetweenOneAndDeckSize>GoodLandCutoff && RandomIntegerBetweenOneAndDeckSize<=LandCutoff) {CardType=2; this.NumberOfLands--; this.NumberOfCards--;}
if (RandomIntegerBetweenOneAndDeckSize>LandCutoff) {CardType=3; this.NumberOfCards--;}
return CardType;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment