本文整理汇总了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);
}
}
示例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;
}