public static int puzzle_add_neighbors(double[] vecur_, ref int vecur, int max_neighbors, ref PuzzleAvgLvls avglvls, int lx, int ly) { if (max_neighbors != 8) throw new Exception(); int xlimit = lx >= avglvls.lambdas - 1 ? avglvls.lambdas - 1 : lx + 1; int ylimit = ly >= avglvls.lambdas - 1 ? avglvls.lambdas - 1 : ly + 1; int ax = lx <= 0 ? 0 : lx - 1; int ay; int neighbors = 0; double @ref = avglvls.lvls[avglvls.lambdas * ly + lx]; do { ay = ly <= 0 ? 0 : ly - 1; do { if (ax == lx && ay == ly) continue; vecur_[vecur++] = @ref - avglvls.lvls[avglvls.lambdas * ay + ax]; neighbors++; } while (ay++ < ylimit); } while (ax++ < xlimit); if (neighbors > max_neighbors) throw new Exception(); return neighbors; }
public static PuzzleAvgLvls puzzle_fill_avglgls(PuzzleContext context, PuzzleView view, int lambdas) { double width = (double)view.width; double height = (double)view.height; PuzzleAvgLvls avglvls = new PuzzleAvgLvls(); avglvls.lambdas = lambdas; avglvls.lvls = new double[lambdas * lambdas]; double xshift = (width - width * lambdas / (lambdas + 1)) / 2; double yshift = (height - height * lambdas / (lambdas + 1)) / 2; int p = (int)Math.Round(Math.Min(width, height) / ((lambdas + 1) * context.puzzle_p_ratio)); if (p < PuzzleNative.PUZZLE_MIN_P) { p = PuzzleNative.PUZZLE_MIN_P; } double x, y; int xd, yd; int px, py; int lwidth, lheight; int lx = 0; int ly; do { ly = 0; do { x = xshift + (double)lx * (width - 1) / (lambdas + 1); y = yshift + (double)ly * (height - 1) / (lambdas + 1); lwidth = (int)Math.Round(xshift + (lx + 1) * (width - 1) / (lambdas + 1) - x); lheight = (int)Math.Round(yshift + (ly + 1) * (height - 1) / (lambdas + 1) - y); xd = p < lwidth ? (int)Math.Round(x + (lwidth - p) / 2.0) : (int)Math.Round(x); yd = p < lheight ? (int)Math.Round(y + (lheight - p) / 2.0) : (int)Math.Round(y); px = view.width - xd < p ? 1 : p; py = view.height - yd < p ? 1 : p; avglvls.lvls[avglvls.lambdas * ly + lx] = (px > 0 && py > 0) ? puzzle_get_avglvl(ref view, xd, yd, px, py) : 0; } while (++ly < lambdas); } while (++lx < lambdas); return(avglvls); }
public static PuzzleDvec puzzle_fill_dvec(PuzzleAvgLvls avglvls) { int lambdas = avglvls.lambdas; PuzzleDvec dvec = new PuzzleDvec(); dvec.vec = new double[(lambdas * lambdas * PuzzleNative.PUZZLE_NEIGHBORS)]; int vecur = 0; int lx = 0; int ly; do { ly = 0; do { puzzle_add_neighbors(dvec.vec, ref vecur, PuzzleNative.PUZZLE_NEIGHBORS, ref avglvls, lx, ly); } while (++ly < lambdas); } while (++lx < lambdas); dvec.sizeof_compressed_vec = vecur; return(dvec); }
public static int puzzle_add_neighbors(double[] vecur_, ref int vecur, int max_neighbors, ref PuzzleAvgLvls avglvls, int lx, int ly) { if (max_neighbors != 8) { throw new Exception(); } int xlimit = lx >= avglvls.lambdas - 1 ? avglvls.lambdas - 1 : lx + 1; int ylimit = ly >= avglvls.lambdas - 1 ? avglvls.lambdas - 1 : ly + 1; int ax = lx <= 0 ? 0 : lx - 1; int ay; int neighbors = 0; double @ref = avglvls.lvls[avglvls.lambdas * ly + lx]; do { ay = ly <= 0 ? 0 : ly - 1; do { if (ax == lx && ay == ly) { continue; } vecur_[vecur++] = @ref - avglvls.lvls[avglvls.lambdas * ay + ax]; neighbors++; } while (ay++ < ylimit); } while (ax++ < xlimit); if (neighbors > max_neighbors) { throw new Exception(); } return(neighbors); }
public static PuzzleDvec puzzle_fill_dvec(PuzzleAvgLvls avglvls) { int lambdas = avglvls.lambdas; PuzzleDvec dvec = new PuzzleDvec(); dvec.vec = new double[(lambdas * lambdas * PuzzleNative.PUZZLE_NEIGHBORS)]; int vecur = 0; int lx = 0; int ly; do { ly = 0; do { puzzle_add_neighbors(dvec.vec, ref vecur, PuzzleNative.PUZZLE_NEIGHBORS, ref avglvls, lx, ly); } while (++ly < lambdas); } while (++lx < lambdas); dvec.sizeof_compressed_vec = vecur; return dvec; }
public static PuzzleAvgLvls puzzle_fill_avglgls(PuzzleContext context, PuzzleView view, int lambdas) { double width = (double)view.width; double height = (double)view.height; PuzzleAvgLvls avglvls = new PuzzleAvgLvls(); avglvls.lambdas = lambdas; avglvls.lvls = new double[lambdas * lambdas]; double xshift = (width - width * lambdas / (lambdas + 1)) / 2; double yshift = (height - height * lambdas / (lambdas + 1)) / 2; int p = (int)Math.Round(Math.Min(width, height) / ((lambdas + 1) * context.puzzle_p_ratio)); if (p < PuzzleNative.PUZZLE_MIN_P) p = PuzzleNative.PUZZLE_MIN_P; double x, y; int xd, yd; int px, py; int lwidth, lheight; int lx = 0; int ly; do { ly = 0; do { x = xshift + (double) lx * (width - 1) / (lambdas + 1); y = yshift + (double) ly * (height - 1) / (lambdas + 1); lwidth = (int)Math.Round(xshift + (lx + 1) * (width - 1) / (lambdas + 1) - x); lheight = (int)Math.Round(yshift + (ly + 1) * (height - 1) / (lambdas + 1) - y); xd = p < lwidth ? (int)Math.Round(x + (lwidth - p) / 2.0) : (int)Math.Round(x); yd = p < lheight ? (int)Math.Round(y + (lheight - p) / 2.0) : (int)Math.Round(y); px = view.width - xd < p ? 1 : p; py = view.height - yd < p ? 1 : p; avglvls.lvls[avglvls.lambdas * ly + lx] = (px > 0 && py > 0) ? puzzle_get_avglvl(ref view, xd, yd, px, py) : 0; } while (++ly < lambdas); } while (++lx < lambdas); return avglvls; }