xxxxxxxxxx
int wins = 0;
int losses = 0;
int games = 0;
int winningdoor = 0;
int randomchoice = 0;
int goatrand = 0;
int goatdoor = 0;
int firstchoice = 0;
int othergoat = 0;
boolean reveal = false;
int[] losingdoors;
int[] resetarray;
void setup(){
size(200,300);
background(0);
}
boolean run = true;
void draw(){
if(run){
/////////////////////////////////////////////STAY//////////////////////////////////
wins = 0;
losses = 0;
games = 100000; // we'll play 100,000 games for accuracy
winningdoor = 0;
randomchoice = 0;
for (int i=0; i < games; i++){
winningdoor = int(random(0,3)); // randomly decide which door has the car
randomchoice = int(random(0,3)); // randomly decide which door is chosen
/*
Random returns a floating point decimal between 0.000...1 and 2.999...
Casting as an integer with (int) drops the decimal, giving us 3 options "0, 1, 2"
At every iteration of i for every game, random spits out a new number.
*/
if (randomchoice == winningdoor){ // if the choice is the same as the winning door
wins++; // count a win
}else{
losses++; // if the choice isn't the winning door
} // count a loss
}
text("One door choice (Stay)\n WINS: " + wins + "\n LOSSES: " + losses + "\n "+
(int)((((float)wins) / ((float)games))*100) + "% win rate \n",5,15);
/////////////////////////////////////////////STAY//////////////////////////////////
/////////////////////////////////////////////SWITCH////////////////////////////////
wins=0; //reset wins and losses to zero
losses=0;
//used below with reveal
losingdoors = new int[0]; //keep track of goat doors
resetarray = new int[0];
goatdoor= 0; //will store the unrevealed goat door here
othergoat= 0; //will store the revealed goat door here
firstchoice= 0;
for (int i = 0; i < games; i++){
losingdoors = new int[0];
winningdoor = int(random(0,3)); // randomly define which door wins
randomchoice = int(random(0,3)); // randomly make an initial choice door
firstchoice = randomchoice; // not a factor of the program just for print
for (int j = 0; j <= 2; j++){
if (j != winningdoor){ // store the losing doors here
losingdoors = append(losingdoors, j); // { goat A door# , goat B door# }
}
}
goatrand = int(random(0,2));
if (losingdoors[goatrand] == randomchoice){
while (losingdoors[goatrand] == randomchoice){
goatrand = int(random(0,2));
}
}
//randomly define which goat door is revealed (so we cant pick it)
//if the randomly chosen door to be revealed is our choice door,
//then we will reset and randomly choose a door until it isn't
othergoat = losingdoors[goatrand]; //store the door where the revealed goat is
losingdoors[goatrand] = -1; //set door to -1 so we CAN not to pick it
for (int k = 0; k < 2; k++){
if (losingdoors[k] != -1){
goatdoor = losingdoors[k]; // now we can know all the doors
}
}
if (randomchoice == winningdoor){ //if our first choice was the winning door
randomchoice = goatdoor; //then we switch to the goat door
}else if (randomchoice == goatdoor){ //if our first choice was goat door
randomchoice = winningdoor; //then we switch to the winning door
}
if (randomchoice == winningdoor){
wins++;
}else{
losses++;
}
}
text("Two door choices (Switch)\n WINS: " + wins + "\n LOSSES: " + losses + "\n "+
(int)((((float)wins) / ((float)games))*100) + "% win rate", 5, 80);
text("EXAMPLE GAME:\nFirst Choice: " + firstchoice + "\nRevealed Goat Door: " + othergoat + "\nSecond Choice: " +
randomchoice + "\nUnrevealed Goat Door: " + goatdoor + "\nWinning Car Door: " + winningdoor, 5, 145);
}
run = false;
/////////////////////////////////////////////SWITCH////////////////////////////////
}