コード例 #1
0
        private static List <GuestData> AddMyself(List <GuestData> data)
        {
            var guests = new List <GuestData>(data);

            var newGuest = new GuestData {
                Name = "me", happiness = new Dictionary <string, int>()
            };

            foreach (var guest in guests)
            {
                guest.happiness["me"]          = 0;
                newGuest.happiness[guest.Name] = 0;
            }
            guests.Add(newGuest);

            return(guests);
        }
コード例 #2
0
        private static List <GuestData> LoadData(string path)
        {
            var guests = new List <GuestData>();

            // Open the file to read from.
            using (StreamReader sr = File.OpenText(path))
            {
                string s = "";
                while ((s = sr.ReadLine()) != null)
                {
                    var line        = s.Split(' ');
                    var name        = line[0];
                    var newNeighbor = line[10].Remove(line[10].Count() - 1, 1);
                    int happiness   = int.Parse(line[3]);

                    if (line[2].Contains("lose"))
                    {
                        happiness = -happiness;
                    }

                    if (guests.Any(gs => gs.Name == name))
                    {
                        var guest = guests.First(gs => gs.Name == name);
                        guest.happiness[newNeighbor] = happiness;
                    }
                    else
                    {
                        var guest = new GuestData();
                        guest.happiness = new Dictionary <string, int>();
                        guest.Name      = name;
                        guest.happiness[newNeighbor] = happiness;
                        guests.Add(guest);
                    }
                }
            }

            return(guests);
        }