コード例 #1
0
 public Missionary(String fN, String n, int i, String z, Leg[] l, String[][] c, MissionaryManager mm)
 {
     fullName = fN;
     name = n;
     id = i;
     legs = l; // (Leg[])l.Clone();
     comps = c;
     //legs = null;
     legIndexs = null;
     manager = mm;
     zone = z;
 }
コード例 #2
0
        public Leg[] getLegs(String t)
        {
            Regex getLegsChunck = new Regex(@"\{?[\w.'][ \-'.\w]+\}?[ ]*(\[[\w\d]+\:[\w\d]+\])?[ ]*(?:\(['.\w ,\-]+\))?");

            // Uses the same Regex sub-strings to match the different parts in each match.
            Regex getCity = new Regex(@"{?[\w.'][ \-'.\w]+}?");
            Regex getTime = new Regex(@"(\[[\w\d]+\:[\w\d]+\])");
            Regex getComps = new Regex(@"(\(['.\w ,\-]+\))");

            String[] legsRaw = getLegsChunck.Matches(t).Cast<Match>().Select(m => m.Value).ToArray();

            List<Leg> legs = new List<Leg>();

            //List<String> legsL = new List<String>();
            //List<String[]> compsL = new List<String[]>();

            String travelDate = date;

            for (int z = 0; z < legsRaw.Length-1; z++)
            {
                string leg = legsRaw[z];
                string nextLeg = legsRaw[z+1];
                Leg cLeg;

                String city;
                bool sleepover = false;
                int arrival_deadline;
                String[] comps;

                // Retrieve info.

                city = getCity.Match(leg).ToString();

                // check for curly braces, so we know to set the sleepover flag, and removes them if present.
                if (city.IndexOf("{") >= 0)
                {
                    // We have them, we need to set the flag.
                    sleepover = true;

                    // Remove the braces from the city name.
                    city = city.Substring(1, city.Length - 2);
                    Console.WriteLine("We stripped a city down to:");
                }

                String time_temp = getTime.Match(leg).ToString();
                if (time_temp.Equals(""))
                {
                    arrival_deadline = -1;
                }
                else
                {
                    arrival_deadline = FUNCS.timeStringToMinutes(time_temp.Substring(1, time_temp.Length - 2));
                }

                String comps_temp = getComps.Match(leg).ToString();
                if (comps_temp.Equals(""))
                {
                    comps = new String[0];
                }
                else
                {
                    comps = comps_temp.Substring(1, comps_temp.Length - 2).Split(new char[] { ',' });
                    for (int i = 0; i < comps.Length; i++)
                    {
                        comps[i] = comps[i].Trim();
                    }
                }

                // if we're sleeping over at this leg... that means we need to move all of our previous dates backwards one!
                // We also set the going_to_sleepover flag, so that the optimizer knows that we need to travel at night.
                // (Not real effective, but it'll do.)
                if (sleepover)
                {
                    for (int b = 0; b < z; b++)
                    {
                        legs[b].date = FUNCS.addDaysToDateString(legs[b].date, -1);
                        legs[b].going_to_sleepover = true;

                    }

                    // From back when I thought I should just it forward and keep going... except then you're LATE for things, duh! :D
                    //travelDate = FUNCS.addDaysToDateString(travelDate, 1);

                }

                // Create the leg and push it to the list.
                String validStation = tm.validateStation(city);
                cLeg = new Leg(travelDate, comps, validStation, "", false); // leave the arrival/sleepover blank/false, we'll add it when we read it.
                legs.Add(cLeg);
                if (z > 0){
                    legs[z-1].arrive = validStation;
                    legs[z-1].going_to_sleepover = sleepover;
                    legs[z - 1].comps = comps;
                }
            }

            // we still need to look at the last thing.
            String lastCity = getCity.Match(legsRaw[legsRaw.Length - 1]).ToString();
            bool lastSleepover = false;

            // check for curly braces, so we know to set the sleepover flag, and removes them if present.
            if (lastCity.IndexOf("{") >= 0)
            {
                // We have them, we need to set the flag.
                lastSleepover = true;

                // Remove the braces from the city name.
                lastCity = lastCity.Substring(1, lastCity.Length - 2);
                Console.WriteLine("We stripped a city down to:");
            }

            String comps_temp2 = getComps.Match(legsRaw[legsRaw.Length -1]).ToString();
            String[] comps2;
            if (comps_temp2.Equals(""))
            {
                comps2 = new String[0];
            }
            else
            {
                comps2 = comps_temp2.Substring(1, comps_temp2.Length - 2).Split(new char[] { ',' });
                for (int i = 0; i < comps2.Length; i++)
                {
                    comps2[i] = comps2[i].Trim();
                }
            }

            // add what we just found.
            legs[legs.Count - 1].going_to_sleepover = lastSleepover;
            legs[legs.Count - 1].arrive = tm.validateStation(lastCity.Trim());
            legs[legs.Count - 1].comps = comps2;

            return legs.ToArray();
        }
コード例 #3
0
 public Missionary(String fN, String n, int i, String z, Leg[] l, String[][] c, Leg[] p, int[] lI, MissionaryManager mm)
 {
     fullName = fN;
     name = n;
     id = i;
     legs = l;
     comps = c;
     legs = p;
     legIndexs = lI;
     manager = mm;
     zone = z;
 }
コード例 #4
0
 public bool addMissionary(String fN, String n, int i, String z, Leg[] l, String[][] c)
 {
     try
     {
         missionaries.Add(new Missionary(fN, n, i, z, l, c, this));
     }
     catch (Exception)
     {
         return false;
     }
        return true;
 }