internal void AddHash(int x) { numPaths++; rand = new JavaRandom(x); // XXX: fp.set(x % size); would work just as well but would encode a // different bit fp.Set(rand.Next(fpsize), true); }
public NoiseGeneratorOctaves(JavaRandom random, int i) { field_1191_b = i; generatorCollection = new NoiseGeneratorPerlin[i]; for (int j = 0; j < i; j++) { generatorCollection[j] = new NoiseGeneratorPerlin(random); } }
public NoiseGeneratorOctaves2(JavaRandom random, int i) { field_4233_b = i; field_4234_a = new NoiseGenerator2[i]; for (int j = 0; j < i; j++) { field_4234_a[j] = new NoiseGenerator2(random); } }
public unsafe void Tick(int *ptr, int size) { if (rnd == null) { rnd = new JavaRandom(new Random().Next()); } int mask = size - 1, shift = CheckSize(size); int i = 0; for (int y = 0; y < size; y++) { for (int x = 0; x < size; x++) { // Calculate the colour at this coordinate in the heatmap float lSoupHeat = 0; int xOffset = x + (int)(1.2 * Math.Sin(y * 22.5 * Utils.Deg2Rad)); int yOffset = y + (int)(1.2 * Math.Sin(x * 22.5 * Utils.Deg2Rad)); for (int j = 0; j < 9; j++) { int xx = xOffset + (j % 3 - 1); int yy = yOffset + (j / 3 - 1); lSoupHeat += soupHeat[(yy & mask) << shift | (xx & mask)]; } float lPotHeat = potHeat[i] // x , y + potHeat[y << shift | ((x + 1) & mask)] + // x + 1, y +potHeat[((y + 1) & mask) << shift | x] + // x , y + 1 +potHeat[((y + 1) & mask) << shift | ((x + 1) & mask)]; // x + 1, y + 1 soupHeat[i] = lSoupHeat * 0.1f + lPotHeat * 0.2f; potHeat[i] += flameHeat[i]; if (potHeat[i] < 0) { potHeat[i] = 0; } flameHeat[i] -= 0.06f * 0.01f; if (rnd.NextFloat() <= 0.005f) { flameHeat[i] = 1.5f * 0.01f; } // Output the pixel float col = 2 * soupHeat[i]; col = col < 0 ? 0 : col; col = col > 1 ? 1 : col; float r = col * 100 + 155; float g = col * col * 255; float b = col * col * col * col * 128; * ptr = 255 << 24 | (byte)r << 16 | (byte)g << 8 | (byte)b; ptr++; i++; } } }
public static void Main(string[] args) { string path = args.Length == 1 ? args[0] : null; int players = 2; string start = Console.ReadLine(); JavaRandom random = new JavaRandom(); ulong seed = (ulong)random.nextInt(999999999); try { if (start.StartsWith("###Seed")) { seed = ulong.Parse(start.Substring(8)); Console.Error.WriteLine("Using seed:" + seed); random = new JavaRandom(seed); start = Console.ReadLine(); } players = int.Parse(start.Split() [1]); } catch (Exception e) { Console.Error.WriteLine("Invalid parameter '" + start + "': " + e); return; } Board board = new Board(random, players); Players = board.players; int round = 0; while (board.Play()) { Console.Error.WriteLine(path); board.Tick(); round++; if (path != null) { Console.Error.WriteLine("draw " + round); Bitmap bmp = board.Draw(); bmp.Save(path + System.IO.Path.DirectorySeparatorChar + $"{round:000}.png"); bmp.Dispose(); } } List <Player> ranking = board.players.OrderByDescending(p => p.Score).ToList(); string result = "###End " + ranking[0].ID; for (int i = 1; i < ranking.Count; i++) { if (ranking[i - 1].Score > ranking[i].Score) { result += " "; } result += ranking[i].ID; } Console.WriteLine(result); }
public void Tick(int *ptr, int size) { if (rnd == null) { rnd = new JavaRandom(new Random().Next()); } int mask = size - 1, shift = CheckSize(size); int i = 0; for (int y = 0; y < size; y++) { for (int x = 0; x < size; x++) { // Calculate the colour at this coordinate in the heatmap float lSoupHeat = soupHeat[y << shift | ((x - 1) & mask)] + soupHeat[y << shift | x] + soupHeat[y << shift | ((x + 1) & mask)]; soupHeat[i] = lSoupHeat / 3.3f + potHeat[i] * 0.8f; potHeat[i] += flameHeat[i]; if (potHeat[i] < 0) { potHeat[i] = 0; } flameHeat[i] -= 0.1f * 0.05f; if (rnd.NextFloat() <= 0.05f) { flameHeat[i] = 0.5f * 0.05f; } // Output the pixel float col = soupHeat[i]; col = col < 0 ? 0 : col; col = col > 1 ? 1 : col; col = col * col; float r = 32 + col * 32; float g = 50 + col * 64; float a = 146 + col * 50; *ptr = (byte)a << 24 | (byte)r << 16 | (byte)g << 8 | 255; ptr++; i++; } } }
public static void Shuffle <T>(this List <T> list, JavaRandom random = null) { // This is an implementation of the Fisher Yates shuffle algorithm if (random == null) { random = new JavaRandom(Environment.TickCount); } for (int i = list.Count - 1; i > 0; i--) { int j = random.nextInt(i + 1); T val = list[i]; list[i] = list[j]; list[j] = val; } }
public void Init(Game game) { this.game = game; rand = new JavaRandom(); double x = (0.0 / 24000.0) + 0.25; if (x < 0) { x += 1; } CelestialAngle = x + ((1.0 - (Math.Cos(x * Math.PI) + 1.0) / 2.0) - x) / 3.0; game.Events.TextureChanged += TextureChanged; game.Events.TexturePackChanged += TexturePackChanged; game.Graphics.ContextLost += ContextLost; game.Graphics.ContextRecreated += ContextRecreated; ContextRecreated(); }
public NoiseGenerator2(JavaRandom random) { field_4295_e = new int[512]; field_4292_a = random.nextDouble() * 256D; field_4291_b = random.nextDouble() * 256D; field_4297_c = random.nextDouble() * 256D; for (int i = 0; i < 256; i++) { field_4295_e[i] = i; } for (int j = 0; j < 256; j++) { int k = random.nextInt(256 - j) + j; int l = field_4295_e[j]; field_4295_e[j] = field_4295_e[k]; field_4295_e[k] = l; field_4295_e[j + 256] = field_4295_e[j]; } }
public NoiseGeneratorPerlin(JavaRandom random) { permutations = new int[512]; xCoord = random.nextDouble() * 256D; yCoord = random.nextDouble() * 256D; zCoord = random.nextDouble() * 256D; for (int i = 0; i < 256; i++) { permutations[i] = i; } for (int j = 0; j < 256; j++) { int k = random.nextInt(256 - j) + j; int l = permutations[j]; permutations[j] = permutations[k]; permutations[k] = l; permutations[j + 256] = permutations[j]; } }
public ChunkGenerator(ChunkHandler ChunkHandler) { rnd = new JavaRandom(); rnd2 = new JavaRandom(); this.Seed = rnd.GetSeed(); //chunkXMul = rnd.nextLong(); //chunkZMul = rnd.nextLong(); n1 = new CombinedNoise( new OctaveNoise(8, rnd), new OctaveNoise(8, rnd)); n2 = new CombinedNoise( new OctaveNoise(8, rnd), new OctaveNoise(8, rnd)); n3 = new OctaveNoise(6, rnd); n4 = new OctaveNoise(8, rnd); n5 = new OctaveNoise(8, rnd); n6 = new OctaveNoise(8, rnd); n7 = new OctaveNoise(8, rnd); this.ChunkHandler = ChunkHandler; }
public Board(JavaRandom random, int playerCount) { Grid = new Field[WIDTH, HEIGHT]; for (int x = 0; x < WIDTH; x++) { for (int y = 0; y < HEIGHT; y++) { Grid[x, y] = new Field(x, y); allFields.Add(Grid[x, y]); } } foreach (Field f in allFields) { f.InitNeighbors(Grid); } for (int i = 0; i < playerCount; i++) { players.Add(new Player(i, this)); } int boxCount = 30 + random.nextInt(36); int[] toDistribute = new int[2] { boxCount / 3, boxCount / 3 }; List <Field> startingPositions = new List <Field>() { Grid[0, 0], Grid[0, HEIGHT - 1], Grid[WIDTH - 1, HEIGHT - 1], Grid[WIDTH - 1, 0] }; int iterations = 0; int boxId = 0; while (boxId < boxCount) { iterations++; if (iterations > 1000) { break; } int x = random.nextInt(WIDTH); int y = random.nextInt(HEIGHT); bool ok = true; foreach (var p in startingPositions) { if ((Math.Abs(p.X - x) + Math.Abs(p.Y - y)) < 2) { ok = false; break; } } if (!ok) { continue; } if (Grid[x, y].Wall || Grid[x, y].Box) { continue; } Grid[x, y].Box = true; for (int i = 0; i < 2; ++i) { if (toDistribute[i] > 0) { Grid[x, y].PowerUp = new PowerUp { ExtraRange = (i == 0), ExtraBomb = (i != 0), field = Grid[x, y] }; --toDistribute[i]; break; } } ++boxId; List <Field> otherCells = new List <Field>() { Grid[WIDTH - x - 1, y], Grid[WIDTH - x - 1, HEIGHT - y - 1], Grid[x, HEIGHT - y - 1] }; foreach (var c in otherCells) { if (!c.Wall && !c.Box) { c.Box = true; ++boxId; if (Grid[x, y].PowerUp != null) { c.PowerUp = new PowerUp { ExtraRange = Grid[x, y].PowerUp.ExtraRange, ExtraBomb = Grid[x, y].PowerUp.ExtraBomb, field = c }; --toDistribute[c.PowerUp.ExtraRange?0:1]; } } } } }
public static void GetSeed_Tests(int seed, long expected) { var output = JavaRandom.GetSeed(seed); Assert.AreEqual(output, expected); }