public virtual bool Check(NewPeople p) { if (p.Strength >= MinStrength && p.Strength <= MaxStrength) { if (p.Perception >= MinPerception && p.Perception <= MaxPerception) { if (p.Endurance >= MinEndurance && p.Endurance <= MaxEndurance) { if (p.Charisma >= MinCharisma && p.Charisma <= MaxCharisma) { if (p.Intelligence >= MinIntelligence && p.Intelligence <= MaxIntelligence) { if (p.Agility >= MinAgility && p.Agility <= MaxAgility) { if (p.Luck >= MinLuck && p.Luck <= MaxLuck) { p.Job = Naam; Debug.WriteLine(p.FirstName + " is een " + Naam); return true; } } } } } } } return false; }
private bool CalculatePartner(NewPeople m, NewPeople newP) { if (m.Partner == null) { if (m.Sex != newP.Sex) { if (Math.Abs((m.DateOfBirth - newP.DateOfBirth).TotalDays) <= 6 * 365) { if (m.LastName != newP.LastName) { if (Math.Abs(m.Strength - newP.Strength) >= 1 && Math.Abs(m.Strength - newP.Strength) <= 3) { if (Math.Abs(m.Perception - newP.Perception) >= 1 && Math.Abs(m.Perception - newP.Perception) <= 3) { if (Math.Abs(m.Endurance - newP.Endurance) >= 1 && Math.Abs(m.Endurance - newP.Endurance) <= 3) { if (Math.Abs(m.Charisma - newP.Charisma) >= 1 && Math.Abs(m.Charisma - newP.Charisma) <= 3) { if (Math.Abs(m.Intelligence - newP.Intelligence) >= 1 && Math.Abs(m.Intelligence - newP.Intelligence) <= 3) { if (Math.Abs(m.Agility - newP.Agility) >= 1 && Math.Abs(m.Agility - newP.Agility) <= 3) { if (Math.Abs(m.Luck - newP.Luck) >= 1 && Math.Abs(m.Luck - newP.Luck) <= 3) { newP.Partner = m.Id; m.Partner = newP.Id; Debug.WriteLine(newP.FirstName + " " + newP.LastName + " has a relation with " + m.FirstName + " " + m.LastName); return true; } } } } } } } } } } } return false; }
async void CalculatePeople() { _people = Context.People.Take(WidthCalc).ToList(); _newPeoples = new List<NewPeople>(); foreach (var p in _people) { var add = new NewPeople(); add.Create(p); _newPeoples.Add(add); } for (int j = 0; j < _newPeoples.Count; j++) { var newP = _newPeoples.ElementAt(j); foreach (var a in _arbeiden) { if (a.Check(newP)) break; } //Check if person has a partner //If not find one if (newP.Partner == null) { for (int k = j + 1; k < _newPeoples.Count; k++) { var m = _newPeoples.ElementAt(k); if (CalculatePartner(m, newP)) break; } } } //Context.People.RemoveRange(_people); Context.People.Take(WidthCalc).Delete(); //Context.NewPeople.AddRange(_newPeoples); Context.BulkInsert(_newPeoples); //Save to DB Context.SaveChanges(); //Update DataGrid _i = 0; var data = Context.People.Take(WidthShow); Lijst = new ObservableCollection<People>(data); }