public static void PlayAuto(int problemnum, string solution, int seed, string[] powerPhrases, int delay) { var problem = ProblemsSet.GetProblem(problemnum); var game = new Game(problem, new Output() { solution = solution, seed = problem.sourceSeeds[seed] }, powerPhrases); var emulator = new Emulator(game, delay); emulator.Run(); }
public static void ShowProblems() { var console = new FastConsole(); var p = 0; while(true) { var problem = ProblemsSet.GetProblem(p); var game = new Game(problem, new Output() { solution = "" }, new string[0]); var map = game.map; using (var drawer = new Drawer(console)) { drawer.console.WriteLine(string.Format("problem {0}", p)); drawer.DrawMap(map, null); foreach (var unit in game.problem.units) { drawer.DrawUnit(unit); } } Console.SetWindowPosition(0, 0); var key = Console.ReadKey(false); if (key.Key == ConsoleKey.LeftArrow) --p; else ++p; if (p < 0) p = 0; if (p > 24) p = 24; } }
public Result CountScore(Problem problem, Func<IProblemSolver> solverFactory, string[] powerPhrases, string folder) { long sum = 0; var lockerForLists = new object(); List<Output> outputs = new List<Output>(); List<GameBase.State> states = new List<GameBase.State>(); List<int> scores = new List<int>(); Parallel.For(0, problem.sourceSeeds.Length, new ParallelOptions() { MaxDegreeOfParallelism = Math.Max(1, Environment.ProcessorCount - 2) }, seedInd => { var solver = solverFactory(); var seed = problem.sourceSeeds[seedInd]; try { Console.WriteLine("Problem {0}: seed {1} started counting", problem.id, seed); var stopwatch = Stopwatch.StartNew(); var solution = solver.Solve(problem, seed, powerPhrases); stopwatch.Stop(); var output = new Output() { problemId = problem.id, seed = seed, solution = solution }; var game = new Game(problem, output, powerPhrases); while (game.state == GameBase.State.UnitInGame || game.state == GameBase.State.WaitUnit) { game.Step(); } lock (lockerForLists) { scores.Add(game.CurrentScore); states.Add(game.state); outputs.Add(output); } Console.WriteLine("Problem {0}: seed: {1}, score: {2}, time: {3}", problem.id, seed, game.CurrentScore, stopwatch.Elapsed); SaveOutput(folder + problem.id, output); } catch (Exception ex) { Console.WriteLine("Problem {0}: seed {1} crashed {2}", problem.id, seed, ex.Message); throw; } }); var result = new Result { Outputs = outputs.ToArray(), EndStates = states.ToArray(), Scores = scores.ToArray() }; SaveResult(folder + problem.id, result); return result; }
public void RecountScores() { var groupBy = GetSolves(); var ungroup = groupBy.SelectMany(g => g); var groupByProblemAndName = ungroup.GroupBy(g => g.Item1 + "<->" + g.Item2); foreach (var g in groupByProblemAndName) { var problFolder = Path.Combine(idealSolvesFolder, g.First().Item1, g.First().Item2); var cb = new StringBuilder(); var sum = 0; foreach (var seedTuple in g) { var seed = seedTuple.Item3; var solution = File.ReadAllText(problFolder + @"\" + seed).ParseAsJson<Output>().solution; var game = new Game(ProblemsSet.GetProblem(int.Parse(seedTuple.Item2)), new Output() { solution = solution, seed = int.Parse(seed) }, PowerDatas.GetPowerPhrases()); while (game.state == GameBase.State.UnitInGame || game.state == GameBase.State.WaitUnit) game.Step(); var resultingScoring = game.CurrentScore; sum += game.CurrentScore; cb.AppendLine(seed + " " + resultingScoring); } var result = cb.ToString(); File.WriteAllText(problFolder + @"\" + "score" + (sum / g.Count()) + ".txt", result); } }
public static void Solve(int problemnum, int seed, string[] magicSpells, int delay, bool visualize) { var problem = ProblemsSet.GetProblem(problemnum); // var solver = new MuggleProblemSolver(); var solver = SelectSolver(problem); var stopwatch = Stopwatch.StartNew(); var solution = solver.Solve(problem, problem.sourceSeeds[seed], magicSpells); stopwatch.Stop(); var game = new Game(problem, new Output { seed = problem.sourceSeeds[seed], solution = solution }, magicSpells); if (visualize) { var emulator = new Emulator(game, delay); emulator.Run(); } else { while (game.state == GameBase.State.UnitInGame || game.state == GameBase.State.WaitUnit) { game.Step(); } Console.WriteLine("Score=" + game.CurrentScore); Console.WriteLine("Time=" + stopwatch.Elapsed); Console.ReadKey(); } }