private static bool HideItems(GameFieldModel model, Random rand, CancellationToken token) { var orderedPairs = model.GetAllPairs(); var pairs = rand.Shake(orderedPairs); var rank = 1; const int maxRank = 2; do { var pair = GetAvailableToHidePair(model, pairs, token, rank); if (pair == null) { if (rank == maxRank) break; rank++; orderedPairs = model.GetAllPairs().Where(model.GetItemVisible); pairs = rand.Shake(orderedPairs); } else { pairs.Remove(pair); } } while(true); return model.VisibleCount <= maxVisibleNumbers; }