public void StartFamilySearchConnection() { _courtHouse = new CourtHouse(); txtOutput.Text = "Signing in."; if (_fhs.initializeConnection()) { txtOutput.Text = "Collecting Results. This may take several minutes. Please wait..."; _courtHouse.init(); picLoading.Show(); backgroundWorker1.RunWorkerAsync(); } else { txtOutput.Text = "Canceled Sign in."; HELPER_EnableStartUI(true); this.btnPlay3DFT.Enabled = true; this.btnOpenFile.Enabled = true; } }
private void btnSimulation_Click(object sender, EventArgs e) { using (SimulationFormWizard simulationForm = new SimulationFormWizard()) { txtOutput.Text = "Lets go forth and replentish the Earth, shall we?"; this.btnPlay3DFT.Enabled = false; // only enabled after saving the file. this.btnOpenFile.Enabled = false; var dialogRet = simulationForm.ShowDialog(); if (dialogRet == DialogResult.Yes) { //Debug.WriteLine("Awake"); _courtHouse = new CourtHouse(); _matchMaker = new Matchmaker(ref _courtHouse); _matchMaker.init(); int lastYear = simulationForm.StartYear; int currentYear = simulationForm.StartYear; int endYear = currentYear + simulationForm.NumberOfYears; TreePerson Adam = new TreePerson(TreePerson.PersonType.Adam, currentYear.ToString()); TreePerson Eve = new TreePerson(TreePerson.PersonType.Eve, currentYear.ToString()); var personAIndex = _matchMaker.courtHouse.myPeople.addToAllPeople(Adam); var personEIndex = _matchMaker.courtHouse.myPeople.addToAllPeople(Eve); _matchMaker.addToSinglesList(personAIndex, Adam.Sex); _matchMaker.addToSinglesList(personEIndex, Eve.Sex); //Debug.WriteLine("Hello " + Adam.Name + " and " + Eve.Name + " !"); //Debug.WriteLine(Adam.GetSex() + " and " + Eve.GetSex()); for (currentYear = simulationForm.StartYear; currentYear <= endYear; currentYear++) { //Debug.WriteLine("Happy New Year!!. It is year: " + currentYear.ToString()); //Debug.WriteLine("We have " + _matchMaker.BachelorPersonIndexList.Count + " Bachelors, and " + // _matchMaker.BachelorettePersonIndexList.Count + " Bachelorettes"); //Debug.WriteLine("Our people count is " + _matchMaker.courtHouse.myPeople.allPeople.Count + ", with alive count =" + // _matchMaker.courtHouse.myPeople.livingCount()); //Debug.WriteLine("We have " + _matchMaker.courtHouse.allFamilies.Count + " Families <-----------------------"); _matchMaker.doWeddings(currentYear); _matchMaker.beFruitfullAndMultiply(currentYear); _matchMaker.mortality(currentYear); lastYear = currentYear; } //Debug.WriteLine("We are done with populating the earth!"); //Debug.WriteLine("We have " + _matchMaker.BachelorPersonIndexList.Count + " Bachelors, and " + // _matchMaker.BachelorettePersonIndexList.Count + " Bachelorettes"); txtOutput.Clear(); txtOutput.AppendText(string.Format("Our simulation created {0} Families, and {1} Individuals", _courtHouse.allFamilies.Count, _courtHouse.myPeople.allPeople.Count)); txtOutput.AppendText(System.Environment.NewLine + System.Environment.NewLine + "--> Next, Save this file, so that you can play it."); //fileNameForSaving = string.Format("3DTree_Sim_F{0}_P{1}", _courtHouse.allFamilies.Count, // _courtHouse.myPeople.allPeople.Count); HELPER_EnableOutputUI(true); } else { txtOutput.Clear(); txtOutput.AppendText("Simulation, Canceled."); this.btnPlay3DFT.Enabled = true; this.btnOpenFile.Enabled = true; } } }
private static int _chanceForABaby = 30; //percent /// <summary> /// Matchmaker has all the powers of populating the earch. Refer to Genesis 1:28 /// God Created Man and Woman.. God Said "Be Fruitful and multiply, and fill the Earth" /// Well... the Matchmaker class and Method simulates this. Starting at the constructor /// where Family 0 is created "Adam abd Eve" of couse. /// Based on a pool (List) of available bachelors and bachelorettes, and a list current families /// These methods are meant to be called while moving a 'currentYear' counter forward year by year. /// Your can move through several hundred or several thousand years, and find your world populated. /// Some interesting parameters and probabilities are used to drive this creation. /// </summary> public Matchmaker(ref CourtHouse myCourtHouse) { courtHouse = myCourtHouse; }
public void OpenFile() { _courtHouse = new CourtHouse(); txtOutput.Text = "Lets go get that file, shall we?"; openFileDialog1.FileName = Path.GetFileName(_myAppDataStorage.FamilyInfoFileName); openFileDialog1.Filter = "Xml Doc (*.xml)|*.xml"; openFileDialog1.AddExtension = true; openFileDialog1.InitialDirectory = Path.GetDirectoryName(_myAppDataStorage.FamilyInfoFileName) + Path.DirectorySeparatorChar; openFileDialog1.RestoreDirectory = true; if (openFileDialog1.ShowDialog() == DialogResult.OK) { // Construct an instance of the XmlSerializer with the type // of object that is being deserialized. XmlSerializer serializer = new XmlSerializer(_courtHouse.GetType()); // To read the file, create a FileStream. FileStream myFileStream = new FileStream(openFileDialog1.FileName, FileMode.Open); // Call the Deserialize method and cast to the object type. _courtHouse = (CourtHouse) serializer.Deserialize(myFileStream); myFileStream.Close(); txtOutput.Clear(); txtOutput.AppendText(string.Format("Read in {0} Families, and {1} Individuals", _courtHouse.allFamilies.Count, _courtHouse.myPeople.allPeople.Count)); txtPlayFile.Text = _myAppDataStorage.FamilyInfoFileName = openFileDialog1.FileName; _myAppDataStorage.Save(); this.btnPlay3DFT.Enabled = true; this.btnOpenFile.Enabled = true; HELPER_EnableOutputUI(true); } else { txtOutput.Clear(); txtOutput.AppendText("Open File, Canceled."); } }
public bool readCollection(CourtHouse courtHouse, BackgroundWorker worker) { _courtHouse = courtHouse; _worker = worker; // Given Ascestory Descendancy Both // # Generations (Radius) // Starting ID // Add persons family as parent (Person) // enumerate children (Person) // enumerate parents (person) // Write: // Recursive Add Descendants (person, generations) // Recursive Add Ancestors (Person, Generations) // We need to be able to run both, so worry about overlap if (_worker.CancellationPending == true) return false; if (startingID.ToLower() == "self") { UserState userState = ft.ReadCurrentUser(); startingID = userState.Id; } FamilyTreePersonState personState = ft.ReadPersonById(startingID); if (_worker.CancellationPending == true) return false; // this does a descendancy recursion if (!AddPersonsFamily(personState, numberOfGenerations)) return false; return true; }