示例#1
0
        public bool SueDeCoq( )
        {
            if (pAnMan.GStage != GStageMemo)
            {
                GStageMemo = pAnMan.GStage;
                fALS.Initialize();
                fALS.PrepareALSLinkMan(+2);     //Generate ALS(+1 & +2)
            }

            if (fALS.ALSLst.Count <= 3)
            {
                return(false);
            }

            foreach (var ISPB in fALS.ALSLst.Where(p => p.tfx >= 18 && p.Size >= 3))      //Selecte Block-type ALS
            {
                if (ISPB.rcbRow.BitCount() <= 1 || ISPB.rcbCol.BitCount() <= 1)
                {
                    continue;                                                         //Block squares have multiple rows and columns
                }
                foreach (var ISPR in fALS.ALSLst.Where(p => p.tfx < 18 && p.Size >= 3))
                {
                                                                                     //Selecte Row-type/Column-type ALS
                    if ((ISPR.rcbBlk & ISPB.rcbBlk) == 0)
                    {
                        continue;                                               //Intersect with ISPB
                    }
                    if (ISPR.rcbBlk.BitCount() < 2)
                    {
                        continue;                                               //ISPR has multiple blocks
                    }
                    //Are the cell configurations of the intersections the same?
                    if ((ISPB.B81 & HouseCells[ISPR.tfx]) != (ISPR.B81 & HouseCells[ISPB.tfx]))
                    {
                        continue;
                    }

                    // ***** the code follows HP -> http://csdenpe.web.fc2.com/page45.html *****

                    Bit81 IS = ISPB.B81 & ISPR.B81;                               //Intersection
                    if (IS.Count < 2)
                    {
                        continue;
                    }
                                                                               //At least 2 cells at the intersection
                    if ((ISPR.B81 - IS).Count == 0)
                    {
                        continue;                                               //There is a part other than the intersecting part in ISPR
                    }
                    Bit81 PB       = ISPB.B81 - IS;                             //ISPB's outside IS
                    Bit81 PR       = ISPR.B81 - IS;                             //ISPR's outside IS
                    int   IS_FreeB = IS.AggregateFreeB(pBDL);                   //Intersection number
                    int   PB_FreeB = PB.AggregateFreeB(pBDL);                   //ISPB's number outside the IS
                    int   PR_FreeB = PR.AggregateFreeB(pBDL);                   //ISPR's number outside the IS
                    if ((IS_FreeB & PB_FreeB & PR_FreeB) > 0)
                    {
                        continue;
                    }

                    //A.DifSet(B)=A-B=A&(B^0x1FF)
                    int PB_FreeBn = PB_FreeB.DifSet(IS_FreeB);                  //Numbers not at the intersection of PB
                    int PR_FreeBn = PR_FreeB.DifSet(IS_FreeB);                  //Numbers not in the intersection of PR

                    int sdqNC = PB_FreeBn.BitCount() + PR_FreeBn.BitCount();    //Number of confirmed numbers outside the intersection
                    if ((IS_FreeB.BitCount() - IS.Count) != (PB.Count + PR.Count - sdqNC))
                    {
                        continue;
                    }

                    int elmB = PB_FreeB | IS_FreeB.DifSet(PR_FreeB);            //Exclusion Number in PB
                    int elmR = PR_FreeB | IS_FreeB.DifSet(PB_FreeB);            //Exclusion Number in PR
                    if (elmB == 0 && elmR == 0)
                    {
                        continue;
                    }

                    foreach (var P in _GetRestCells(ISPB, elmB))
                    {
                        P.CancelB |= P.FreeB & elmB; SolCode = 2;
                    }
                    foreach (var P in _GetRestCells(ISPR, elmR))
                    {
                        P.CancelB |= P.FreeB & elmR; SolCode = 2;
                    }

                    if (SolCode > 0)       //--- SueDeCoq found -----
                    {
                        SolCode = 2;
                        SuDoQueEx_SolResult(ISPB, ISPR);
                        if (ISPB.Level >= 3 || ISPB.Level >= 3)
                        {
                            WriteLine("Level-3");
                        }

                        if (__SimpleAnalizerB__)
                        {
                            return(true);
                        }
                        if (!pAnMan.SnapSaveGP(true))
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
        }                                        //UVWXYZ-wing

        private bool _UVWXYZwing(int wsz)        //simple UVWXYZwing
        {
            if (pAnMan.GStage != GStageMemo)
            {
                GStageMemo = pAnMan.GStage;
                FBCX       = pBDL.FindAll(p => p.FreeBC == wsz);
            }
            if (FBCX.Count == 0)
            {
                return(false);
            }

            bool wingF = false;

            foreach (var P0 in FBCX)                       //focused Cell
            {
                int b0 = P0.b;                             //focused Block
                foreach (int no in P0.FreeB.IEGet_BtoNo()) //focused Digit
                {
                    int   noB   = 1 << no;
                    Bit81 P0con = (new Bit81(pBDL, noB, FreeBC: 2)) & ConnectedCells[P0.rc];
                    Bit81 Pin   = P0con & HouseCells[18 + P0.b];

                    Bit81 Pout = null, Pin2 = null;
                    for (int dir = 0; dir < 2; dir++) //dir 0:row 1:col
                    {
                        int rcDir = (dir == 0)? P0.r: (9 + P0.c);
                        Pin2 = Pin - HouseCells[rcDir];
                        if (Pin2.IsZero())
                        {
                            continue;
                        }
                        Pout = (P0con & HouseCells[rcDir]) - HouseCells[18 + P0.b];
                        if (Pin2.Count + Pout.Count != (wsz - 1))
                        {
                            continue;
                        }

                        int FreeBin  = Pin2.AggregateFreeB(pBDL);
                        int FreeBout = Pout.AggregateFreeB(pBDL);
                        if ((FreeBin | FreeBout) != P0.FreeB)
                        {
                            continue;
                        }
                        Bit81 ELst = HouseCells[rcDir] & HouseCells[18 + P0.b];
                        ELst.BPReset(P0.rc);
                        string msg3 = "";
                        foreach (var E in ELst.IEGet_rc().Select(p => pBDL[p]))
                        {
                            if ((E.FreeB & noB) > 0)
                            {
                                E.CancelB = noB; wingF = true;
                                msg3     += " " + E.rc.ToRCString();
                            }
                        }
                        if (!wingF)
                        {
                            continue;
                        }

                        //--- ...wing found -------------
                        SolCode = 2;
                        string[] xyzWingName = { "XYZ-Wing", "WXYZ-Wing", "VWXYZ-Wing", "UVWXYZ-Wing" };
                        string   SolMsg      = xyzWingName[wsz - 3];

                        if (SolInfoB)
                        {
                            P0.SetNoBBgColor(P0.FreeB, AttCr, SolBkCr2);
                            foreach (var P in Pin2.IEGet_rc().Select(p => pBDL[p]))
                            {
                                P.SetNoBBgColor(P.FreeB, AttCr, SolBkCr);
                            }
                            foreach (var P in Pout.IEGet_rc().Select(p => pBDL[p]))
                            {
                                P.SetNoBBgColor(P.FreeB, AttCr, SolBkCr);
                            }

                            string msg0 = " Pivot: " + P0.rc.ToRCString();
                            string st   = ""; foreach (var rc in Pin2.IEGet_rc())
                            {
                                st += " " + rc.ToRCString();
                            }
                            string msg1 = " in: " + st.ToString_SameHouseComp();
                            st = "";  foreach (var rc in Pout.IEGet_rc())
                            {
                                st += " " + rc.ToRCString();
                            }
                            string msg2 = " out: " + st.ToString_SameHouseComp();
                            st = ""; foreach (var rc in Pin2.IEGet_rc())
                            {
                                st += " " + rc.ToRCString();
                            }

                            ResultLong = SolMsg + "\r" + msg0 + "\r   " + msg1 + "\r  " + msg2 + "\r Eliminated: " + msg3.ToString_SameHouseComp();
                            Result     = SolMsg + msg0 + msg1 + msg2;
                        }
                        if (__SimpleAnalizerB__)
                        {
                            return(true);
                        }
                        if (!pAnMan.SnapSaveGP(true))
                        {
                            return(true);
                        }
                        wingF = false;
                    }
                }
            }
            return(false);
        }