Example #1
0
 public static void main(String[] args) {
   System.out.println("please enter size of grid.");
   int n = IO.readInt();
   if (n < 0) {
     IO.reportBadInput();
     return;
   }
   char[][] tissue = new char[n][n];
   System.out.println("Please enter threshold value in percent form (between 0 -100)");
   int threshold = IO.readInt();
   System.out.println("Please enter number of max rounds.");
   int maxRounds = IO.readInt();
   System.out.println(
       "Please enter number of times the board should be printed int x rounds. (Fresquencey of printing. i splled frequency wrong.");
   int frequency = IO.readInt();
   System.out.println("Please enter percent blank");
   int percentBlank = IO.readInt();
   System.out.println("Pease enter percentX");
   int percentX = IO.readInt();
   if (percentBlank < 0
       || percentBlank > 100
       || percentX < 0
       || percentX > 100
       || threshold < 0
       || threshold > 100
       || n < 0
       || maxRounds <= 0
       || frequency < 0) {
     IO.reportBadInput();
     return;
   }
   assignCellTypes(tissue, percentBlank, percentX);
   CellSimGUI hi = new CellSimGUI(n, 1);
   System.out.println("Initial board is: ");
   printTissue(tissue, hi, n, threshold);
   System.out.println("");
   int x = 0;
   int i = 0;
   int a = 0;
   int max = 1;
   int rounds = 0;
   double percentUnsatisfied = 0;
   int counter = 0;
   double satisfied = 0;
   while (boardSatisfied(tissue, threshold) == false) {
     counter = moveAllUnsatisfied(tissue, threshold) + counter;
     x++;
     if (x % frequency == 0) {
       printTissue(tissue, hi, n, threshold);
       System.out.println("");
       if (boardSatisfied(tissue, threshold) == false) {
         System.out.println("Board is not satisfied");
       } else System.out.println("Board is satisfied.");
     }
     if (max == maxRounds) {
       System.out.println("Board cannot be satisfied within max rounds givent.");
       for (i = 0; i < tissue.length; i++) {
         for (a = 0; a < tissue.length; a++) {
           if (isSatisfied(tissue, i, a, threshold) == false) percentUnsatisfied++;
           else satisfied++;
         }
       }
       percentUnsatisfied = (satisfied / (percentUnsatisfied + satisfied));
       System.out.println(
           "This is the percent of satisfied cells : " + (percentUnsatisfied * 100) + "%");
       System.out.println("THis is the number of movements that occured: " + counter);
       return;
     }
     max++;
     rounds++;
   }
   System.out.println("This took " + rounds + " number of rounds");
   System.out.println("THis is the number of movements that occured: " + counter);
   System.out.println("Baord is satisfied. Final board is:");
   printTissue(tissue, hi, n, threshold);
 }