public void FindBestMatchForGift_lavel_B(double x, double y, double quan) { flag++; if (flag == 1) { originalValueOF_Y = y; originalValueOF_X = x; } width_X Xdata = new width_X(x, y, default); width_X FoundMatch_of_X; Tree.FindBestMatch(Xdata, Tree.Root, out FoundMatch_of_X); if (FoundMatch_of_X == null || FoundMatch_of_X.x > originalValueOF_X + (originalValueOF_X * 0.4)) // if not founnd Xdata { if (Alloptions.Count != 0) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("THE Best match that has been found !\n"); Console.ResetColor(); Console.WriteLine("--------------------------------------"); ShowOptions(); } else { Console.Clear(); Console.WriteLine("Not found match"); Console.ReadLine(); } } else // if Xdata exist { height_Y newYdata = new height_Y(y, default); height_Y FoundMatch_of_Y; FoundMatch_of_X.FindBestMatch_of_Y(newYdata, out FoundMatch_of_Y); if (FoundMatch_of_Y != null) // if Y_data exist { if (FoundMatch_of_Y.quantity >= quan) //checking if the best match contains the required quantity { width_X newda = new width_X(FoundMatch_of_X.x, FoundMatch_of_Y.y, FoundMatch_of_Y.quantity); Alloptions.Add(newda); ListOf_heights.Add(FoundMatch_of_Y); Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("THE Best match that has been found !\n"); Console.ResetColor(); Console.WriteLine("--------------------------------------"); ShowOptions(); return; } if (FoundMatch_of_Y.quantity >= quan * 0.4) //checking if quantity bigger than 40% of request { width_X newda = new width_X(FoundMatch_of_X.x, FoundMatch_of_Y.y, FoundMatch_of_Y.quantity); Alloptions.Add(newda); ListOf_heights.Add(FoundMatch_of_Y); FindBestMatchForGift_lavel_B(x, FoundMatch_of_Y.y + 0.1, quan); } else { FindBestMatchForGift_lavel_B(x, FoundMatch_of_Y.y + 0.1, quan); } } else // if Y_data not found { FindBestMatchForGift_lavel_B(FoundMatch_of_X.x + 0.01, originalValueOF_Y, quan); } } }
public void FindBestMatchForGift_lavel_A(double x, double y) { width_X Xdata = new width_X(x, y, default); width_X FoundMatch_of_X; Tree.FindBestMatch(Xdata, Tree.Root, out FoundMatch_of_X); if (FoundMatch_of_X == null) // if not founnd Xdata { try { throw new Exception("Not found match"); } catch (Exception e) { Console.WriteLine(e.Message); } } else // if Xdata exist { height_Y newYdata = new height_Y(y, default); height_Y FoundMatch_of_Y; FoundMatch_of_X.FindBestMatch_of_Y(newYdata, out FoundMatch_of_Y); try { if (FoundMatch_of_Y != null) // if Y_data exist { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("THE Best match that has been found !\n"); Console.ResetColor(); Console.WriteLine("--------------------------------------"); Console.WriteLine($"width={FoundMatch_of_X.x}" + "" + FoundMatch_of_Y + "\n"); FoundMatch_of_Y.quantity = FoundMatch_of_Y.quantity - 1; if (FoundMatch_of_Y.CheckAllowable_Quantity()) // checking the quantity if it is acceptable { Console.WriteLine("the current number of boxes has reached zero!"); FoundMatch_of_X.y_dataList.Remove(FoundMatch_of_Y); if (FoundMatch_of_X.y_dataList == null) { Tree.Remove(FoundMatch_of_X); } Console.WriteLine("this object has been removed from the system!"); } } else // if Y_data not exist { width_X Xdata2 = new width_X(x + 0.01, y, default); counter++; if (counter > 100) { counter = 0; throw new Exception("Not found match"); } FindBestMatchForGift_lavel_A(Xdata2.x, y); } } catch (Exception e) { Console.WriteLine(e.Message); } } }