/** * Gets a Coord array from the "on" contents of this GreasedRegion, using a deterministic but random-seeming * scattering of chosen cells with a count that matches the given {@code fraction} of the total amount of "on" cells * in this. This is pseudo-random with a fixed seed, but is very good at avoiding overlap (just as good as * {@link #separatedRegionZCurve(double, int)}, and probably faster). If you request too many cells (too high of a * value for fraction), it will start to overlap, but a fraction value of 0.4 reliably has had no overlap in * testing. Does not restrict the size of the returned array other than only using up to * {@code fraction * size()} cells. * @param fraction the fraction of "on" cells to randomly select, between 0.0 and 1.0 * @return a freshly-allocated Coord array containing the quasi-random cells */ public Coord[] mixedRandomSeparated(double fraction) { return mixedRandomSeparated(fraction, -1, 1L); }
/** * Gets a Coord array from the "on" contents of this GreasedRegion, using a deterministic but random-seeming * scattering of chosen cells with a count that matches the given {@code fraction} of the total amount of "on" cells * in this. This is pseudo-random with a fixed seed, but is very good at avoiding overlap (just as good as * {@link #separatedRegionZCurve(double, int)}, and probably faster). If you request too many cells (too high of a * value for fraction), it will start to overlap, but a fraction value of 0.4 reliably has had no overlap in * testing. Restricts the total size of the returned array to a maximum of {@code limit} (minimum is 0 if no cells * are "on"). If limit is negative, this will not restrict the size. * @param fraction the fraction of "on" cells to randomly select, between 0.0 and 1.0 * @param limit the maximum size of the array to return * @return a freshly-allocated Coord array containing the pseudo-random cells */ public Coord[] mixedRandomSeparated(double fraction, int limit) { return mixedRandomSeparated(fraction, limit, 1L); }
for(Coord hole : new GreasedRegion(map, '.').fringe().removeEdges().mixedRandomSeparated(0.25, -1, rng.nextLong())) { if (((map[hole.x - 1][hole.y] == '.' && map[hole.x + 1][hole.y] == '.') || (map[hole.x][hole.y - 1] == '.' && map[hole.x][hole.y + 1] == '.'))) {
tmpInner.remake(area).retract(4).expand8way().and(area); tmpEdge.remake(area).surface8way(); Coord[] edges = tmpEdge.mixedRandomSeparated(0.35); int eLen = edges.length; Double[] powers = new Double[eLen]; Coord[] centers = map.mixedRandomSeparated(0.1, factionCount, rng.nextLong()); int controlled = (int) (map.size() * Math.max(0.0, Math.min(1.0, controlledFraction)));