예제 #1
0
파일: TreeNode.cs 프로젝트: jandar78/Novus
		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;
		}
예제 #2
0
파일: States.cs 프로젝트: jandar78/Novus
		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];
        }
예제 #3
0
파일: TreeNode.cs 프로젝트: jandar78/Novus
        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);
                        }

                    }
                }
            }
        }
예제 #4
0
파일: TreeNode.cs 프로젝트: jandar78/Novus
		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);
					}
				}
			}
		}
예제 #5
0
파일: TreeNode.cs 프로젝트: jandar78/Novus
        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));
                }
            }
        }