public class Square {

  //the value of the square, a number between 1-9 or 0 if empty
  // ints default value is 0
  private final int val;
  //whether or not a pencil mark exists for each of the possible numbers where a
  //true in the index ith place means the number i is pencilled in
  //boolean default value is false
  private boolean[] possibles;
  //the number of pencil marks
  private int count;

  Square(int n) {
    //if the square has a value, then there should be no pencil marks
    val = n;
    possibles = new boolean[]{false, false, false, false, false, false, false, false, false, false};
    count = 0;
  }

  Square() {
    //a new square without a value has a full set of pencil marks
    val = 0;
    possibles = new boolean[]{false, true, true, true, true, true, true, true, true, true};
    count = 9;
  }

  void printAll() {
    System.out.println("value is = " + val + ", count is = " + count);
    System.out.print('{');
    for (boolean mark : possibles) {
      System.out.print(mark + ",");
    }
    System.out.println("\b}");
  }

  void print() {
    System.out.print(val + " ");
  }

  int value() {
    return val;
  }

  boolean isEmpty() {
    return val == 0;
  }

  boolean hasUniquePMark() {
    return count == 1;
  }

  int uniquePMark() {
    assert hasUniquePMark() : "must have only one pencil mark";
    for (int i = 1; i <= 9; i++) {
      if (possibles[i]) {
        return i;
      }

    }
    return 0;
  }


  void removePMarkIfThere(int n) {
    if (possibles[n]) {
      possibles[n] = false;
      count--;
    }
  }
}


