Ejemplo n.º 1
0
        public static string AddDays(string timecode, int days)
        {
            //List<string> splits = timecode.Split(seperators).ToList<string>();

            GTime newtime = new GTime(timecode);

            //int newdays = Convert.ToInt32(splits[2]);

            newtime.Day += days;

            while (!CheckForValidDate(newtime))
            {
                if (newtime.Day > 30)
                {
                    newtime.Month += 1;

                    newtime.Day -= 30;
                }

                if (newtime.Month > 12)
                {
                    newtime.Year += 1;

                    newtime.Month -= 12;
                }
            }

            return(newtime.ToString());
        }
Ejemplo n.º 2
0
        public Character(Database db, DNA dna, GTime time, int id) : this(db)
        {
            List <Gene> genes = dna.Genes;
            this.CID       = id;
            this.BirthTime = time;
            this.Dead      = false;
            this.DueDate   = new GTime(true);
            this.IsSingle  = true;
            this.Dna       = dna;

            // Gene Pair 1
            int gone = genes[0].ToInt() % 2;
            int gtwo = genes[1].ToInt() % 2;

            if (gone + gtwo == 1)
            {
                this.Gender = true;
            }

            else if (gone + gtwo == 0)
            {
                this.Gender = false;
            }

            else
            {
                Console.WriteLine("{0} has two y chromosomes", id);
            }

            this.Fname = NDB.GenFname(this.Gender);

            this.Lname = NDB.GenLname();
        }
