From 452585bfc93b2d4873e7afcd710f4082cae6f262 Mon Sep 17 00:00:00 2001 From: eulerscheZahl Date: Sun, 20 Aug 2017 10:04:22 +0200 Subject: [PATCH] seeding for 2 more referees, bugfix for BTTC --- BackToTheCode/BackToTheCodeReferee.cs | 43 ++++++++++++++++--------- TheGreatEscape/TheGreatEscapeReferee.cs | 38 +++++++++++++--------- 2 files changed, 50 insertions(+), 31 deletions(-) diff --git a/BackToTheCode/BackToTheCodeReferee.cs b/BackToTheCode/BackToTheCodeReferee.cs index efb007f..1862081 100644 --- a/BackToTheCode/BackToTheCodeReferee.cs +++ b/BackToTheCode/BackToTheCodeReferee.cs @@ -8,21 +8,28 @@ class BackToTheCodeReferee { public static void Main(string[] args) { - string path = args.Length == 1 ? args[0] : null; - string line = Console.ReadLine(); - int playerCount = int.Parse(line.Split()[1]); - Board board = new Board(playerCount); - int tick = 0; - while (board.Tick ()) { - tick++; - if (path != null) - { - Bitmap bmp = board.Draw(); - bmp.Save(path + System.IO.Path.DirectorySeparatorChar + $"{tick:000}.png"); - bmp.Dispose(); + string path = args.Length == 1 ? args [0] : null; + + int seed = -1; + while (true) { + string[] lineParts = Console.ReadLine ().Split (); + if (lineParts [0] == "###Seed") + seed = int.Parse (lineParts [1]); + else if (lineParts [0] == "###Start") { + int playerCount = int.Parse (lineParts [1]); + Board board = new Board (playerCount, seed); + int tick = 0; + while (board.Tick ()) { + tick++; + if (path != null) { + Bitmap bmp = board.Draw (); + bmp.Save (path + System.IO.Path.DirectorySeparatorChar +$"{tick:000}.png"); + bmp.Dispose (); + } + } + Console.WriteLine (board.Ranking ()); } } - Console.WriteLine (board.Ranking ()); } } @@ -36,9 +43,9 @@ class Board List allFields = new List(); private int round = 0; - public Board(int playerCount) + public Board(int playerCount, int seed) { - Random random = new Random(); + Random random = seed >= 0 ? new Random (seed) : new Random (); for (int i = 0; i < playerCount; i++) { players.Add(new Player(i, random.Next(WIDTH), random.Next(HEIGHT))); } @@ -48,6 +55,12 @@ public Board(int playerCount) allFields.Add (grid [x, y]); } } + + foreach (Player p in players) { + if (players.Any(q => p != q && p.X == q.X && p.Y == q.Y)) + continue; + grid[p.X, p.Y].Conquer(p.ID, round); + } } public Bitmap Draw() { diff --git a/TheGreatEscape/TheGreatEscapeReferee.cs b/TheGreatEscape/TheGreatEscapeReferee.cs index 642e7b8..dd0d5ad 100644 --- a/TheGreatEscape/TheGreatEscapeReferee.cs +++ b/TheGreatEscape/TheGreatEscapeReferee.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Drawing; using System.Linq; @@ -7,23 +7,28 @@ class TheGreatEscapeReferee { public static void Main(string[] args) { - string path = args.Length == 1 ? args[0] : null; + string path = args.Length == 1 ? args [0] : null; - int playerCount = int.Parse(Console.ReadLine().Split()[1]); - - Board board = new Board(playerCount); - if (path != null) - { - Bitmap bmp = board.Draw(); - bmp.Save(path + System.IO.Path.DirectorySeparatorChar + "000.png"); - bmp.Dispose(); - } + int seed = -1; + while (true) { + string[] lineParts = Console.ReadLine ().Split (); + if (lineParts [0] == "###Seed") + seed = int.Parse (lineParts [1]); + else if (lineParts [0] == "###Start") { + int playerCount = int.Parse (lineParts [1]); + Board board = new Board (playerCount, seed); + if (path != null) { + Bitmap bmp = board.Draw (); + bmp.Save (path + System.IO.Path.DirectorySeparatorChar + "000.png"); + bmp.Dispose (); + } - while (board.Play()) - { - board.Tick(path); + while (board.Play ()) { + board.Tick (path); + } + board.DeclareWinner (); + } } - board.DeclareWinner(); } class Board @@ -45,8 +50,9 @@ class Board private static int[,] offset = new int[,] { { 0, 1 }, { 1, 0 }, { 0, -1 }, { -1, 0 } }; private static string[] directions = new string[] { "DOWN", "RIGHT", "UP", "LEFT" }; - public Board(int playerCount) + public Board(int playerCount, int seed) { + if (seed >= 0) random = new Random(seed); this.playerCount = playerCount; for (int i = 0; i < playerCount; i++) {