private void CalculateOpponentsOverallMetrics(GameState gameState, MetricsEvaluator evaluator) { Metrics overallMetrics; if (gameState.OpponentsCell.IsACutVertex) { gameState.OpponentsCell.CalculateSubtreeMetricsForOpponent(evaluator, null /* No entry component */); overallMetrics = gameState.OpponentsCell.SubtreeMetricsForOpponent; } else { BiconnectedComponent playersComponent = gameState.OpponentsCell.GetBiconnectedComponents().FirstOrDefault(); if (playersComponent == null) { // The player has no more moves left - there are no edges leading from the cell, and hence no components to be part of! overallMetrics = Metrics.Zero; } else { playersComponent.CalculateSubtreeMetricsForOpponent(evaluator, gameState.OpponentsCell); overallMetrics = playersComponent.SubtreeMetricsForOpponent; } } gameState.NumberOfCellsClosestToOpponent = overallMetrics.NumberOfCellsClosestToPlayer; gameState.NumberOfCellsReachableByOpponent = overallMetrics.NumberOfCellsReachableByPlayer; gameState.TotalDegreesOfCellsClosestToOpponent = overallMetrics.TotalDegreesOfCellsClosestToPlayer; gameState.TotalDegreesOfCellsReachableByOpponent = overallMetrics.TotalDegreesOfCellsReachableByPlayer; gameState.SumOfDistancesFromYouOnOpponentsClosestCells = overallMetrics.SumOfDistancesFromOtherPlayerOnClosestCells; gameState.SumOfDistancesFromOpponentOnOpponentsClosestCells = overallMetrics.SumOfDistancesFromThisPlayerOnClosestCells; gameState.NumberOfComponentBranchesInOpponentsTree = overallMetrics.NumberOfComponentBranchesInTree; }
public void Calculate(GameState gameState, MetricsEvaluator evaluator) { #if DEBUG Stopwatch swatch = Stopwatch.StartNew(); #endif count = 0; nextComponentNumber = 1; edgeStack = new Stack <Edge>(); Queue <CellState> cellsToVisit = new Queue <CellState>(); gameState.ClearBiconnectedComponentProperties(); foreach (CellState cellState in gameState.GetAllCellStates()) { if (cellState.OccupationStatus != OccupationStatus.YourWall && cellState.OccupationStatus != OccupationStatus.OpponentWall) { cellState.ClearBiconnectedComponentProperties(); cellsToVisit.Enqueue(cellState); } } int cellsToVisitCount = cellsToVisit.Count; while (cellsToVisitCount != 0) { CellState nextCellToVisit = cellsToVisit.Dequeue(); if (!nextCellToVisit.Visited) { Visit(nextCellToVisit); } cellsToVisitCount--; } PerformPostProcessingOnBiconnectedComponents(gameState, evaluator); #if DEBUG swatch.Stop(); Debug.WriteLine(String.Format("Biconnected components algorithm with {1} spaces filled took {0} ", swatch.Elapsed, gameState.OpponentsWallLength + gameState.YourWallLength + 2)); #endif // TODO: Move to a more appropriate place later... //BiconnectedChambersAlgorithm bcChambersAlg = new BiconnectedChambersAlgorithm(); //bcChambersAlg.Calculate(gameState); }
private void PerformPostProcessingOnBiconnectedComponents(GameState gameState, MetricsEvaluator evaluator) { // Calculate the components adjacent to each component as well as the statistics of each component: foreach (BiconnectedComponent component in gameState.GetBiconnectedComponents()) { component.CalculateAdjacentComponents(); component.CalculateMetricsOfComponent(); } // Calculate the metrics based on a tree of components reachable by you: CalculateYourOverallMetrics(gameState, evaluator); CalculateOpponentsOverallMetrics(gameState, evaluator); }