Esempio n. 1
0
 public Edge(Game game, Node startNode = null, Node endNode = null, int cost = 1)
 {
     m_startNode = new Node(game);
     m_startNode = startNode;
     m_endNode = new Node(game);
     m_endNode = endNode;
     m_cost = cost;
 }
Esempio n. 2
0
        public void AndrewBreadthFirst(Node start, Node target)
        {
            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < columns; j++)
                {
                    nodes[i, j].distance = Int32.MaxValue;
                    nodes[i, j].backPtr = null;
                }
            }

            Queue<Node> myQueue = new Queue<Node>();
      
            start.distance = 0;

            myQueue.Enqueue(start);

            while (myQueue.Count != 0)
            {

                currentNode = myQueue.Dequeue();
                currentNode.setColor(Color.Yellow);

                if (currentNode.iValue == target.iValue && currentNode.jValue == target.jValue)
                {
                    break;
                }

                currentNode.getEdges(this);
                while (currentNode.neighborStack.Count != 0)
                {
                    currentNeighbor = currentNode.neighborStack.Pop();
                    if (currentNeighbor.distance == Int32.MaxValue)
                    {
                        currentNeighbor.distance = currentNode.distance + 1;
                        currentNeighbor.backPtr = currentNode;
                        myQueue.Enqueue(currentNeighbor);
                        currentNeighbor.setColor(Color.Orange);
                    }
                }

            }


            while (currentNode != start)
            {
                currentNode.setColor(Color.Pink);
                currentNode = currentNode.backPtr;
            }
            start.setColor(Color.Red);
            target.setColor(Color.Green);


        }
Esempio n. 3
0
        public void initialize(GraphicsDeviceManager graphicsDM, int gridSize, Game myGame, SpriteBatch sb)
        {
            spriteBatch = sb;
            graphics = graphicsDM;
            cellSize = gridSize;
            game = myGame;
            rows = graphics.PreferredBackBufferWidth / cellSize;
            columns = graphics.PreferredBackBufferHeight / cellSize;
            nodes = new Node[rows, columns];
            nodeQueue = new Queue<Node>();

            for (int i = 0; i < rows; i++)
            {
                for (int j = 0; j < columns; j++)
                {
                    nodes[i, j] = new Node(game, i, j);
                    nodes[i, j].setIJvalue(i, j);
                    nodes[i, j].setLocation(i * gridSize, j * gridSize);
                    nodes[i, j].setSize(gridSize, gridSize);
                }
            }
        }