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 result = new List <TurnResult>(); var mines = Graph.Mines.Keys.ToList(); for (var i = 0; i < mines.Count; i++) { for (var j = i + 1; j < mines.Count; j++) { var denic = new Dinic(Graph, PunterId, mines[i], mines[j], out int flow); if (flow == 0 || flow == Dinic.INF) { continue; } var cut = denic.GetMinCut(); foreach (var edge in cut) { result.Add( new TurnResult { Estimation = Random.Value.NextDouble(), Move = AiMoveDecision.Claim(edge, PunterId, "Because I'm crazy!") }); } } } return(result); }
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()); }
public List <TurnResult> NextTurns() { Init(); return(Graph.Vertexes.Values .SelectMany(v => v.Edges) .Select( edge => edge.IsFree ? new TurnResult { Estimation = EstimateWeight(edge), Move = AiMoveDecision.Claim(edge, PunterId), } : null) .Where(river => river != null && river.Estimation > 0) .ToList()); }