Example #1
0
  public static boolean isValid(GardenModel mod) {
    for (Garden g : mod.gardens) {
      if (g.getTreeCount() > mod.trees) return false;
      if (g.getUnknownCount() + g.getTreeCount() < mod.trees) return false;
    }
    for (Iterator<Line> it = mod.grid.iterateColumns(); it.hasNext(); ) {
      Line col = it.next();
      if (col.getTreeCount() > mod.trees) return false;
      if (col.getUnknownCount() + col.getTreeCount() < mod.trees) return false;
    }
    for (Iterator<Line> it = mod.grid.iterateRows(); it.hasNext(); ) {
      Line row = it.next();
      if (row.getTreeCount() > mod.trees) return false;
      if (row.getUnknownCount() + row.getTreeCount() < mod.trees) return false;
    }

    for (Cell c : mod.grid) {
      if (c.getState() == State.Tree) {
        for (Iterator<Cell> it = mod.grid.iterateAdjacent(c); it.hasNext(); ) {
          if (it.next().getState() == State.Tree) return false;
        }
      }
    }

    for (Garden g : mod.gardens) {
      if (!g.areThereEnoughFreeNonAdjacentCells()) return false;
    }
    for (Line l : mod.grid.getColumnsAndRows()) {
      if (!l.areThereEnoughFreeNonAdjacentCells(mod.trees)) return false;
    }

    return checkBalance(mod);
  }
Example #2
0
  public static boolean isComplete(GardenModel mod) {
    for (Garden g : mod.gardens) {
      if (g.getTreeCount() != mod.trees) return false;
    }
    for (Iterator<Line> it = mod.grid.iterateColumns(); it.hasNext(); ) {
      Line col = it.next();
      if (col.getTreeCount() != mod.trees) return false;
    }
    for (Iterator<Line> it = mod.grid.iterateRows(); it.hasNext(); ) {
      Line row = it.next();
      if (row.getTreeCount() != mod.trees) return false;
    }

    return Analysis.isValid(mod);
  }