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


C# Hex.Adjacent方法代码示例

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


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

示例1: BreadthFirstSearch

    public static List<Hex> BreadthFirstSearch(Hex source, List<List<Hex>> map, int moves, Team team)
    {
        Queue<Hex> queue = new Queue<Hex>();
        List<Hex> found = new List<Hex>();
        List<Hex> visited = new List<Hex>();
        source.Adjacent(map).ForEach(h => queue.Enqueue(h));
        Hex current = null;

        while(queue.Count > 0) {
            current = queue.Dequeue();
            if(DepthFirstSearch(source, current, map, moves, team == 0).Count > 0 && !visited.Contains(current) && (team == Team.NEUTRAL || (current.Unit == null || current.Unit.Team == ((team == Team.ME) ? Team.ENEMY : Team.ME)))) {
                found.Add(current);
                current.Adjacent(map).ForEach(h => queue.Enqueue(h));
            }
            visited.Add(current);
        }

        return found;
    }
开发者ID:AndersHqst,项目名称:Battle-For-Betelgeuse,代码行数:19,代码来源:PathFinder.cs

示例2: DFS

    static List<Hex> DFS(Hex thisHex, Hex toHex, List<List<Hex>> map, int moves, List<Hex> acc, bool ignoreUnits)
    {
        try {
        if(thisHex.GridPosition != toHex.GridPosition) {
            if(moves < 1) {
                return new List<Hex>();
            } else {
                List<Hex> adj = thisHex.Adjacent(map);
                if(!ignoreUnits) {
                    adj.RemoveAll (h => !(h.Unit == null || h.GridPosition == targetTile.GridPosition));
                }
                Hex nextHex = null;
                foreach(Hex h in adj) {
                        if(nextHex != null) {
                            float oldD = Mathf.Sqrt(
                                            Mathf.Pow(nextHex.GridPosition.x - toHex.GridPosition.x, 2) +
                                            Mathf.Pow(nextHex.GridPosition.y - toHex.GridPosition.y, 2)
                                );
                            float newD = Mathf.Sqrt(
                                            Mathf.Pow(h.GridPosition.x - toHex.GridPosition.x, 2) +
                                            Mathf.Pow(h.GridPosition.y - toHex.GridPosition.y, 2)
                                );

                            if(newD < oldD) {
                                nextHex = h;
                            }
                        } else {
                            nextHex = h;
                        }
                }
                acc.Add(nextHex);
                return DFS (nextHex, toHex, map, moves-1, acc, ignoreUnits);
            }
            } else { return acc; }
        } catch {
            return acc;
        }
    }
开发者ID:AndersHqst,项目名称:Battle-For-Betelgeuse,代码行数:38,代码来源:PathFinder.cs

示例3: getMoves

 void getMoves(Hex hex, int i, List<Hex> acc)
 {
     if(i < 1) {
         return;
     } else {
         List<Hex> adj = hex.Adjacent(gameControl.GridControl.Map).FindAll(h => !acc.Contains(h) && (h.Unit == null || (h.Unit.Team != 0 && h.Unit.Team != player.Team)));
         acc.AddRange(adj);
         adj.ForEach(h => getMoves(h, --i, acc));
     }
 }
开发者ID:AndersHqst,项目名称:Battle-For-Betelgeuse,代码行数:10,代码来源:EasyAI.cs


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