Example #1
0
		public TreeTraverser(TreeNode root, string endPointID, bool stayInZone = false) {
			_root = root;
			StayInZone = stayInZone;
			_visitedNodes = new Stack<TreeNode>();
			_unvisitedNodes = new Queue<TreeNode>();
			_unvisitedNodes.Enqueue(_root);
			EndPointID = endPointID;
		}
Example #2
0
		public FindPath(string startPoint, string endPoint) {
			IRoom room = Room.GetRoom(startPoint);
			IRoom endRoom = Room.GetRoom(endPoint);
			TreeNode rootNode = new TreeNode(room);
			rootNode.Parent = rootNode;
			_tree = new TreeTraverser(rootNode, endRoom.Id, room.Zone == endRoom.Zone);

            var result = GetPath();

            NextRoomInPath = result.Result[0];
        }
Example #3
0
        private void AddAdjacentRoomInDirection(TreeNode currentNode, IRoom room, RoomExits direction) {

            if (room.GetRoomExit(direction) != null) {
                if (currentNode.Parent != null && room.GetRoomExit(direction).availableExits[direction].Id != currentNode.Parent.ID) {
                    var newNode = new TreeNode(room.GetRoomExit(direction).availableExits[direction]);
                    if (!_unvisitedNodes.Contains(newNode)) {
                        if (!currentNode.AdjacentNodes.ContainsKey(direction.ToString())) {
                            currentNode.AdjacentNodes.Add(direction.ToString(), newNode);
                            currentNode.AdjacentNodes[direction.ToString()].Parent = currentNode;
                            AddNode(newNode);
                        }

                    }
                }
            }
        }
Example #4
0
		private void AddNode(TreeNode node) {
			if (node != null) {
				IRoom room = Room.GetRoom(node.ID);

				if (StayInZone && node.Zone != Root.Zone) {
					//Don't add it to the Queue it's out of bounds
				}
				else {
					if (!_visitedNodes.Any(n => n.ID == node.ID)) {
						_unvisitedNodes.Enqueue(node);
					}
				}
			}
		}
Example #5
0
        private void EnqueueAdjacentNodes(TreeNode currentNode) {
            IRoom room = Room.GetRoom(currentNode.ID);

            foreach (string direction in Enum.GetNames(typeof(RoomExits))) {
                if (direction != "None") {
                    AddAdjacentRoomInDirection(currentNode, room, (RoomExits)Enum.Parse(typeof(RoomExits), direction));
                }
            }
        }