Official CompileBot Testing Thread

+/u/CompileBot Java

import java.util.Random;

public class Main{
    public static void main(String[] args){

         Random rand = new Random();  //fair random number generator
         int victories = 0, trials = 0; //victories is how often we guess correctly; trials is how often we try
         for(int i = 0; i < 10000; i++){ //try 10000 times
           //first, pick a card
           int card = rand.nextInt(3);//0 = red/red; 1 = red/blue; 2 = blue/blue
           //then pick a side
           int side = rand.nextInt(2);//0 = first; 1 = second.

           //variable for whether or not the top is red (initialized to false, but it'll get changed later)
           boolean seenRed = false;
           //variable for whether or not the bottom is red
           boolean hiddenRed = false;
           //variable for whether or not we predict that the bottom is red
           boolean predictedRed = false;

           //this chunk determines the value of the above three booleans
           switch(card){
               case 0://It's red/red.  We see red, predict red, and red is hidden
                   seenRed = false;
                   predictedRed = true;
                   hiddenRed = true;
                   break;
               case 1: //it's red/blue
                   if(side == 0){
                       seenRed = true;
                       predictedRed = true;
                       hiddenRed = false;
                   }
                   else{
                       seenRed = false;
                       predictedRed = false;
                       hiddenRed = true;
                   }
                   break;
               case 2: //it's blue/blue
                   seenRed = false;
                   predictedRed = false;
                   hiddenRed = false;
                   break;
           }

           //Check to see if we guessed right
           if(predictedRed == hiddenRed){
               victories++;
           }
           //either way, note the trial
           trials++;
       }
       System.out.println(victories + " " + trials);
    }
}
/r/CompileBot Thread