コード例 #1
0
        private List <TurnResult> GetTurnsForComponents(Graph graph, ConnectedComponent[] connectedComponents, ConnectedComponent currentComponent)
        {
            EdgeWeighter.Init(connectedComponents, currentComponent);

            var vertices = currentComponent.Vertices
                           .SelectMany(v => graph.Vertexes[v].Edges)
                           .ToList();

            var claimVertices = vertices
                                .Where(e => e.Owner == -1 && !AreConnected(currentComponent, e.From, e.To))
                                .Select(e => new TurnResult
            {
                Estimation = EdgeWeighter.EstimateWeight(e),
                Move       = AiMoveDecision.Claim(e, PunterId)
            });

            var optionVertices = !State.settings.options || State.map.OptionsLeft(State.punter) <= 0
                ? Enumerable.Empty <TurnResult>()
                : vertices
                                 .Where(e => e.Owner != -1 && e.OptionOwner == -1 && !AreConnected(currentComponent, e.From, e.To))
                                 .Select(e => new TurnResult
            {
                Estimation = EdgeWeighter.EstimateWeight(e) * OptionPenaltyMultiplier,
                Move       = AiMoveDecision.Option(e, PunterId)
            }).ToList();

            return(claimVertices.Concat(optionVertices)
                   .Where(t => t.Estimation > 0)
                   .ToList());
        }
        public List <TurnResult> NextTurns()
        {
            var claimedVertexes = Graph.Vertexes.Values
                                  .SelectMany(x => x.Edges)
                                  .Where(edge => edge.Owner == PunterId)
                                  .SelectMany(edge => new[] { edge.From, edge.To })
                                  .Distinct()
                                  .ToArray();

            if (claimedVertexes.Length == 0)
            {
                return(Graph.Mines.Values
                       .SelectMany(v => v.Edges)
                       .Where(e => e.Owner == -1)
                       .Select(
                           e => new TurnResult
                {
                    Estimation = 1,
                    Move = AiMoveDecision.Claim(e, PunterId, "No edges yet, selecting first mine")
                })
                       .ToList());
            }

            var connectedComponents = ConnectedComponentsService.For(PunterId);
            var maxComponent        = connectedComponents.MaxBy(comp => comp.Vertices.Count);

            EdgeWeighter.Init(connectedComponents, maxComponent);

            var vertices = maxComponent.Vertices
                           .SelectMany(v => Graph.Vertexes[v].Edges)
                           .ToList();

            var claimVertices = vertices
                                .Where(e => e.Owner == -1 && !AreConnected(maxComponent, e.From, e.To))
                                .Select(
                e => new TurnResult
            {
                Estimation = EdgeWeighter.EstimateWeight(e),
                Move       = AiMoveDecision.Claim(e, PunterId)
            });


            var optionVertices = !State.settings.options || State.map.OptionsLeft(State.punter) <= 0
                ? Enumerable.Empty <TurnResult>()
                : vertices
                                 .Where(e => e.Owner != -1 && e.OptionOwner == -1 && !AreConnected(maxComponent, e.From, e.To))
                                 .Select(e => new TurnResult
            {
                Estimation = EdgeWeighter.EstimateWeight(e) * OptionPenaltyMultiplier,
                Move       = AiMoveDecision.Option(e, PunterId)
            }).ToList();

            return(claimVertices.Concat(optionVertices)
                   .Where(t => t.Estimation > 0)
                   .ToList());
        }