Beispiel #1
0
        private bool _ALSXZsub(int sz)
        {
            if (ALSMan.ALSLst.Count < 2)
            {
                return(false);
            }

            var cmb = new Combination(ALSMan.ALSLst.Count, 2);
            int nxt = 99;

            while (cmb.Successor(nxt))                          //Select two ALSs
            {
                UALS UA = ALSMan.ALSLst[cmb.Index[0]];
                nxt = 0; if (!UA.singly || UA.Size == 1 || UA.Size > (sz - 2))
                {
                    continue;
                }

                UALS UB = ALSMan.ALSLst[cmb.Index[1]];
                nxt = 1; if (!UB.singly || UB.Size == 1 || (UA.Size + UB.Size) != sz)
                {
                    continue;
                }

                int RCC = ALSMan.Get_AlsAlsRcc(UA, UB);          //Common numbers, House contact, Without overlap
                if (RCC == 0)
                {
                    continue;
                }

                if (RCC.BitCount() == 1)                          //===== Singly Linked =====
                {
                    int EnoB = (UA.FreeB & UB.FreeB).DifSet(RCC); //Exclude candidate digit
                    if (EnoB > 0 && _ALSXZ_SinglyLinked(UA, UB, RCC, EnoB))
                    {
                        SolCode = 2;
                        ALSXZ_SolResult(RCC, UA, UB);

                        if (__SimpleAnalizerB__)
                        {
                            return(true);
                        }
                        if (!pAnMan.SnapSaveGP(true))
                        {
                            return(true);
                        }
                    }
                }
                else if (RCC.BitCount() == 2)    //===== Doubly Linked =====
                {
                    if (_ALSXZ_DoublyLinked(UA, UB, RCC))
                    {
                        SolCode = 2;
                        ALSXZ_SolResult(RCC, UA, UB);

                        if (__SimpleAnalizerB__)
                        {
                            return(true);
                        }
                        if (!pAnMan.SnapSaveGP(true))
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
        private bool _ALSXYWingSub(int szT)
        {
            //(ALS sorted by size)
            foreach (var UC in ALSMan.ALSLst.Where(p => p.Size <= szT - 2))
            {
                if (!UC.singly)
                {
                    continue;
                }
                int szS = szT - UC.Size;

                UALS UA, UB, UApre = null;
                int  nxt = 0, RccAC = -1, RccBC = -1;
                var  cmb = new Combination(ALSMan.ALSLst.Count, 2);
                while (cmb.Successor(nxt))
                {
                    nxt = 0;
                    UA  = ALSMan.ALSLst[cmb.Index[0]];
                    if (!UA.singly || UA == UC || UA.Size > szS - 1)
                    {
                        continue;
                    }
                    if (UA != UApre)
                    {
                        RccAC = ALSMan.Get_AlsAlsRcc(UA, UC);    //RCC
                        if (RccAC.BitCount() != 1)
                        {
                            continue;
                        }
                        UApre = UA;
                    }

                    UB = ALSMan.ALSLst[cmb.Index[1]];
                    if (!UB.singly || UB.Size > (szS - UA.Size))
                    {
                        continue;                                      //Skip using "Sort by size"
                    }
                    nxt = 1;
                    if (UB == UC || UB.Size != (szS - UA.Size))
                    {
                        continue;
                    }
                    if (!(UA.B81 & UB.B81).IsZero())
                    {
                        continue;                               //Overlap
                    }
                    RccBC = ALSMan.Get_AlsAlsRcc(UB, UC);       //RCC
                    if (RccBC.BitCount() != 1)
                    {
                        continue;
                    }
                    if (RccAC == RccBC)
                    {
                        continue;
                    }

                    int EFrB = (UA.FreeB & UB.FreeB).DifSet(RccAC | RccBC);
                    if (EFrB == 0)
                    {
                        continue;
                    }
                    foreach (var no in EFrB.IEGet_BtoNo())
                    {
                        int   noB = (1 << no);
                        Bit81 UE  = new Bit81();
                        foreach (var P in UA.UCellLst.Where(p => (p.FreeB & noB) > 0))
                        {
                            UE.BPSet(P.rc);
                        }
                        foreach (var P in UB.UCellLst.Where(p => (p.FreeB & noB) > 0))
                        {
                            UE.BPSet(P.rc);
                        }

                        Bit81 TBD = (new Bit81(pBDL, noB)) - (UA.B81 | UB.B81 | UC.B81);
                        foreach (var rc in TBD.IEGet_rc())
                        {
                            if (!(UE - ConnectedCells[rc]).IsZero())
                            {
                                continue;
                            }
                            pBDL[rc].CancelB = noB; SolCode = 2;
                        }

                        if (SolCode > 0) //===== ALS XY-Wing found =====
                        {
                            ALSXYWing_SolResult(UA, UB, UC, RccAC, RccBC);
                            if (__SimpleAnalizerB__)
                            {
                                return(true);
                            }
                            if (!pAnMan.SnapSaveGP(true))
                            {
                                return(true);
                            }
                        }
                    }
                }
            }
            return(false);
        }