Seed based random generator
This commit is contained in:
@@ -20,7 +20,7 @@ import mc.core.block.Block;
|
|||||||
* +-------------+----------------+------------+
|
* +-------------+----------------+------------+
|
||||||
*
|
*
|
||||||
* Total: 16 bits header (2 bytes) + 24 * block_count bits (3 * block_count bytes)
|
* Total: 16 bits header (2 bytes) + 24 * block_count bits (3 * block_count bytes)
|
||||||
* Max size: 12290 bytes (~12 Mb per chunk)
|
* Max size: 12290 bytes (~12 Kb per chunk)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
/* 16x16x16 */
|
/* 16x16x16 */
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ package mc.core.world;
|
|||||||
* | biome_map | 256x256 0-32 | 2097152 |
|
* | biome_map | 256x256 0-32 | 2097152 |
|
||||||
* +-------------+----------------+------------+
|
* +-------------+----------------+------------+
|
||||||
*
|
*
|
||||||
* Total: 2097152 bits (262144 bytes = 256 Mb)
|
* Total: 2097152 bits (256 Kb)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public interface Region {
|
public interface Region {
|
||||||
|
|||||||
@@ -25,7 +25,18 @@ import java.util.UUID;
|
|||||||
* +-------------+----------------+------------+
|
* +-------------+----------------+------------+
|
||||||
* | seed | long | 64 |
|
* | seed | long | 64 |
|
||||||
* +-------------+----------------+------------+
|
* +-------------+----------------+------------+
|
||||||
|
* | type | 0-255 | 8 |
|
||||||
|
* +-------------+----------------+------------+
|
||||||
*
|
*
|
||||||
|
* /worlds/
|
||||||
|
* --> []/world_uuid/
|
||||||
|
* --> world.dat
|
||||||
|
* --> []/r.X.Z/
|
||||||
|
* --> biomes.dat
|
||||||
|
* --> []chunk_x_y_z.dat
|
||||||
|
* --> entities.dat
|
||||||
|
* --> /playerdata/
|
||||||
|
* --> []player_uuid.dat
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public interface World {
|
public interface World {
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package mc.world.generated_world;
|
||||||
|
|
||||||
|
public final class SeedRandomGenerator {
|
||||||
|
|
||||||
|
public static double random (int x, int y, int seed) {
|
||||||
|
x = Math.abs(x - y) + 1;
|
||||||
|
y = Math.abs(y - x) + 1;
|
||||||
|
for (int i = 0; i < 40; i ++) {
|
||||||
|
int a1 = x % 13;
|
||||||
|
int a2 = x % 31;
|
||||||
|
int a3 = x % 89;
|
||||||
|
int a4 = y % 359;
|
||||||
|
int a5 = y % 7;
|
||||||
|
int a6 = y % 313;
|
||||||
|
int a7 = y % 8461;
|
||||||
|
int a8 = y % 105467;
|
||||||
|
int a9 = x % 105943;
|
||||||
|
y = x + seed;
|
||||||
|
x += a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9;
|
||||||
|
}
|
||||||
|
return ((x + y) % 100000) / 100000d;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package mc.world.generated_world;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import javax.imageio.ImageIO;
|
||||||
|
import java.awt.image.BufferedImage;
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
public class SeedRandomGeneratorTest {
|
||||||
|
@Test
|
||||||
|
public void randomTest() throws Exception {
|
||||||
|
double maxDiff = 0;
|
||||||
|
double maxDisp = 0;
|
||||||
|
for (int i = 0; i < 100; i ++) {
|
||||||
|
double mid = 0;
|
||||||
|
double disp = 0;
|
||||||
|
int seed = (int) (Math.random() * Integer.MAX_VALUE);
|
||||||
|
for (int x = -1000; x < 1000; x++) {
|
||||||
|
for (int y = -1000; y < 1000; y++) {
|
||||||
|
double rnd = SeedRandomGenerator.random(x, y, seed);
|
||||||
|
mid += rnd;
|
||||||
|
disp += (rnd - 0.5) * (rnd - 0.5);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mid = mid/4000000;
|
||||||
|
disp = Math.sqrt(disp)/4000000;
|
||||||
|
if (maxDiff < Math.abs(mid - 0.5)) {
|
||||||
|
maxDiff = Math.abs(mid - 0.5);
|
||||||
|
}
|
||||||
|
if (maxDisp < disp) {
|
||||||
|
maxDisp = disp;
|
||||||
|
}
|
||||||
|
System.out.printf("Iteration %d.\t mid: %.3f, \tdisp %.6f\n", i + 1, mid, disp);
|
||||||
|
}
|
||||||
|
System.out.printf("Max diff: %.3f\n", maxDiff);
|
||||||
|
System.out.printf("Max disp: %.6f\n", maxDisp);
|
||||||
|
|
||||||
|
assertTrue(maxDiff > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void generateImage () throws Exception {
|
||||||
|
int h = 500;
|
||||||
|
int w = 500;
|
||||||
|
BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
|
||||||
|
|
||||||
|
int seed = (int) (Math.random() * Integer.MAX_VALUE) / 1024;
|
||||||
|
for (int x = 0; x < w; x ++) {
|
||||||
|
for (int y = 0; y < h; y ++) {
|
||||||
|
image.setRGB(x, y, (int) (0xffffff * SeedRandomGenerator.random(x, y, seed)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ImageIO.write(image, "bmp", new File("out", "seed_random.png"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user