import java.util.*;

/** Contains methods for creating music according to Mozart's
  Musikalisches WŸrfelspiel --Mozart's musical dice game. 
  
  Within this class, a parameter d of type double[] is supposed
  to be the values in a .wav array, as created by a call on
  StdAudio.read.
  */
public class WurfelSpiel {
    
    private final static int measure= 16; // The number of measures in a minuet or trio
    private final static int die= 6;      // Maximum value of a roll of a die
   
    private static Random generator= new Random();
    
    private final static int[][] minuet= {
        {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {0, 96, 22, 141, 41, 105, 122, 11, 30, 70, 121, 26, 9, 112, 49, 109, 14},
        {0, 32, 6, 128, 63, 146, 46, 134, 81, 117, 39, 126, 56, 174, 18, 116, 83},
        {0, 69, 95, 158, 13, 153, 55, 110, 24, 66, 139, 15, 132, 73, 58, 145, 79},
        {0, 40, 17, 113, 85, 161, 2 ,159, 100, 90, 176, 7, 4, 67, 160, 52, 170},
        {0, 148, 74, 163, 45, 80, 97, 36, 107, 25, 143, 64, 125, 76, 136, 1, 93},
        {0, 104, 157, 27, 167, 154, 68, 118, 91, 138, 71, 150, 29, 101, 162, 23, 151},
        {0, 152, 60, 171, 53, 99, 133, 21, 127, 16, 155, 57, 175, 43, 168, 89, 172},
        {0, 119, 84, 114, 50, 140, 86, 169, 94, 120, 88, 48, 166, 51, 115, 72, 111},
        {0, 98, 142, 42, 156, 75, 129, 62, 123, 65, 77, 19, 82, 137, 38, 149, 8},
        {0, 3, 87, 165, 61, 135, 47, 147, 33, 102, 4, 31, 164, 44, 59, 173, 78},
        {0, 54, 130, 10, 103, 28, 37, 106, 5, 35, 20, 108, 92, 12, 124, 44, 131}
    };
    
    private final static int[][] trio= {
        {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
        {0, 72, 6, 59, 25, 81, 41, 89, 13, 36, 5, 46, 79, 30, 95, 19, 66},
        {0, 56, 82, 42, 74, 14, 7, 26, 71, 76, 20, 64, 84, 8, 35, 47, 88},
        {0, 75, 39, 54, 1, 65, 43, 15, 80, 9, 34, 93, 48, 69, 58, 90, 21},
        {0, 40, 73, 16, 68, 29, 55, 2, 61, 22, 67, 49, 77, 57, 87, 33, 10},
        {0, 83, 3, 28, 53, 37, 17, 44, 70, 63, 85, 32, 96, 12, 23, 50, 91},
        {0, 18, 45, 62, 38, 4, 27, 52, 94, 11, 92, 24, 86, 51, 60, 78, 31}
    };
    
    // The only constructor is private, so no instances can be created
    // outside the class.
    private WurfelSpiel() {}
    
    /** = a roll of a die --an int in the range 1..6 */
    public static int throwDie(){
        return 0;
    }
    
    /** = String rep of sa: i.e. the string "[sa[0], sa[1], ..., ]". */
    public static String toString(String[] sa) {
        /** The kind of loop you write here is standard for producing
            a list of things with comments between elements. You are
            expected to study the result and to be able to produce
            such code. */
        
        String res= "[";
        
        // invariant: res contains "[" followed by sa[0..i-1],
        //            with commas between elements.
        for (int i= 0; i != sa.length; i= i+1) {
            /** Process sa[i]. This is done in two steps.
                (1) If this is not the first iteration, append ", " to res.
                (2) Append s[i] to res.
            */
        }
        
        res= res + "]";
        return res;
    }
    
    /** = A String array that contains the names of all the files
      described by row 2 of array minuet and row 1 of array trio .<br><br>
      
      The file names are of the form            <br><br>
      
      "measures/m<integer>.wav" and             <br>
      "measures/T<integer>.wav",                <br><br>
      
      so the files are expected to be in directory measures.<br><br>
      
      Here is an example of a file name: "measures/T5.wav".*/
    public static String[] create1Spiel() {
        // You must write one or more loops here. Do not write 32 assignments.
        // The purpose is to prepare you to write the later function createRandomSpiel.
        return null;
    }
    
    /** Play the music given by files whose names are in s, in order */
    public static void play(String[] s) {
        /** REMOVE THIS COMMENT WHEN DONE!!!
            You can rely on methods StdAudio.read(String) and
            StdAudio.play(double[])  when writing the body of this
            procedure. */
    }
    
    /** Put all the measures given by file names in s into
      a new array d and return d.
      For example, suppose s contains three file names, and the
      length of the three files are 50, 15, and 30. Then in the
      returned array d,<br>
      the values in the first file go in d[0..49],<br>
      the values in the second file go in d[50..64],<br>
      the values in the third file go in d[65..94].<br>*/
    public static double[] build(String[] s) {
        int size= 0;  // will contain the length of the result array
        
        /* Store in size the length of the final array. Do this
           by reading each file and adding its length to size
        */
        
        
        
        //  { size is the length of the result array }
        
        
        /* Declare an array of the proper size, read in each file
           and place its values in the array, and return the array
        */
        
        
        return null;
    }
  
        
    /** = an array of random measure filenames:
          16 for a minuet and then 16 for a trio. <br><br>
          
          The filenames have the form       <br><br>
          
            "measures/m<integer>.wav" and   <br>
            "measures/T<integer>.wav"       <br><br>
         
         so the files are expected to be in directory measures,
         which should be in the same folder as this class.<br><br>
         
         Here is an example of a file name: "measures/T5.wav".*/
    public static String[] createRandomSpiel() {
        
        return null;
    }
    
    
    
    /** Play d */
    public static void play(double[] d){
        StdAudio.play(d);
    }
    
    /** Place the values in array d into b[k], b[k+1], ... */
    public static void copy(double[] d, double[] b, int k) {
        for (int i= 0; i != d.length; i= i+1) {
            b[k+i]= d[i];   
        }
    }
    
}
