Пример #1
0
        public void AddStreet()
        {
            if (!CheckLocation(openStreetToAdd.FirstCorner) || !CheckLocation(openStreetToAdd.SecondCorner))
            {
                IsLocationNotValid = true;
                return;
            }

            IsLocationNotValid = false;
            OpenStreetList.Add(OpenStreetToAdd);
            OpenStreetToAdd = new OpenStreet();
        }
Пример #2
0
        private List <string> getRouteList()
        {
            List <string>      retList         = new List <string>();
            List <List <int> > positionsList   = new List <List <int> >();
            List <int>         positions       = new List <int>();
            List <int>         openStreetsUsed = new List <int>();

            positions.Add(FIRESTATION_LOCATION);
            getNextPosition(FIRESTATION_LOCATION, 0);

            void getNextPosition(int lastPosition, int lastStreetUsed)
            {
                for (int i = lastStreetUsed; i < openStreetList.Count; i++)
                {
                    OpenStreet curStreet = openStreetList.ElementAt(i);

                    if (curStreet.FirstCorner == lastPosition && !positions.Contains(curStreet.SecondCorner))
                    {
                        if (!checkFireCorner(curStreet.SecondCorner, i))
                        {
                            return;
                        }
                    }
                    else if (curStreet.SecondCorner == lastPosition && !positions.Contains(curStreet.FirstCorner))
                    {
                        if (!checkFireCorner(curStreet.FirstCorner, i))
                        {
                            return;
                        }
                    }
                }

                positions.Remove(positions.Last());
                if (positions.Count == 0)
                {
                    return;
                }

                int lastStreet = openStreetsUsed.Last();

                openStreetsUsed.Remove(lastStreet);
                getNextPosition(positions.Last(), lastStreet + 1);
            }

            bool checkFireCorner(int corner, int index)
            {
                positions.Add(corner);

                if (corner != FireToAdd.Location)
                {
                    openStreetsUsed.Add(index);
                    getNextPosition(positions.Last(), 0);
                    return(false);
                }
                else
                {
                    List <int> auxPos = new List <int>(positions);
                    positionsList.Add(auxPos);
                    positions.Remove(corner);
                    return(true);
                }
            }

            // Convert int List to string
            foreach (List <int> posList in positionsList)
            {
                string positionString = "";

                foreach (int pos in posList)
                {
                    positionString += $"{pos} ";

                    if (pos != posList.Last())
                    {
                        positionString += " - ";
                    }
                }
                retList.Add(positionString);
            }

            return(retList);
        }