Beispiel #1
0
        private void Visit(CellState startCellState)
        {
            startCellState.Visited = true;
            count++;
            startCellState.DfsDepth = count;
            startCellState.DfsLow   = count;
            foreach (CellState adjacentCellState in startCellState.GetAdjacentCellStates())
            {
                if (adjacentCellState.OccupationStatus != OccupationStatus.YourWall && adjacentCellState.OccupationStatus != OccupationStatus.OpponentWall)
                {
                    if (!adjacentCellState.Visited)
                    {
                        Edge newEdge = new Edge
                        {
                            StartVertex = startCellState,
                            EndVertex   = adjacentCellState
                        };
                        edgeStack.Push(newEdge);
                        adjacentCellState.ParentCellState = startCellState;
                        Visit(adjacentCellState);
                        if (adjacentCellState.DfsLow >= startCellState.DfsDepth)
                        {
                            // Create a biconnected component
                            BiconnectedComponent component = new BiconnectedComponent(nextComponentNumber);
                            nextComponentNumber++;
                            startCellState.GameState.AddBiconnectedComponent(component);

                            Edge poppedEdge = null;
                            do
                            {
                                poppedEdge = edgeStack.Pop();
                                component.AddCell(poppedEdge.StartVertex);
                                component.AddCell(poppedEdge.EndVertex);
                                poppedEdge.StartVertex.AddBiconnectedComponent(component);
                                poppedEdge.EndVertex.AddBiconnectedComponent(component);
                            }while (poppedEdge != newEdge);
                        }
                        if (adjacentCellState.DfsLow < startCellState.DfsLow)
                        {
                            startCellState.DfsLow = adjacentCellState.DfsLow;
                        }
                    }
                    else
                    if (!(adjacentCellState.ParentCellState == startCellState) && (adjacentCellState.DfsDepth < startCellState.DfsDepth))
                    {
                        // The link from startCellState to adjacentCellState is a back edge to an ancestor of startCellState:
                        Edge backEdge = new Edge
                        {
                            StartVertex = startCellState,
                            EndVertex   = adjacentCellState
                        };
                        edgeStack.Push(backEdge);
                        if (adjacentCellState.DfsDepth < startCellState.DfsLow)
                        {
                            startCellState.DfsLow = adjacentCellState.DfsDepth;
                        }
                    }
                }
            }
        }
Beispiel #2
0
        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;
        }