예제 #1
0
        public void AddSumBlockCondition(int Sum, int xFrom, int xTo, int yFrom, int yTo)
        {
            Fields ConditionFields = new Fields();

            for (int x = xFrom; x <= xTo; x++)
            {
                for (int y = yFrom; y <= yTo; y++)
                {
                    ConditionFields.Add(FieldList.At(x, y));
                }
            }
            SumCondition cnd = new SumCondition(Sum, ConditionFields);

            Conditions.Add(cnd);
        }
예제 #2
0
        public void FindHiddenConditions()
        {
            List <Condition> HiddenConditions = new List <Condition>();

            foreach (Condition cnd in Conditions)
            {
                if (cnd is SumCondition)
                {
                    SumCondition            scnd = (SumCondition)cnd;
                    SubSetNumberCondition   ssncnd;
                    MultipleNumberCondition mnc;
                    switch (scnd.FieldList.Count)
                    {
                    case 1:
                        ssncnd = new SubSetNumberCondition(new int[1] {
                            scnd.Sum
                        }, scnd.FieldList);
                        HiddenConditions.Add(ssncnd);
                        break;

                    case 2:
                        if (CheckInAllNumberBlock(scnd.FieldList))
                        {
                            switch (scnd.Sum)
                            {
                            case 1:
                                ssncnd = new SubSetNumberCondition(new int[2] {
                                    0, 1
                                }, scnd.FieldList);
                                ssncnd.FieldList = scnd.FieldList;
                                HiddenConditions.Add(ssncnd);
                                break;

                            case 2:
                                ssncnd = new SubSetNumberCondition(new int[2] {
                                    0, 2
                                }, scnd.FieldList);
                                ssncnd.FieldList = scnd.FieldList;
                                HiddenConditions.Add(ssncnd);
                                break;

                            case 3:
                                mnc = new MultipleNumberCondition(new int[2][] { new int[2] {
                                                                                     0, 3
                                                                                 }, new int[2] {
                                                                                     1, 2
                                                                                 } }, scnd.FieldList);
                                mnc.FieldList = scnd.FieldList;
                                HiddenConditions.Add(mnc);
                                break;

                            case 4:
                                mnc = new MultipleNumberCondition(new int[2][] { new int[2] {
                                                                                     0, 4
                                                                                 }, new int[2] {
                                                                                     1, 3
                                                                                 } }, scnd.FieldList);
                                mnc.FieldList = scnd.FieldList;
                                HiddenConditions.Add(mnc);
                                break;

                            case 13:
                                mnc = new MultipleNumberCondition(new int[2][] { new int[2] {
                                                                                     8, 5
                                                                                 }, new int[2] {
                                                                                     7, 6
                                                                                 } }, scnd.FieldList);
                                mnc.FieldList = scnd.FieldList;
                                HiddenConditions.Add(mnc);
                                break;

                            case 12:
                                mnc = new MultipleNumberCondition(new int[2][] { new int[2] {
                                                                                     8, 4
                                                                                 }, new int[2] {
                                                                                     7, 5
                                                                                 } }, scnd.FieldList);
                                mnc.FieldList = scnd.FieldList;
                                HiddenConditions.Add(mnc);
                                break;

                            case 15:
                                ssncnd = new SubSetNumberCondition(new int[2] {
                                    7, 8
                                }, scnd.FieldList);
                                ssncnd.FieldList = scnd.FieldList;
                                HiddenConditions.Add(ssncnd);
                                break;

                            case 14:
                                ssncnd = new SubSetNumberCondition(new int[2] {
                                    6, 8
                                }, scnd.FieldList);
                                ssncnd.FieldList = scnd.FieldList;
                                HiddenConditions.Add(ssncnd);
                                break;
                            }
                            break;
                        }
                        break;

                    case 3:
                        if (CheckInAllNumberBlock(scnd.FieldList))
                        {
                            switch (scnd.Sum)
                            {
                            case 3:
                                ssncnd = new SubSetNumberCondition(new int[3] {
                                    0, 1, 2
                                }, scnd.FieldList);
                                ssncnd.FieldList = scnd.FieldList;
                                HiddenConditions.Add(ssncnd);
                                break;

                            case 4:
                                ssncnd = new SubSetNumberCondition(new int[3] {
                                    0, 1, 3
                                }, scnd.FieldList);
                                ssncnd.FieldList = scnd.FieldList;
                                HiddenConditions.Add(ssncnd);
                                break;

                            case 5:
                                mnc = new MultipleNumberCondition(new int[2][] { new int[3] {
                                                                                     0, 1, 4
                                                                                 }, new int[3] {
                                                                                     0, 2, 3
                                                                                 } }, scnd.FieldList);
                                mnc.FieldList = scnd.FieldList;
                                HiddenConditions.Add(mnc);
                                break;

                            case 19:
                                mnc = new MultipleNumberCondition(new int[2][] { new int[3] {
                                                                                     8, 7, 4
                                                                                 }, new int[3] {
                                                                                     8, 6, 5
                                                                                 } }, scnd.FieldList);
                                mnc.FieldList = scnd.FieldList;
                                HiddenConditions.Add(mnc);
                                break;

                            case 21:
                                ssncnd = new SubSetNumberCondition(new int[3] {
                                    6, 7, 8
                                }, scnd.FieldList);
                                ssncnd.FieldList = scnd.FieldList;
                                HiddenConditions.Add(ssncnd);
                                break;

                            case 20:
                                ssncnd = new SubSetNumberCondition(new int[3] {
                                    5, 7, 8
                                }, scnd.FieldList);
                                ssncnd.FieldList = scnd.FieldList;
                                HiddenConditions.Add(ssncnd);
                                break;
                            }
                            break;
                        }
                        break;
                    }
                }
            }
            foreach (Condition cnd in HiddenConditions)
            {
                Conditions.Add(cnd);
            }

            bool ExcludesFound = true;

            while (ExcludesFound)
            {
                ExcludesFound = false;
                foreach (Condition cnd in Conditions)
                {
                    if (cnd is AllNumberCondition)
                    {
                        AllNumberCondition anc     = (AllNumberCondition)cnd;
                        List <int[]>       Pairs   = new List <int[]>();
                        List <int[]>       Triples = new List <int[]>();

                        foreach (Condition scnd in Conditions)
                        {
                            if (scnd is SubSetNumberCondition)
                            {
                                SubSetNumberCondition ssnc = (SubSetNumberCondition)scnd;
                                foreach (Field f in ssnc.FieldList)
                                {
                                    for (int i = 0; i < 9; i++)
                                    {
                                        foreach (int n in ssnc.Numbers)
                                        {
                                            if (i == n)
                                            {
                                                goto Found;
                                            }
                                        }
                                        if (f.Exclude(i))
                                        {
                                            ExcludesFound = true;
                                        }
Found:
                                        continue;
                                    }
                                }
                                if ((anc.FieldList & ssnc.FieldList) == ssnc.FieldList) // ssnc all containted in anc
                                {
                                    foreach (Field f in anc.FieldList)
                                    {
                                        if (!(ssnc.FieldList & f))
                                        {
                                            foreach (int n in ssnc.Numbers)
                                            {
                                                if (f.Exclude(n))
                                                {
                                                    ExcludesFound = true;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }


                        foreach (Field f in anc.FieldList)
                        {
                            if (f.IsSingleNumber)
                            {
                                foreach (Field f2 in anc.FieldList)
                                {
                                    if (f2 != f) // all otheres except the original
                                    {
                                        if (f2.Exclude(f.Number))
                                        {
                                            ExcludesFound = true;
                                        }
                                    }
                                }
                            }
                            else if (f.IsPair)  // detact pairs of values
                            {
                                Pairs.Add(f.GetValidNumbers());
                            }
                            else if (f.IsTriple)
                            {
                                Triples.Add(f.GetValidNumbers());
                            }
                        }
                        foreach (int[] pair in Pairs)   // check if 2 fields have the same pair
                        {
                            foreach (int[] pair2 in Pairs)
                            {
                                if (pair != pair2)
                                {
                                    if (CompareIntArrays(pair, pair2))  // yes, 2 fieds have the same pair
                                    {
                                        // now exlude each other from that all number group from this pairs
                                        foreach (Field f in anc.FieldList)
                                        {
                                            if (!CompareIntArrays(pair, f.GetValidNumbers())) // not the paired-fields
                                            {
                                                foreach (int iEx in pair)                     // exlcude the numbers
                                                {
                                                    if (f.Exclude(iEx))
                                                    {
                                                        ExcludesFound = true;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        foreach (int[] triple1 in Triples)   // check if 3 fields have the same triple
                        {
                            foreach (int[] triple2 in Triples)
                            {
                                if (triple1 != triple2)
                                {
                                    if (CompareIntArrays(triple1, triple2))  // yes, 2 fieds have the same triple
                                    {
                                        foreach (int[] triple3 in Triples)
                                        {
                                            if (triple3 != triple2 && triple3 != triple1)
                                            {
                                                if (CompareIntArrays(triple1, triple3))  // yes, all 3 fieds have the same triple
                                                {
                                                    // now exlude each other from that all number group from this pairs
                                                    foreach (Field f in anc.FieldList)
                                                    {
                                                        if (!CompareIntArrays(triple1, f.GetValidNumbers())) // not the tripled-fields
                                                        {
                                                            foreach (int iEx in triple1)                     // exlcude the numbers
                                                            {
                                                                if (f.Exclude(iEx))
                                                                {
                                                                    ExcludesFound = true;
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }