/**
  * @param minValue
  * @param maxValue
  */
 public void onAllValidPositions(
     int minValue, int maxValue, Callback3<Integer, Integer, Integer> cb) {
   for (int x = 0; x < sideLen; x++) {
     for (int y = 0; y < sideLen; y++) {
       int value = this.data.$get(x).$get(y);
       if (value >= minValue && value <= maxValue) {
         cb.$invoke(x, y, value);
       }
     }
   }
 }
  public boolean nextRandomPosition(
      Callback3<Integer, Integer, Object> cb, Object arg, int minValue) {
    int n = JSGlobal.parseInt(Math.random() * sideLen, 10);
    for (int x = 0; x < sideLen; x++) {
      for (int y = 0; y < sideLen; y++) {
        if (this.data.$get(x).$get(y) >= minValue) {
          n--;

          if (n < 0) {
            cb.$invoke(x, y, arg);
            return true;
          }
        }
      }
    }

    return false;
  }
  public void nextValidPosition(
      int x,
      int y,
      int minValue,
      boolean walkLeft,
      Callback3<Integer, Integer, Object> cb,
      Object arg) {
    x = x - this.centerX;
    y = y - this.centerY;

    if (x < 0 || y < 0 || x >= sideLen || y >= sideLen) {
      if (walkLeft) {
        // start bottom right
        x = sideLen - 1;
        y = sideLen - 1;

      } else {
        // start top left
        x = 0;
        y = 0;
      }
    }

    // walk to the next position
    int mod = (walkLeft) ? -1 : +1;
    y += mod;
    for (; (walkLeft) ? x >= 0 : x < sideLen; x += mod) {
      for (; (walkLeft) ? y >= 0 : y < sideLen; y += mod) {
        if (this.data.$get(x).$get(y) >= minValue) {
          // valid position
          cb.$invoke(x, y, arg);
          return;
        }
      }

      y = (walkLeft) ? sideLen - 1 : 0;
    }
  }