public void Test6() { var builder = new SimplePowerPhraseBuilder(new[] {"hi", "hihi", "hihihi", "hihihihi", "hihihihihi", "hihihihihihi", "hihihihihihihi", "hihihihihihihihi", "hihihihihihihihihi", "hihihihihihihihihihi" }); var moves = Enumerable.Range(0, 10000).Select(i => MoveType.SW).ToArray(); var sw = Stopwatch.StartNew(); var result = builder.Build(moves); sw.Stop(); Console.WriteLine(sw.Elapsed); Assert.IsTrue(Regex.IsMatch(result, @"(hi)+", RegexOptions.IgnoreCase)); }
public override string Solve(Problem problem, int seed, string[] powerPhrases) { var finalPowerPhraseBuilder = new SimplePowerPhraseBuilder(powerPhrases); var spelledPhrases = new bool[powerPhrases.Length]; var solution = new List<MoveType>(); var game = new SolverGame(problem, seed, powerPhrases); while (true) { switch (game.state) { case GameBase.State.WaitUnit: game.Step(); break; case GameBase.State.UnitInGame: if (nextUnitsPositions == null || !nextUnitsPositions.Any()) { var bestPositions = FindBestPositions_Recursive(unitsAhead, game.map.Clone(), new[] { game.currentUnit }.Concat(game.GetAllRestUnits()).ToArray(), 0, powerPhrases, spelledPhrases); nextUnitsPositions = bestPositions.Item2.ToList(); } var wayToBestPosition = nextUnitsPositions.First(); nextUnitsPositions = nextUnitsPositions.Skip(1).ToList(); var unitSolution = staticPowerPhraseBuilder.Build(wayToBestPosition.Item2.path); CallEvent(game, unitSolution); game.ApplyUnitSolution(unitSolution); solution.AddRange(wayToBestPosition.Item2.path); spelledPhrases = wayToBestPosition.Item2.spelledWords; break; case GameBase.State.EndInvalidCommand: case GameBase.State.EndPositionRepeated: throw new InvalidOperationException(string.Format("Invalid state: {0}", game.state)); case GameBase.State.End: return finalPowerPhraseBuilder.Build(solution); default: throw new ArgumentOutOfRangeException(); } } }
public string Solve(Problem problem, int seed, string[] powerPhrases) { var finalPowerPhraseBuilder = new SimplePowerPhraseBuilder(powerPhrases); var spelledPhrases = new bool[powerPhrases.Length]; var solution = new List<MoveType>(); var game = new SolverGame(problem, seed, powerPhrases); while (true) { switch (game.state) { case GameBase.State.WaitUnit: game.Step(); break; case GameBase.State.UnitInGame: var reachablePositions = new ReachablePositionsWithWords(game.map, powerPhrases, spelledPhrases); var evaluatePositions = new EvaluatePositions2(game.map); var endPositions = reachablePositions.EndPositions(game.currentUnit); var estimated = new Dictionary<Unit, double>(); var bestPosition = endPositions.ArgMax(p => { double value; if (estimated.TryGetValue(p.Item1, out value)) return value; return estimated[p.Item1] = evaluatePositions.Evaluate(p.Item1); }); var score = evaluatePositions.Evaluate(bestPosition.Item1); var wayToBestPosition = bestPosition.Item2; var unitSolution = staticPowerPhraseBuilder.Build(wayToBestPosition.path); SolutionAdded(game, unitSolution); game.ApplyUnitSolution(unitSolution); spelledPhrases = wayToBestPosition.spelledWords; solution.AddRange(wayToBestPosition.path); break; case GameBase.State.EndInvalidCommand: case GameBase.State.EndPositionRepeated: throw new InvalidOperationException(string.Format("Invalid state: {0}", game.state)); case GameBase.State.End: return finalPowerPhraseBuilder.Build(solution); default: throw new ArgumentOutOfRangeException(); } } }
public void Test5() { var builder = new SimplePowerPhraseBuilder(new[] {"Ei!", "hi", "hi hi"}); var result = builder.Build(new[] {MoveType.E, MoveType.SW, MoveType.SW, MoveType.SW, MoveType.SE, MoveType.SW, MoveType.SW, MoveType.SE, MoveType.SW, MoveType.SW}); Assert.IsTrue(Regex.IsMatch(result, @".hi..hi hi", RegexOptions.IgnoreCase)); }
public void Test4() { var builder = new SimplePowerPhraseBuilder(new[] {"Ei!"}); Assert.AreEqual("ei!ei!", builder.Build(new[] {MoveType.E, MoveType.SW, MoveType.W, MoveType.E, MoveType.SW, MoveType.W})); }
public void Test2() { var builder = new SimplePowerPhraseBuilder(null); Assert.AreEqual(3, builder.Build(new[] {MoveType.E, MoveType.SW, MoveType.W}).Length); }
public void Test1() { var builder = new SimplePowerPhraseBuilder(null); Assert.AreEqual("", builder.Build(new MoveType[0])); }