Advertisement
Mr_Linnenburger

ElevensSimulation

Apr 26th, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.10 KB | None | 0 0
  1. /**
  2.  * This is a class that plays noninteractive games of Elevens.
  3.  * See accompanying documents for a description of how Elevens is played.
  4.  */
  5. public class ElevensSimulation {
  6.  
  7.     /**
  8.      * The number of games of Elevens to play.
  9.      */
  10.     private static final int GAMES_TO_PLAY = 100000;
  11.  
  12.     /**
  13.      * Flag used to control debugging print statements.
  14.      */
  15.     private static final boolean I_AM_DEBUGGING = false;
  16.  
  17.  
  18.     /**
  19.      * @param args is not used.
  20.      */
  21.     public static void main(String[] args) {
  22.         ElevensSimulatorBoard board = new ElevensSimulatorBoard();
  23.         int wins = 0;
  24.  
  25.         for (int k = 0; k < GAMES_TO_PLAY; k++) {
  26.             if (I_AM_DEBUGGING) {
  27.                 System.out.println(board);
  28.             }
  29.             while (board.playIfPossible()) {
  30.                 if (I_AM_DEBUGGING) {
  31.                     System.out.println(board);
  32.                 }
  33.             }
  34.             if (board.gameIsWon()) {
  35.                 wins++;
  36.             }
  37.             board.newGame();
  38.         }
  39.  
  40.         double percentWon = (int)(1000.0 * wins / GAMES_TO_PLAY + 0.5) / 10.0;
  41.         System.out.println("Games won:    " + wins);
  42.         System.out.println("Games played: " + GAMES_TO_PLAY);
  43.         System.out.println("Percent won:  " + percentWon + "%");
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement