示例#1
0
 public void add(Node node)
 {
     for (int k = 0; k < size; k++) {
         if (node.f < list[k].f) {
             list.Insert(k, node);
             size++;
             return;
         }
     }
     size++;
     list.Add(node);
 }
示例#2
0
        public List<Node> AStar(Node start, Node dest)
        {
            for (int k = 0; k < graph.Length; k++) {
                graph[k].g = 0;
                graph[k].f = 0;
            }
            List <Node> path= new List<Node>();
            Node[] Closed = new Node[graph.Length];
            int closed_counter = 0;
            JasonQ Open = new JasonQ();
            JasonQ neighborSet;
            Open.add(start);
            for (int k = 0; k < graph.Length; k++) {
                if (graph[k] != start) {
                    Open.add(graph[k]);
                    graph[k].g = 0;
                    graph[k].f = 0;
                }
            }

            Node current;

            double g_score = 0;
            double f_score = g_score + start.H(dest);

            start.g = g_score;
            start.f = f_score;

            double tempg = 0;

            while (Open.Size() > 0)
            {
                current = Open.dequeue();
                if (current == dest)
                {
                    path.Add(current);
                    return path;
                }
                Closed[closed_counter++] = current;
                for (int k = 0; k < current.neighbors.Count; k++) {
                    tempg = current.g + current.getTo(k);
                    if (isIn(Closed, current.neighbors[k]))
                    {
                        if (tempg >= current.neighbors[k].g)
                        {

                        }
                        else
                        {
                            //put camefrom to neighbor somehow. this following line is my attempt
                            path.Add(current.neighbors[k]);
                            current.neighbors[k].g = tempg;
                            current.neighbors[k].f = tempg + current.neighbors[k].H(dest);
                            if (!isIn(Open, current.neighbors[k]))
                            {
                                Open.add(current.neighbors[k]);
                            }
                        }
                    }
                    else
                    {
                        //put camefrom to neighbor somehow. this following line is my attempt
                        path.Add(current.neighbors[k]);
                        current.neighbors[k].g = tempg;
                        current.neighbors[k].f = tempg + current.neighbors[k].H(dest);
                        if (!isIn(Open, current.neighbors[k]))
                        {
                            Open.add(current.neighbors[k]);
                        }
                    }
                }
            }

            return path;
        }
示例#3
0
 public NodeGraph(Node[] map)
 {
     graph = map;
 }
示例#4
0
 public bool isIn(Node[] c, Node node)
 {
     for (int k = 0; k < c.Length; k++)
     {
         if (c[k] == node) return true;
     }
     return false;
 }
示例#5
0
 public bool isIn(JasonQ o, Node node)
 {
     for (int k = 0; k < o.Size(); k++)
     {
         if (o.get(k) == node) return true;
     }
     return false;
 }
示例#6
0
文件: Npc.cs 项目: kdetweiler/island
 public NPC(Vector2 newPosition, String newName, Node spawnNode)
 {
     position = newPosition;
     name = newName;
     sensor = new Sensor(300, 3);
     //rectangle = new Rectangle((int)position.X, (int)position.Y, texture.Width, texture.Height);
     rectangle = new Rectangle((int)position.X, (int)position.Y, 50, 50);
     location = spawnNode;
     health = 100;
     maxHealth = 100;
     strength = 10;
     defense = 5;
     isAlive = true;
     isHostile = false;
 }
示例#7
0
文件: Npc.cs 项目: kdetweiler/island
 public List<Node> nodeMove(NodeGraph nodegraph, Node desiredEnd)
 {
     List<Node> answer=nodegraph.AStar(location, desiredEnd);
     shortDest = answer[1];
     return answer;
 }
示例#8
0
文件: Npc.cs 项目: kdetweiler/island
        /*
        public void Load(ContentManager Content, Texture2D newTexture)
        {
            npcIdle = new Animation(newTexture, 32, 0.1f, true);

            animationPlayer.PlayAnimation(npcIdle);
        }*/
        public override void Update(GameTime gameTime)
        {
            if (shortDest.point.X == this.rectangle.X && shortDest.point.Y == this.rectangle.Y) {
                //A* shit goes here
                location = shortDest;
                //calculate using finalDest and the new location A* path

            }
        }
示例#9
0
文件: Npc.cs 项目: kdetweiler/island
        public NPC(Texture2D newTexture, Vector2 newPosition, String newName, Node spawnNode, Vector2 newAttackRange)
        {
            texture = newTexture;
            position = newPosition;
            name = newName;
            sensor = new Sensor(300, 3);
            rectangle = new Rectangle((int)position.X, (int)position.Y, texture.Width, texture.Height);
            location = spawnNode;
            health = 100;
            maxHealth = 100;
            strength = 10;
            defense = 5;
            isAlive = true;
            isHostile = false;

            attackRange = newAttackRange;
            withinRange = false;
        }
示例#10
0
文件: Node.cs 项目: kdetweiler/island
 public void testAdd(Node node)
 {
     neighbors.Add(node);
     distanceTo.Add(50);
 }
示例#11
0
文件: Node.cs 项目: kdetweiler/island
 public double H(Node dest)
 {
     return Math.Sqrt(Math.Pow((point.X - dest.point.X),2) - Math.Pow((point.Y - dest.point.Y),2));
 }
示例#12
0
文件: Node.cs 项目: kdetweiler/island
 public double G(Node dest)
 {
     return 0;
 }
示例#13
0
文件: Node.cs 项目: kdetweiler/island
 public void addNeighbor(Node node, double dist)
 {
     neighbors.Add(node);
     distanceTo.Add(dist);
 }