当前位置: 首页>>代码示例>>C#>>正文


C# Edge.getNeighbors方法代码示例

本文整理汇总了C#中Edge.getNeighbors方法的典型用法代码示例。如果您正苦于以下问题:C# Edge.getNeighbors方法的具体用法?C# Edge.getNeighbors怎么用?C# Edge.getNeighbors使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Edge的用法示例。


在下文中一共展示了Edge.getNeighbors方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: LongestRoadOfPlayer

    private static int LongestRoadOfPlayer(Player player, Edge visiting, List<Edge> visitedEdges, List<Node> visitedNodes, int length)
    {
        int longestRoad = 0;
        int totalNeighborLongest = 0;
        visitedEdges.Add (visiting);

        foreach (Node neighbor in visiting.getNeighbors ()) {
            int neighborLongest = 0;

            if (!visitedNodes.Contains (neighbor)) {
                visitedNodes.Add (neighbor);

                foreach (Edge neighborEdge in neighbor.getRoads ()) {
                    if (!visitedEdges.Contains (neighborEdge) && neighborEdge.owner == player) {
                        int testLength = LongestRoadOfPlayer (player, neighborEdge, visitedEdges, visitedNodes, length+1);
                        if (testLength > longestRoad) {
                            longestRoad = testLength;
                        }
                        if (testLength > neighborLongest) {
                            neighborLongest = testLength;
                        }
                    }
                }
            }

            totalNeighborLongest += neighborLongest;
        }

        if (length == 0) {
            return totalNeighborLongest + 1;
        }
        else {
            return Math.Max (longestRoad, length);
        }
    }
开发者ID:Gabino3,项目名称:socAI,代码行数:35,代码来源:Board.cs

示例2: ScoreEdge

    /*
     * Score an edge based on possible future expansions up to a crtain depth. Scoring changes with distance from start.
     */
    public static double ScoreEdge(Player player, Board board, Edge edge, List<Edge> visitedEdges, List<Node> visitedNodes, int depth, int maxDepth)
    {
        if (depth > maxDepth) {
            return 0;
        }

        double score = 0;
        visitedEdges.Add (edge);

        foreach (Node neighbor in edge.getNeighbors ()) {
            if (neighbor.occupied == Node.Occupation.none && board.CanBuildSettlementHere(neighbor.visual.transform, player, false)) {
                foreach (Tile tile in neighbor.getTiles ()) {
                    score += TileScore (tile) * DEPTH_MODIFIERS[depth];
                }
            }

            if (!visitedNodes.Contains (neighbor)) {
                visitedNodes.Add (neighbor);
                foreach(Edge neighborEdge in neighbor.getRoads ()) {
                    if (!visitedEdges.Contains (neighborEdge)) {
                        score += ScoreEdge (player, board, neighborEdge, visitedEdges, visitedNodes, depth+1, maxDepth);
                    }
                }
            }
        }

        return score;
    }
开发者ID:Gabino3,项目名称:socAI,代码行数:31,代码来源:AIEngine.cs


注:本文中的Edge.getNeighbors方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。