From 36195a3e9fc7cd27bf138a7eea6e410a80ad70e8 Mon Sep 17 00:00:00 2001 From: Anna Date: Fri, 15 Jan 2021 22:12:29 -0500 Subject: [PATCH] fix: make the job filter work better --- BetterPartyFinder/Filter.cs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/BetterPartyFinder/Filter.cs b/BetterPartyFinder/Filter.cs index e75992c..27fcfe7 100755 --- a/BetterPartyFinder/Filter.cs +++ b/BetterPartyFinder/Filter.cs @@ -102,6 +102,16 @@ namespace BetterPartyFinder { } } + // ensure the number of total slots with possibles joins is at least the number of jobs + // note that this doesn't make sure it's joinable, see below + var numSlots = jobs + .Aggregate((acc, x) => acc.Union(x).ToHashSet()) + .Count; + + if (numSlots < jobs.Length) { + return false; + } + // loop through each unique pair of jobs for (var i = 0; i < jobs.Length; i++) { // ReSharper disable once LoopCanBeConvertedToQuery @@ -115,12 +125,13 @@ namespace BetterPartyFinder { // check if the slots either job can join have overlap var overlap = a.Intersect(b); - if (!overlap.Any()) { + if (overlap.Count() != 1) { continue; } // if there is overlap, check the difference between the sets // if there is no difference, the party can't be joined + // note that if the overlap is more than one slot, we don't need to check var difference = a.Except(b); if (!difference.Any()) { return false;