示例#1
-16
  /**
   * The actual minConflicts algorithm
   *
   * @param csp An CSP
   * @param maxSteps The maximum amount of steps to take before bailing
   * @return The number of steps actually taken, or -1 if we bailed.
   */
  private short minConflicts(CSP csp, short maxSteps) {

    short shuffleList[] = new short[csp.board];
    for (short i = 0; i < csp.board; ++i) {
      shuffleList[i] = i;
    }

    for (short i = 0; i < maxSteps; ++i) {
      if (csp.solution()) {
        return i;
      }

      shuffle(shuffleList);

      for (short n = 0; n < csp.board; ++n) {
        if (csp.isConflicted(shuffleList[n])) {
          short moveTo = csp.minConflicts(shuffleList[n]);

          csp.matrix[shuffleList[n]] = moveTo;

          break;
        }
      }
    }
    return -1;
  }