public static Tuple <Solution, int> FindSolution(Map map, Robot[] robots) { var platformCells = map.EmptyCells; Solution bestSolution = null; int bestScore = -1; Stopwatch watch = Stopwatch.StartNew(); int simulationCount = 0; while (watch.ElapsedMilliseconds < 970) { var solution = RandomSolutionFinder.GenerateRandomSolution(map, platformCells); //Evaluate var newMap = map.Apply(solution.Arrows); int score = ScoreCalculator.ComputeScore(newMap, robots); if (score > bestScore) { bestScore = score; bestSolution = solution; } simulationCount++; } Player.Debug($"Nb Simulation {simulationCount.ToString()} in {watch.ElapsedMilliseconds.ToString()}ms"); Player.Debug($"Best score achieved: {bestScore.ToString()}"); return(new Tuple <Solution, int>(bestSolution, bestScore)); }
public static void Run() { var map = new Map( "###################", "###################", "###################", "###################", "###............####", "###################", "###################", "###################", "###################", "###################"); var robots = new Robot[] { new Robot(0, 3, 4, 'R') }; var bestSolution = RandomSolutionFinder.FindSolution(map, robots); }
static void Main(string[] args) { //Test.Run(); string[] lines = new string[10]; for (int i = 0; i < 10; i++) { string line = Console.ReadLine(); lines[i] = line; } Map map = new Map(lines); int robotCount = int.Parse(Console.ReadLine()); Robot[] robots = new Robot[robotCount]; for (int i = 0; i < robotCount; i++) { string[] inputs = Console.ReadLine().Split(' '); int x = int.Parse(inputs[0]); int y = int.Parse(inputs[1]); string direction = inputs[2]; robots[i] = new Robot(i, x, y, direction[0]); } var bestSolution = RandomSolutionFinder.FindSolution(map, robots); // Write an action using Console.WriteLine() // To debug: Console.Error.WriteLine("Debug messages..."); var output = bestSolution.Item1.ToString(); Player.Debug(output); Console.WriteLine(output); }