Ejemplo n.º 3
0
        /*public void Death()
         * {
         *
         *  int maxcharsdie = Convert.ToInt32(Math.Floor(this.CDB.GetNumberOfAliveCharacters() * MAXDEATHPERC));
         *
         *  int numtodie = rngesus.Next(0, maxcharsdie);
         *
         *  List<int> ids = new List<int>();
         *
         *  for (int i = 0; i < numtodie; i++)
         *  {
         *
         *      ids.Add(rngesus.Next(0, this.TotalCharacters-1));
         *
         *  }
         *
         *  foreach(int i in ids)
         *  {
         *
         *      int unlucky = rngesus.Next(1,100);
         *
         *      if (rngesus.Next(1,100) == unlucky)
         *      {
         *
         *          Character chara = new Character(this.CDB, i);
         *
         *          if (!chara.Dead)
         *          {
         *
         *              Console.WriteLine("{0}: {1} has died", this.Time.ToString(), chara.Fname);
         *              chara.Dead = true;
         *              this.CDB.SaveCharacter(chara);
         *
         *          }
         *
         *      }
         *
         *  }
         *
         * } */

        public void GetPregnant(string timecode, List <Character> chars)
        {
            if (ContainsWomen(chars))
            {
                for (int i = 0; i < chars.Count; i++)
                {
                    if (!chars[i].Gender && !chars[i].IsPregnent())
                    {
                        if (this.FamTree.HasSpouse(chars[i]))
                        {
                            Character spouse = this.CDB.GetCharacter(this.FamTree.GetSpouse(chars[i]));

                            if (!spouse.Dead)
                            {
                                string duecode = GTime.AddDays(timecode, rngesus.Next(270, 281));

                                chars[i].DueDate = new GTime(duecode);

                                Console.WriteLine("{0}: {1} and {2} are pregnant, due date is {3}", this.Time.ToString(), spouse.Fname, chars[i].Fname, chars[i].DueDate.ToString());
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public GTime AddDays(GTime time, int days)
        {
            GTime newtime = time;

            newtime.Day += days;

            while (!CheckForValidDate(newtime))
            {
                if (Day >= 30)
                {
                    newtime.Month += 1;

                    newtime.Day -= 30;
                }

                if (Month >= 12)
                {
                    newtime.Year += 1;

                    newtime.Month -= 12;
                }
            }

            return(newtime);
        }
Ejemplo n.º 5
0
        public GTime FutureDateDays(int days)
        {
            GTime newtime = this;

            for (int i = 0; i < days * 1440; i++)
            {
                newtime = newtime++;
            }

            return(newtime);
        }
Ejemplo n.º 6
0
        public static GTime operator -(GTime gt1, GTime gt2)
        {
            GTime newtime = new GTime();

            newtime.Year   = gt1.Year - gt2.Year;
            newtime.Month  = gt1.Month - gt2.Month;
            newtime.Day    = gt1.Day - gt2.Day;
            newtime.Hour   = gt1.Hour - gt2.Hour;
            newtime.Minute = gt1.Minute - gt2.Minute;

            return(newtime);
        }
Ejemplo n.º 7
0
        public List <Character> FillListWithViableCharacters(GTime time)
        {
            List <int> ids = this.FamTree.GetListOfSingleCharacters(NumOfRowsInTable());

            string query = string.Format("SELECT * FROM CharacterDb WHERE Dead = 0 AND ({0} - BirthTime) / 10000 >= 18 AND (", time.ToDouble());

            query += "IsSingle = 1 OR ";

            query += string.Format("DueDate = {0} OR (DueDate < 0 AND Gender = 0))", time.ToDouble());

            List <Character> chars = new List <Character>();

            chars = Query(query);

            return(chars);
        }
Ejemplo n.º 8
0
        public static GTime IncrementByDays(GTime time)
        {
            time.Day++;

            if (time.Day > 30)
            {
                time.Day = 1;

                time.Month++;
            }

            if (time.Month > 12)
            {
                time.Month = 1;

                time.Year++;
            }

            return(time);
        }
Ejemplo n.º 9
0
        public static bool CheckForValidDate(GTime time)
        {
            if (time.Minute > 59 || time.Minute < 0)
            {
                return(false);
            }

            if (time.Hour > 23 || time.Hour < 0)
            {
                return(false);
            }

            if (time.Day > 30 || time.Day < 0)
            {
                return(false);
            }

            if (time.Month > 12 || time.Month < 0)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 10
0
        public static void CharMenu(Database db)
        {

            int choice;

            CharacterDB cdb = new CharacterDB(db);

            //Console.Clear();
            Console.WriteLine("Welcome to the character builder");
            Console.WriteLine("");
            Console.WriteLine("1. Generate Character by DNA");
            Console.WriteLine("2. Generate Child from Parent DNA.");
            Console.WriteLine("3. Generate random character from gender.");
            Console.WriteLine("4. Generate child from random parents.");
            Console.WriteLine("5. Generate Random Parents and then Child");
            Console.WriteLine("6. Show all races and mods");
            Console.WriteLine("7. Run Life Sim");
            Console.WriteLine("8. Fill DB with Characters");
            Console.WriteLine("9. Test EmptyDB");
            Console.WriteLine("10. Create CSV files");
            Console.WriteLine("11. Exit");
            Console.Write("Please enter your choice: ");
            choice = Convert.ToInt32(Console.ReadLine());
            Console.Clear();

            if (choice == 1)
            {

                string cdna;

                Console.WriteLine("");

                Console.Write("Please enter the DNA string: ");

                cdna = Console.ReadLine();

                DNA dna = new DNA(cdna);

                Character chara = new Character(db,dna,new GTime(),0);

                Console.WriteLine(chara.ToString());

                Console.ReadKey();

                CharMenu(db);


            }

            else if (choice == 2)
            {

                Console.WriteLine("");

                //Console.Write("Please enter the number of generations: ");

                //int choice2 = Convert.ToInt32(Console.ReadLine());

                Console.Write("Enter Dad Dna: ");
                string cddna = Console.ReadLine();

                Console.Write("Enter Mom DNA: ");
                string cmdna = Console.ReadLine();

                Character dad = new Character(db,new DNA(cddna),new GTime(),0);
                Character mom = new Character(db,new DNA(cmdna),new GTime(),1);

                Console.WriteLine("\n" + dad.ToString());
                Console.WriteLine("\n" + mom.ToString());

                Character child = new Character(db,dad,mom,new GTime(),2);

                Console.WriteLine("\n" + child.ToString());

                Console.WriteLine(child.Dna.ToString());

                Console.ReadKey();

                CharMenu(db);

            }

            else if (choice == 3)
            {

                Console.Write("Please enter a gender: ");
                string gen = Console.ReadLine();
                bool gender;

                List<char> input = gen.ToList<char>();

                if (input[0] == 'm' || input[0] == 'M')
                {

                    gender = true;

                }

                else
                {

                    gender = false;

                }

                Character a = new Character(db,new DNA(gender),new GTime(),0);

                Console.WriteLine("\n" + a.ToString());

                Console.ReadKey();
                CharMenu(db);

            }

            else if (choice == 4)
            {

                bool end = false;

                int numchars = 0;

                //Console.WriteLine("Generating Dad...");
                Character dad = new Character(db,new DNA(true),new GTime(),numchars);
                numchars++;

                //Console.WriteLine("\nGenerating Mom...");
                Character mom = new Character(db,new DNA(false),new GTime(),numchars);
                numchars++;

                while(!end)
                {

                    Console.WriteLine("\nDad:\n" + dad.ToString());
                    Console.WriteLine("\nMom:\n" + mom.ToString());

                    Console.WriteLine("\nCreating Child");
                    Character child = new Character(db,new DNA(dad.Dna.Miosis(), mom.Dna.Miosis()),new GTime(), numchars);
                    numchars++;
                    Console.WriteLine("\n" + child.ToString());

                    Console.Write("\nend? (y/n): ");
                    string chc = Console.ReadLine();

                    if (chc.Contains('y') || chc.Contains('Y'))
                    {

                        end = true;

                    }

                    else
                    {

                        Console.Clear();

                    }

                }

                CharMenu(db);

            }

            else if (choice == 5)
            {

                bool end = false;
                int numchars = 0;

                while (!end)
                {

                    Character dad = new Character(db,new DNA(true), new GTime(),numchars);
                    numchars++;
                    Console.WriteLine("\nDad:\n" + dad.ToString());
                    Character mom = new Character(db,new DNA(false),new GTime(),numchars);
                    numchars++;
                    Console.WriteLine("\nMom:\n" + mom.ToString());

                    Console.WriteLine("\nCreating Child");
                    Character child = new Character(db,new DNA(dad.Dna.Miosis(), mom.Dna.Miosis()),new GTime(),numchars);
                    numchars++;
                    Console.WriteLine("\n" + child.ToString());

                    Console.Write("\nend? (y/n): ");
                    string chc = Console.ReadLine();

                    if (chc.Contains('y') || chc.Contains('Y'))
                    {

                        end = true;

                    }

                    else
                    {

                        Console.Clear();

                    }

                }

                CharMenu(db);

            }

            else if (choice == 6)
            {

                Console.WriteLine("");

                Race r = new Race(db);

                List<Race> races = r.GetAllRaces();

                foreach (Race ra in races)
                {

                    Console.WriteLine(ra.ToString());

                }

                Console.ReadKey();
                CharMenu(db);

            }

            else if (choice == 7)
            {

                Console.Write("Please enter a starting population: ");
                int startpop = Convert.ToInt32(Console.ReadLine());

                Console.Write("Please enter the max years: ");
                int maxyears = Convert.ToInt32(Console.ReadLine());

                LifeSimulator sim = new LifeSimulator(db,startpop, maxyears);

                Console.ReadKey();
                CharMenu(db);

            }

            else if (choice == 8)
            {

                Console.Write("Enter the number of characters to genereate: ");
                int numchars = Convert.ToInt32(Console.ReadLine());

                List<Character> chars = new List<Character>();

                GTime time = new GTime();

                for (int i = 0; i < numchars; i++)
                {

                    Character chara = new Character(db,new DNA(),time,i);

                    chars.Add(chara);

                }

                cdb.SaveListOfCharacters(chars);

                CharMenu(db);

            }

            else if(choice == 9)
            {

                List<Character> chars = new List<Character>();

                chars.AddRange(cdb.GetAllCharacters());

                Console.WriteLine(chars);

                Console.ReadKey();

            }

            else if (choice == 10)
            {

                NameDB nm = new NameDB(db);
                //nm.NumberedFile();
                CharMenu(db);

            }

            else if (choice == 11)
            {

                Console.WriteLine("Exiting....");
                Console.ReadKey();

            }

            else
            {

                Console.WriteLine("Please enter a valid choice");
                Console.ReadKey();

                CharMenu(db);

            }

        }
Ejemplo n.º 11
0
 public Event(GTime time) : this(time, "")
 {
 }
Ejemplo n.º 12
0
 public Event(GTime time, string evntxt)
 {
     this.Time      = time;
     this.EventText = evntxt;
 }
Ejemplo n.º 13
0
 public Character(Database db, Character dad, Character mom, GTime time, int id) : this(db, new DNA(dad.Dna.Miosis(), mom.Dna.Miosis()), time, id)
 {
     this.Fname = NDB.GenFname(this.Gender);
     this.Lname = dad.Lname;
 }
Ejemplo n.º 14
0
        public LifeSimulator(Database db, int startpop, int maxyears) : this(db)
        {
            this.Time = new GTime();

            List <Character> characters = new List <Character>();

            for (int i = 0; i < startpop; i++)
            {
                if (i % 2 == 0)
                {
                    Character chara = new Character(db, new DNA(false), Time, TotalCharacters);
                    TotalCharacters++;
                    characters.Add(chara);
                    Console.WriteLine("{0}: {1},{2} was created.", this.Time.ToString(), chara.Fname, chara.Gender);
                }

                else
                {
                    Character chara = new Character(db, new DNA(true), Time, TotalCharacters);
                    TotalCharacters++;
                    characters.Add(chara);
                    Console.WriteLine("{0}: {1},{2} was created.", this.Time.ToString(), chara.Fname, chara.Gender);
                }
            }

            this.CDB.SaveListOfCharacters(characters);

            characters.Clear();

            this.Time = AGE18;

            int tempyear = 18;

            do
            {
                //Console.WriteLine(this.Time.ToString() + " New Day");

                if (this.Time.Year > tempyear)
                {
                    ShowStats();

                    Console.WriteLine(this.Time.ToString() + " New Year!");

                    tempyear = this.Time.Year;
                }

                characters.AddRange(this.CDB.FillListWithViableCharacters(this.Time));

                if (!OnlyOneGenderAndSingle(characters))
                {
                    Marriage(characters);

                    GetPregnant(this.Time.ToString(), characters);

                    HaveChild(characters);
                }

                //Death();

                this.Time = GTime.IncrementByDays(this.Time);

                //this.Time = this.Time++;

                //CleanLists();

                this.CDB.SaveListOfCharacters(characters);

                characters.Clear();
            } while (this.Time.Year != maxyears + 1 && !AllDead(characters));

            Console.WriteLine("{0} characters have been created", this.TotalCharacters);
        }