/**
 * CS1101 (AY2009/10 Semester 1)
 * MMCode.java
 * This class defines the four-peg code for MasterMind.
 * Complete the countSinks(MMCode) and countHits(MMCode) methods.
 */

class MMCode {
  
   // Data members
   private Peg peg1, peg2, peg3, peg4;

   // Constructors
   public MMCode() {
      this(new Peg('R'), new Peg('R'), new Peg('R'), new Peg('R'));
   }

   public MMCode(MMCode pegs) {
      this(new Peg(pegs.peg1), 
           new Peg(pegs.peg2),
           new Peg(pegs.peg3),
           new Peg(pegs.peg4));
   }

   public MMCode(Peg p1, Peg p2, Peg p3, Peg p4) {
      peg1 = p1;
      peg2 = p2;
      peg3 = p3;
      peg4 = p4;
   }
 
   // Changes the colour of the selected peg
   public void setColour(int whichPeg, char c) {
      switch (whichPeg) {
         case 1: peg1.setColour(c); break;
         case 2: peg2.setColour(c); break;
         case 3: peg3.setColour(c); break;
         case 4: peg4.setColour(c); break;
         default: System.err.println("No such peg!");
                  System.exit(1);
      }
   }

   // Returns colour of the selected peg 
   public char getColour(int whichPeg) {
      char c = ' ';
      switch (whichPeg) {
         case 1: c = peg1.getColour(); break;
         case 2: c = peg2.getColour(); break;
         case 3: c = peg3.getColour(); break;
         case 4: c = peg4.getColour(); break;
         default: System.err.println("No such peg!");
                  System.exit(2);
      }
      return c;
   }

   // Returns string representation of a MMCode object
   public String toString() {
      return peg1.toString() + " " +
             peg2.toString() + " " +
             peg3.toString() + " " +
             peg4.toString();

      /* alternative (the one above is preferred, why?)
      return peg1.getColour() + " " +
             peg2.getColour() + " " +
             peg3.getColour() + " " +
             peg4.getColour();
      */
   }

   // Returns the number of sinks between object and guessPegs
   public int countSinks(MMCode guessPegs) {
      int sinks = 0;

      // fill in the code

      return sinks;
   }

   // Returns the number of hits between object and guessPegs
   // Note to students: there are many ways to solve this!
   public int countHits(MMCode guessPegs) {
      int hits = 0;

      // fill in the code

      return hits;
   }

}

