/// <summary> /// Go through the current table list to determine switch targets /// The target can be one family, and can be a combination of families, /// currently sitting on the table, whose combined sizes /// is suitable for a switch. /// Cannot do two moves yet. /// For simplicity, we just look for a single family at a time /// for switching. No combinations. /// </summary> /// <param name="fmly"></param> /// <returns></returns> private static List <Family> BuildSwitchTargeList(Family fmly) { List <Family> list = new List <Family> { }; for (int j = 0; j < _tableList.Count; j++) { //only occupied tables if (_tableList[j].GuestList != null) { for (int k = 0; k < _tableList[j].GuestList.Count; k++) { WeddingTable currentTable = _tableList[j]; Family currentGuest = _tableList[j].GuestList[k]; if (fmly.Size <= currentGuest.Size + _tableList[j].FreeSpots) { //check if the family is compatible with the remaining families //if so, add currentTable.GuestList.Remove(currentGuest); if (currentTable.FirendlyWith(fmly.Name) && fmly.Likes(currentTable.FamilyNames)) { list.Add(currentGuest); } //add it back currentTable.GuestList.Add(currentGuest); } } } } return(list); }
static void Main() { Family Welters = new Family("Welters", 6, ""); Family Smiths = new Family("Smiths", 4, "Welters"); Family Burks = new Family("Burks", 3, ""); Family Leskos = new Family("Leskos", 2, ""); //Family Leskos = new Family("Leskos", 2, "Burks"); //involving two moves: Smiths switches with Burks, and Adding Leskos to table A. The program is yet too dumb to do that. _unseated_list = new List <Family> { Welters, Smiths, Leskos, Burks }; WeddingTable tableA = new WeddingTable("A", 8); WeddingTable tableB = new WeddingTable("B", 6); WeddingTable tableC = new WeddingTable("C", 4); _tableList = new List <WeddingTable> { tableA, tableB, tableC }; _leftover_list = new List <Family> { }; if (_unseated_list.Sum(x => x.Size) > _tableList.Sum(x => x.Capacity)) { Console.WriteLine("You need more tables"); Console.Read(); return; } //largest family first _unseated_list = _unseated_list.OrderByDescending((x => x.Size)).ToList(); //smallest table first, so that we can assign the current largest family to //the first _tableList = _tableList.OrderBy((x => x.Capacity)).ToList(); while (_unseated_list.Count > 0) { //try my luck... try { Assign_Seats(_unseated_list[0]); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.Read(); return; } } //all is good if (_leftover_list.Count == 0) { //print all the stuff PrintResults(); return; } else { //try BASIC switch, print result if lucky while (_leftover_list.Count > 0) { //try to switch seats if (!SwitchSeats(_leftover_list[0])) { Console.WriteLine("Some families cannot be seated. Or the program isn't yet smart enough."); Console.Read(); return; } } //luck strikes! PrintResults(); } }