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


C# Tile.addToTotalCost方法代码示例

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


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

示例1: iterateAStar

        private Tile iterateAStar(Tile start, Tile goal)
        {
            if(DEBUG)
                Console.WriteLine("Called iterateAStar!, goal is at (" + goal.getMapX() + "," + goal.getMapY() + ")");

            Tile ret = null;
            List<Tile> bestpath = new List<Tile>();
            List<Tile> closed = new List<Tile>();
            start.addToTotalCost(Math.Abs(start.getMapX() - goal.getMapX()) + Math.Abs(start.getMapY() - goal.getMapY()));
            List<Tile> open = new List<Tile>();
            open.Add(start);
            while (open.Count > 0)
            {
                //get the lowest cost node...
                Tile cur = open.Min();
                if(DEBUG)
                    Console.WriteLine("Min retrieved a node with " + cur.getTotalCost() + " from the open list");

                if (cur.getMapX() == goal.getMapX() && cur.getMapY() == goal.getMapY())
                {
                    if(DEBUG)
                        Console.WriteLine("Found goal! cur is (" + cur.getMapX() + "," + cur.getMapY() + ")");

                    return cur;
                    //return addToBestPath(bestpath, cur, last);
                }
                else
                {
                    //Tile newlast = addToBestPath(bestpath, cur, last);
                    int curx = cur.getMapX();
                    int cury = cur.getMapY();
                    //last = newlast;
                    open.Remove(cur);
                    closed.Add(cur);
                    Tile up = map.getTileAt(curx, cury - 1);
                    Tile down = map.getTileAt(curx, cury + 1);
                    Tile left = map.getTileAt(curx - 1, cury);
                    Tile right = map.getTileAt(curx + 1, cury);

                    if (canAdd(up, open, closed))
                        addTile(up, cur, open, goal);

                    if (canAdd(down, open, closed))
                        addTile(down, cur, open, goal);

                    if (canAdd(left, open, closed))
                        addTile(left, cur, open, goal);

                    if (canAdd(right, open, closed))
                        addTile(right, cur, open, goal);
                }

            }
            if(DEBUG)
                Console.WriteLine("Failed to find a path!");

            return ret;
        }
开发者ID:gogetasama,项目名称:cs134rpg,代码行数:58,代码来源:Game1.cs

示例2: addTile

 private void addTile(Tile toadd, Tile prev, List<Tile> open, Tile goal)
 {
     toadd.setPrevious(prev);
     int distance = getCumulativeCost(toadd);
     toadd.addToTotalCost(distance + Math.Abs(toadd.getMapX() - goal.getMapX()) + Math.Abs(toadd.getMapY() - goal.getMapY()));
         if(DEBUG)
         Console.WriteLine("Adding node with cost " + toadd.getTotalCost() + " to open list");
     open.Add(toadd);
 }
开发者ID:gogetasama,项目名称:cs134rpg,代码行数:9,代码来源:Game1.cs


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