Exclusive Rule

 


        private HashSet<(string B, string C)> CollectExclusiveRules()

        {

            string pattern = @"(\S+\[[A-Za-z0-9]+\]).Exclusive\s*=\s*(\S+\[[A-Za-z0-9]+\])";

            var forbiddenPairs = new HashSet<(string B, string C)>();

            foreach (var rule in CodeSettingRules)

            {

                var match = Regex.Match(rule, pattern);

                if (!match.Success)

                {

                    continue;

                }


                forbiddenPairs.Add((match.Groups[1].Value.Trim(), match.Groups[2].Value.Trim()));

            }


            return forbiddenPairs;

        }


        private bool IsInExclusiveRules(Collection<string> items, HashSet<(string B, string C)> forbiddenPairs)

        {

            if (forbiddenPairs.Count == 0)

            {

                return false;

            }


            foreach (var s1 in items)

            {

                foreach (var s2 in items)

                {

                    if (s1 == s2) continue; // 跳過自己配對自己


                    if (forbiddenPairs.Contains((s1, s2)) || forbiddenPairs.Contains((s2, s1)))

                    {

                        return true;

                    }

                }

            }


            return false;

        }

留言