public FuturesPositioner(Map map, Graph graph, IList <int> path, MineDistCalculator minDists) { this.map = map; this.graph = graph; this.path = path; this.minDists = minDists; }
public FutureIsNowSetupStrategy(State state, IServices services, double pathMultiplier = 1) { this.pathMultiplier = pathMultiplier; this.state = state; graph = services.Get <Graph>(); mineDistCalculator = services.Get <MineDistCalculator>(); }
public PathSelector(Map map, MineDistCalculator minDists, int length) { this.map = map; graph = new Graph(map); this.minDists = minDists; this.length = length; }
public FutureConnectivityDependentSetupStrategy( double pathMultiplier, State state, IServices services) { futureIsNowSetupStrategy = new FutureIsNowSetupStrategy(state, services, pathMultiplier); this.state = state; graph = services.Get <Graph>(); mineDistCalculator = services.Get <MineDistCalculator>(); }
public void SelectMines() { var map = MapLoader.LoadMapByNameInTests("tube.json").Map; var desiredLen = 15; var graph = new Graph(map); var minDists = new MineDistCalculator(graph); var path = new PathSelector(map, minDists, desiredLen).SelectPath(); var positioner = new FuturesPositioner(map, graph, path, minDists); var futures = positioner.GetFutures(); map.ShowWithPath(path, futures); }
private static int CalculateCost(Future future, MineDistCalculator calculator) { var dist = 0; try { dist = calculator.GetDist(future.source, future.target); } catch (InvalidOperationException) { try { dist = calculator.GetDist(future.target, future.source); } catch (InvalidOperationException) { return(0); } } return(dist * dist * dist); }
public MeetingPointService(Graph graph, MineDistCalculator calculator, ServiceState serviceState, bool isSetupStage) { if (isSetupStage) { var bestPoint = -1; var bestValue = 0; var bestCount = 0; foreach (var vertex in graph.Vertexes) { if (vertex.Value.IsMine) { continue; } var value = 0; var count = 0; foreach (var mine in graph.Mines) { var dist = calculator.GetDist(mine.Key, vertex.Key); if (dist == -1) { continue; } count++; value += dist; } if (bestPoint == -1 || bestCount < count || bestCount == count && value < bestValue) { bestPoint = vertex.Key; bestCount = count; bestValue = value; } } serviceState.meetingPoint = bestPoint; } MeetingPoint = serviceState.meetingPoint; }
public ScoreData GetScoreData(int punter, Map map, Future[] futures) { var scoreData = new ScoreData(); var graph = new Graph(map); var distCalc = new MineDistCalculator(graph); var minesCalc = new ConnectedCalculator(graph, punter); long res = 0; foreach (var vertex in graph.Vertexes) { var mines = minesCalc.GetConnectedMines(vertex.Key); foreach (var mine in mines) { long dist = distCalc.GetDist(mine, vertex.Key); res += dist * dist; } } scoreData.ScoreWithoutFutures = res; foreach (var future in futures) { var mines = minesCalc.GetConnectedMines(future.target); var dist = distCalc.GetDist(future.source, future.target); var futureScoreValue = dist * dist * dist; if (mines.Contains(future.source)) { scoreData.GainedFuturesScore += futureScoreValue; scoreData.GainedFuturesCount++; } scoreData.PossibleFuturesScore += futureScoreValue; scoreData.TotalFuturesCount++; } return(scoreData); }
public void SetFutures(Dictionary <int, Future[]> futures, Map map) { this.futures = futures; var graph = new Graph(map); futureToListIndex.Clear(); futuresList.Items.Clear(); var calculator = new MineDistCalculator(graph); var i = 0; foreach (var futuresGroup in futures) { var id = futuresGroup.Key; foreach (var future in futuresGroup.Value) { var str = $"{id}:\t{future.source}->{future.target}\t|{CalculateCost(future, calculator)}"; futuresList.Items.Add(str, false); futureToListIndex[future] = i++; } } UpdateFuturesStats(map); }
private int CalcProperVertexScore(int vertexId, ICollection <int> claimedMineIds) { return(claimedMineIds.Select( mineId => MineDistCalculator.GetDist(mineId, vertexId)) .Sum(x => GetScore(claimedMineIds, x, vertexId))); }