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 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 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 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 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]; } } } } }