static bool ParseDynasty(StringReader i_sr, Dynasty i_dynasty)
        {
            Reader.ReadSpaces(i_sr);
            if (!Reader.ReadAToken(i_sr, '{'))
            {
                Debug.Assert(false, "A token '{' expected");
                return false;
            }
            Reader.ReadSpaces(i_sr);
            while (i_sr.Peek() != '}')
            {
                Reader.ReadSpaces(i_sr);
                string key;
                if (!Reader.ReadAKey(i_sr, out key))
                {
                    Debug.Assert(false, "A key expected");
                    return false;
                }

                Reader.ReadSpaces(i_sr);
                if (!Reader.ReadAToken(i_sr, '='))
                {
                    Debug.Assert(false, "A token '=' expected");
                    return false;
                }
                Reader.ReadSpaces(i_sr);
                if (key == name)
                {
                    string strname;
                    if (!Reader.ReadAString(i_sr, out strname))
                    {
                        Debug.Assert(false, "A string expected");
                    }
                    i_dynasty.name = strname;
                }
                else if (key == culture)
                {
                    string strculture;
                    if (!Reader.ReadAKey(i_sr, out strculture))
                    {
                        Debug.Assert(false, "A string expected");
                    }
                    i_dynasty.culture = strculture;
                }
                else
                {
                    Reader.ReadValue(i_sr);
                }
                Reader.ReadSpaces(i_sr);

            }
            if (!Reader.ReadAToken(i_sr, '}'))
            {
                Debug.Assert(false, "A token '}' expected");
                return false;
            }
            return true;
        }
 public static Person GenPerson(Dynasty i_dynasty, Person i_father, DateTime i_beginDateTime, DateTime i_endDateTime)
 {
     Person person = new Person();
     if (i_beginDateTime > taoToConfucian)
     {
         person.religion = confucian;
     }
     else
     {
         person.religion = tao;
     }
     person.father = i_father;
     person.name = new Name();
     person.name.first = Name.RandomName();
     DateTime born = new DateTime(Rnd.rnd.Next(i_beginDateTime.Year -maxElectedAge, i_beginDateTime.Year - minElectedAge + 1), Rnd.rnd.Next(1, 13), Rnd.rnd.Next(1, 29));
     if (i_father != null)
     {
         DateTime fatherBorn = i_father.born;
         DateTime minBornTime = i_father.born.AddYears(adultYear);
         if (minBornTime > born)
         {
             born = new DateTime(Rnd.rnd.Next(minBornTime.Year + 1, minBornTime.Year + 1 + 5), Rnd.rnd.Next(1, 13), Rnd.rnd.Next(1, 29));
             born = new DateTime(Math.Min(born.Ticks, i_father.die.AddDays(-1).Ticks));
             born = new DateTime(Math.Min(born.Ticks, i_beginDateTime.AddYears(-16).Ticks));
         }
         i_father.children.Add(person);
     }
     DateTime maxTime = born.AddYears(maxDeathTime);
     DateTime die = new DateTime(Rnd.rnd.Next(i_endDateTime.Year, maxTime.Year + 1), Rnd.rnd.Next(1, 13), Rnd.rnd.Next(1, 29));
     die = new DateTime(Math.Max(die.Ticks, i_endDateTime.AddDays(1).Ticks));
     Debug.Assert(i_father == null || born < i_father.die);
     Debug.Assert(born.AddYears(adultYear) <= i_beginDateTime);
     Debug.Assert(die >= i_endDateTime);
     person.born = born;
     person.die = die;
     if (Rnd.rnd.Next(0, 4) == 0)
     {
         person.name.middle = "";
     }
     else
     {
         person.name.middle = Name.RandomName();
     }
     person.name.dynasty = i_dynasty;
     person.id = personIdBase + personNum;
     China.people.Add(person);
     personNum++;
     return person;
 }
 static bool ParseDynastyFile(string i_content)
 {
     using (StringReader sr = new StringReader(i_content))
     {
         while (sr.Peek() != -1)
         {
             Reader.ReadSpaces(sr);
             string key;
             if (!Reader.ReadAKey(sr, out key))
             {
                 Debug.Assert(false, "A key expected");
                 return false;
             }
             Reader.ReadSpaces(sr);
             if (!Reader.ReadAToken(sr, '='))
             {
                 Debug.Assert(false, "A token '=' expected");
                 return false;
             }
             Reader.ReadSpaces(sr);
             int id = Int32.Parse(key);
             Dynasty dynasty = new Dynasty();
             dynasty.id = id;
             ParseDynasty(sr, dynasty);
             if (dynasty.culture == han)
             {
                 China.dynasties.Add(dynasty);
             }
             Reader.ReadSpaces(sr);
         }
     }
     return true;
 }
 public static Dynasty GenDynasty()
 {
     int lenDyn = China.dynasties.Count();
     int index = dynastyNum % lenDyn;
     Dynasty dynasty = new Dynasty();
     dynasty.name = China.dynasties[index].name;
     dynasty.id = dynastyIdBase + dynastyNum;
     dynasty.culture = han;
     China.dynasties.Add(dynasty);
     return dynasty;
 }