예제 #1
0
        public void Test()
        {
            string word = "blue hades";
            var problemnum = 2;
            int unitIndex = 2;
            int seedIndex = 5;

            var problem = ProblemsSet.GetProblem(problemnum);
            var originalUnit = problem.units[unitIndex];
            var prefix = new List<MoveType>();
            var spawnedUnit = Game.SpawnUnit(originalUnit, problem).Move(MoveType.SE).Move(MoveType.SW);
            var unit = spawnedUnit;
            var units = new List<Unit> { unit };

            foreach (var c in word)
            {
                var moveType = MoveTypeExt.Convert(c);
                unit = unit.Move(moveType.Value);
                units.Add(unit);
            }
            var minX = units.SelectMany(x => x.members).Min(t => t.x);
            while (minX < 0)
            {
                prefix.Add(MoveType.E);
                minX++;
            }
            while (minX > 0)
            {
                prefix.Add(MoveType.W);
                minX--;
            }
            prefix.Add(MoveType.SE);
            prefix.Add(MoveType.SW);

            var game = new SolverGame(problem, problem.sourceSeeds[seedIndex], new string[0]);
            game.Step();
            var danananananananananananananan = "danananananananananananananan";
            game.ApplyUnitSolution(danananananananananananananan);
            if (game.state != GameBase.State.End && game.state != GameBase.State.WaitUnit)
                throw new InvalidOperationException(string.Format("Invalid game state: {0}", game.state));
            game.Step();
            Assert.That(game.spawnedUnitIndex, Is.EqualTo(unitIndex));
            var staticPowerPhraseBuilder = new StaticPowerPhraseBuilder();
            var solution = staticPowerPhraseBuilder.Build(prefix) + word;
            Console.Out.WriteLine(danananananananananananananan + solution);
            game.ApplyUnitSolution(solution);

            var output = new Output
            {
                problemId = problemnum,
                seed = problem.sourceSeeds[seedIndex],
                solution = danananananananananananananan + solution
            };
        }
예제 #2
0
        public void TestSendSolution()
        {
            var solution = new Output
            {
                problemId = 2,
                seed = 15385,//seed! ,Not index
                tag = "new15K!_reg" + " " + DateTime.Now.ToString("O"),
                solution = "dananananananananananananananpppppplacthulhu fhtagn!"
            };

            var result = HttpHelper.SendOutput(DavarAccount.TestTeam, solution);
            Assert.IsTrue(result);
        }
예제 #3
0
        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;
        }
예제 #4
0
 public Game([NotNull] Problem problem, [NotNull] Output output, string[] magicSpells)
     : base(problem, output.seed, magicSpells)
 {
     this.output = output;
     currentCommand = 0;
 }
예제 #5
0
 private static void SaveOutput(string directory, Output output)
 {
     if (!Directory.Exists(directory))
         Directory.CreateDirectory(directory);
     var path = Path.Combine(directory, "" + output.seed);
     File.WriteAllText(path, output.ToJson());
 }