예제 #1
0
        /// <summary>
        /// Find destination
        /// </summary>
        /// <param name="typeMoveEvent"></param>
        /// <returns></returns>
        public List <LocationType> SearchFacility(HotelEventType typeMoveEvent)
        {
            // where we add the facilities where visitor wants to go to
            List <LocationType> amountFacilities = new List <LocationType>();

            // Reurn based on the event a instance
            foreach (var item in PathFinding.facilities)
            {
                // switch based on events
                switch (typeMoveEvent)
                {
                // return a lobby
                case HotelEventType.CHECK_OUT:
                case HotelEventType.CHECK_IN:
                case HotelEventType.EVACUATE:
                    if (item is Lobby)
                    {
                        amountFacilities.Add(item);
                    }
                    break;

                // return the fitness-halls
                case HotelEventType.GOTO_FITNESS:
                    if (item is Fitness)
                    {
                        amountFacilities.Add(item);
                    }
                    break;

                // return the cinemas
                case HotelEventType.GOTO_CINEMA:
                case HotelEventType.START_CINEMA:
                    if (item is Cinema)
                    {
                        amountFacilities.Add(item);
                    }
                    break;

                // return the restaurants
                case HotelEventType.NEED_FOOD:
                    if (item is Restaurant)
                    {
                        amountFacilities.Add(item);
                    }
                    break;

                default:
                    break;
                }
            }
            // return list
            return(amountFacilities);
        }
예제 #2
0
        /// <summary>
        /// Start the build up for the clean up event right after the check out event.
        /// </summary>
        /// <param name="room">What room needs to be cleaned.</param>
        /// <param name="hotelEventType">Wanna know if it is a normal clean job or an emergency.</param>
        private void StartClean(IRoom room, HotelEventType hotelEventType)
        {
            IRoom currentRoom = room;
            bool  maidFound   = false;

            foreach (IPerson work in people.Keys)
            {
                if (work.id.Contains("Maid"))
                {
                    List <Maid> maids = new List <Maid>(); //List of all the maids.
                    foreach (IPerson person in people.Keys)
                    {
                        if (person.id.Contains("Maid"))//add all the maids
                        {
                            maids.Add((Maid)person);
                        }
                    }

                    foreach (Maid worker in maids)
                    {
                        Maid currentMaid = (Maid)worker; //What maid we are on.
                        if (worker.busy == false && currentRoom.roomIsGettingCleaned == false)
                        {
                            //Gives the maid the room we are on.
                            worker.busy = true;
                            worker.room = currentRoom;
                            currentRoom.roomIsGettingCleaned = true;

                            //Find path
                            IRoom end = currentRoom;
                            try
                            {
                                if (hotelEventType == HotelEventType.CLEANING_EMERGENCY)
                                {
                                    IRoom start = coordinates[currentMaid.eventQueue.LastOrDefault().Last().position.X, currentMaid.eventQueue.LastOrDefault().Last().position.Y];
                                    end.danger = true;
                                    FindPath(start, end, currentMaid);
                                }
                                else
                                {
                                    IRoom start = coordinates[currentMaid.eventQueue.LastOrDefault().Last().position.X, currentMaid.eventQueue.LastOrDefault().Last().position.Y];
                                    FindPath(start, end, currentMaid); //Add path to room which needs to be cleaned.
                                }
                            }
                            catch
                            {
                                if (hotelEventType == HotelEventType.CLEANING_EMERGENCY)
                                {
                                    IRoom start = currentMaid.currentRoom;
                                    end.danger = true;
                                    FindPath(start, end, currentMaid);
                                }
                                else
                                {
                                    IRoom start = currentMaid.currentRoom;
                                    FindPath(start, end, currentMaid); //Add path to room which needs to be cleaned.
                                }
                            }
                            maidFound = true;
                        }
                    }
                    if (maidFound == false)
                    {
                        Dictionary <Maid, List <IRoom> > paths = new Dictionary <Maid, List <IRoom> >();
                        for (int i = 0; i < maids.Count; i++)
                        {
                            try
                            {
                                List <IRoom> path = dijkstra.Run(maids[i].currentRoom, currentRoom, maids[i]);
                                paths.Add(maids[i], path);
                            }
                            catch
                            {
                                int          posX = maids[i].eventQueue.Last().Last().position.X;
                                int          posY = maids[i].eventQueue.Last().Last().position.Y;
                                List <IRoom> path = dijkstra.Run(coordinates[posX, posY], currentRoom, maids[i]);
                                paths.Add(maids[i], path); //Saves all the paths to the final destination.
                            }
                        }
                        List <IRoom> shortestPath = paths.Values.FirstOrDefault();

                        //Gets last element from the list aka the shortest path
                        foreach (var path in paths)
                        {
                            if (path.Value.LastOrDefault().distance < shortestPath.LastOrDefault().distance)
                            {
                                shortestPath = path.Value;
                            }
                            //checks wich maid this short path belongs too.
                            var query2 = from element in paths
                                         where element.Value == shortestPath
                                         select element.Key.id;

                            foreach (string whichMaid in query2)
                            {
                                if (path.Key.id == whichMaid)
                                {
                                    Maid currentMaid = (Maid)path.Key;
                                    currentMaid.busy = true;
                                    currentRoom.roomIsGettingCleaned = true;
                                    IRoom end = path.Value.Last();
                                    try
                                    {
                                        IRoom start = coordinates[currentMaid.eventQueue.LastOrDefault().Last().position.X, currentMaid.eventQueue.LastOrDefault().Last().position.Y];
                                        FindPath(start, end, path.Key);
                                    }
                                    catch
                                    {
                                        IRoom start = currentMaid.currentRoom;

                                        FindPath(start, end, path.Key);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }