Exemple #1
0
        public AiMoveDecision GetNextMove(State state, IServices services)
        {
            var myStrategy      = StrategyProvider(state, services);
            var enemyStrategies = Enumerable.Range(0, state.punters)
                                  .Except(new[] { state.punter })
                                  .Select(enemyId => StrategyProvider(state, services))
                                  .ToArray();
            var bestTurn       = GetMyBestTurn(myStrategy);
            var enemyBestTurns = enemyStrategies
                                 .Select(s => s.NextTurns())
                                 .Where(ts => ts.Count >= 2)
                                 .Select(ts => ts.OrderByDescending(x => x.Estimation).Take(2).ToArray())
                                 .ToArray();

            if (enemyBestTurns.Any())
            {
                var bestestEnemyTurns = enemyBestTurns.MaxBy(ts => ts[0].Estimation - ts[1].Estimation);
                if (bestestEnemyTurns[0].Estimation > Settings.EnemyTurnEstimationDifferenceWeight *
                    bestestEnemyTurns[1].Estimation &&
                    bestestEnemyTurns[0].Estimation > Settings.MyTurnEsimationWeight * bestTurn.Estimation)
                {
                    bestTurn = bestestEnemyTurns[0];
                }
            }
            if (bestTurn.Estimation < 0)
            {
                return(AiMoveDecision.Pass(state.punter));
            }
            return(bestTurn.Move);
        }
Exemple #2
0
        public AiMoveDecision GetNextMove(State state, IServices services)
        {
            var strategy = StrategyProvider(state, services);
            var turns    = strategy.NextTurns();

            if (!turns.Any())
            {
                return(AiMoveDecision.Pass(state.punter));
            }
            return(turns.MaxBy(x => x.Estimation).Move);
        }
 private static AiMoveDecision GetNextMove(IAi ai, State state, bool eatExceptions, Dictionary <IAi, Exception> lastException)
 {
     try
     {
         return(ai.GetNextMove(state, new Services(state)));
     }
     catch (Exception e)
     {
         lastException[ai] = e;
         if (eatExceptions)
         {
             return(AiMoveDecision.Pass(state.punter, e.ToString()));
         }
         else
         {
             throw;
         }
     }
 }
        private AiMoveDecision TryGetNextMove()
        {
            var meetingPoint = meetingPointService.MeetingPoint;

            var toDo = graph.GetNotOwnedMines(state.punter).Select(x => x.Id);

            var myVerts = graph.Vertexes.Values.Where(
                v =>
                v.Edges.Any(e => e.IsOwnedBy(state.punter)) || v.Id == meetingPoint)
                          .Select(x => x.Id)
                          .ToList();

            var shortest = new ShortestPathFinder(graph, state.punter, myVerts);

            var skip = false;

            foreach (var mine in toDo)
            {
                var path = shortest.GetPath(mine);

                if (path == null)
                {
                    continue;
                }

                int len = path.Count - 1;
                if (len > state.credits[state.punter])
                {
                    skip = true;
                    continue;
                }

                return(AiMoveDecision.Splurge(state.punter, path.ToArray()));
            }

            if (skip)
            {
                return(AiMoveDecision.Pass(state.punter, "wait"));
            }
            return(null);
        }