private bool Match(Card[] expected, MadeHand actual) { Guards.Assert(expected.Length == actual.Played.Length, "Impossible match"); var expectedSorted = expected.SortByFace(); var actualSorted = actual.Played.SortByFace(); // Run each position for (int i = 0; i < expectedSorted.Length; i++) { var expect = expectedSorted[i]; // If it is not a match in the hand if (!expect.Equals(actualSorted[i])) { // Check to see if it is an alternate if (!(actual.Alternates?.ContainsKey(actualSorted[i]) ?? false)) { return(false); } if (!actual.Alternates[actualSorted[i]].Any(_ => _.Equals(expect))) { return(false); } } } return(true); }