Ejemplo n.º 1
0
		public virtual string Solve(Problem problem, int seed, string[] powerPhrases)
		{
			var finalPowerPhraseBuilder = new SimplePowerPhraseBuilder(powerPhrases);
			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 ReachablePositions(game.map);
						var evaluatePositions = new EvaluatePositions3(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);
						});
                        DebugBest(estimated, evaluatePositions);
						var wayToBestPosition = bestPosition.Item2;
						var unitSolution = staticPowerPhraseBuilder.Build(wayToBestPosition);
						CallEvent(game, unitSolution);
						game.ApplyUnitSolution(unitSolution);
						solution.AddRange(wayToBestPosition);
						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();
				}
			}
		}
Ejemplo n.º 2
0
	    private void DebugBest(Dictionary<Unit, double> estimated, EvaluatePositions3 evaluator)
	    {
	        var best = estimated.OrderByDescending(kv => kv.Value).Take(10).ToArray();
            
            foreach (var unit in best)
	            evaluator.Evaluate(unit.Key);

	    }