private Point CalculateNextStep(Node guide)
 {
     while (guide.Last.Last != null)
     {
         guide = guide.Last;
     }
     return guide.Value;
 }
Ejemplo n.º 2
0
 private Point FindNextStep(Node firstNode,Node secondNode)
 {
     Point result = new Point();
     var queue = new Queue<Node>();
     queue.Enqueue(firstNode);
     Node nodeInGraph = new Node(new Point());
     while (queue.Count > 0)
     {
         nodeInGraph = queue.Dequeue();
         nodeInGraph.Color = 2;
         if ((nodeInGraph.Top != null) && (nodeInGraph.Top.Color == 0) )
         {
             nodeInGraph.Top.Color = 1;
             nodeInGraph.Top.Last = nodeInGraph;
             queue.Enqueue(nodeInGraph.Top);
             if (nodeInGraph.Top.Value == secondNode.Value)
             {
                 result = CalculateNextStep(nodeInGraph.Top);
                 break;
             }
         }
         if ((nodeInGraph.Down != null) && (nodeInGraph.Down.Color == 0) )
         {
             nodeInGraph.Down.Color = 1;
             nodeInGraph.Down.Last = nodeInGraph;
             queue.Enqueue(nodeInGraph.Down);
             if (nodeInGraph.Down.Value == secondNode.Value)
             {
                 result = CalculateNextStep(nodeInGraph.Down);
                 break;
             }
         }
         if ((nodeInGraph.Left != null) && (nodeInGraph.Left.Color == 0))
         {
             nodeInGraph.Left.Color = 1;
             nodeInGraph.Left.Last = nodeInGraph;
             queue.Enqueue(nodeInGraph.Left);
             if (nodeInGraph.Left.Value == secondNode.Value)
             {
                 result = CalculateNextStep(nodeInGraph.Left);
                 break;
             }
         }
         if ((nodeInGraph.Right != null) && (nodeInGraph.Right.Color == 0))
         {
             nodeInGraph.Right.Color = 1;
             nodeInGraph.Right.Last = nodeInGraph;
             queue.Enqueue(nodeInGraph.Right);
             if (nodeInGraph.Right.Value == secondNode.Value)
             {
                 result = CalculateNextStep(nodeInGraph.Right);
                 break;
             }
         }
     }
     return result;
 }
Ejemplo n.º 3
0
 private Point CalculateNextStep(Node guide)
 {
     Point result = new Point(0,0);
     Node temp = new Node(new Point());
     while (temp.Last.Last != null)
     {
         temp = temp.Last;
     }
     result = temp.Value;
     return result;
 }
 private Point AddNewNodeInQueue(Node node, Point result)
 {
     if ((node != null) && (node.isFound == false))
     {
         node.isFound = true;
         node.Last = _nodeInGraph;
         _queueForBFS.Enqueue(node);
         if (node.Value == _pacManCoordinate)
         {
             result = CalculateNextStep(node);
         }
     }
     return result;
 }
Ejemplo n.º 5
0
 private List<Node> CreateGraph()
 {
     var result = new List<Node>();
     foreach (Point point in _vertexCoordinates)
     {
         Point _newVertex = point;
         var _newNode = new Node(_newVertex);
         _newNode.Down = GetNeighbor(_newVertex, new Point(0, 50));
         _newNode.Top = GetNeighbor(_newVertex, new Point(0, -50));
         _newNode.Left = GetNeighbor(_newVertex, new Point(-50, 0));
         _newNode.Right = GetNeighbor(_newVertex, new Point(50, 0));
         result.Add(_newNode);
     }
     return result;
 }
Ejemplo n.º 6
0
 public Node(Point value)
 {
     this.Value = value;
     this.Color = 0;
     this.Last = null;
     this.Left = null;
     this.Right = null;
     this.Top = null;
     this.Down = null;
 }
Ejemplo n.º 7
0
 private Node SearchNode(Point node)
 {
     Node result=new Node(node);
     foreach (Node possibleNode in _graph)
     {
         if (possibleNode.Value == node)
             result= possibleNode;
     }
     return result;
 }
 private Point FindNextStep(Node enemyNode)
 {
     Point result = enemyNode.Value;
     _queueForBFS = new Queue<Node>();
     _queueForBFS.Enqueue(enemyNode);
     enemyNode.isFound = true;
     while (_queueForBFS.Count > 0 && result == enemyNode.Value)
     {
         _nodeInGraph = _queueForBFS.Dequeue();
         result = AddNewNodeInQueue(_nodeInGraph.Top, result);
         result = AddNewNodeInQueue(_nodeInGraph.Down, result);
         result = AddNewNodeInQueue(_nodeInGraph.Left, result);
         result = AddNewNodeInQueue(_nodeInGraph.Right, result);
     }
     return result;
 }
 private Node GetNeighbor(Point offset,Node currentNode)
 {
     foreach (Node node in _graph)
     {
         if (currentNode.Value == new Point(node.Value.X - offset.X, node.Value.Y - offset.Y))
             return node;
     }
     return null;
 }