private int GroupedNLEx_CheckSolution(USuperLink GNL_Result, ref int contDiscontF)
        {
            bool SolFound = false;

            GroupedLink GLKnxt = GNL_Result.resultGLK;

            if (GLKnxt == null)
            {
                return(-1);                                     //Not established
            }
            List <GroupedLink> SolLst = Convert_ChainToList_GNL(GNL_Result);

            if (SolLst == null || SolLst.Count < 2)
            {
                return(-1);                                    //Not established
            }
            GroupedLink GLKorg  = SolLst[0];
            bool        SolType = Check_SuperLinkSequence(GLKnxt, GLKorg); //true:Continuous  false:DisContinuous

            contDiscontF = SolType? 1: 2;

            if (SolType)         //==================== continuous ====================
            {
                Bit81 UsedCs = SolLst.Aggregate(new Bit81(), (Q, P) => Q | P.UGCellsB.B81);

                foreach (var LK in SolLst.Where(P => (P.type == W)))
                {
                    int   noB   = 1 << LK.no;
                    Bit81 SolBP = new Bit81();
                    LK.UGCellsA.ForEach(P => { if ((P.FreeB & noB) > 0)
                                               {
                                                   SolBP.BPSet(P.rc);
                                               }
                                        });
                    LK.UGCellsB.ForEach(P => { if ((P.FreeB & noB) > 0)
                                               {
                                                   SolBP.BPSet(P.rc);
                                               }
                                        });
                    if (SolBP.BitCount() <= 1)
                    {
                        continue;
                    }
                    foreach (var P in pBDL.Where(p => (p.FreeB & noB) > 0))
                    {
                        if (UsedCs.IsHit(P.rc))
                        {
                            continue;
                        }
                        if (!(SolBP - ConnectedCells[P.rc]).IsZero())
                        {
                            continue;
                        }
                        if ((P.FreeB & noB) == 0)
                        {
                            continue;
                        }
                        P.CancelB |= noB; �@�@//exclusion digit
        public string GenMessage2FakeProposition(int rc0, int no, USuperLink USLK, UCell Q)
        {
            string st = "";

            st += $"ForceChain_Cell r{(rc0/9+1)}c{(rc0%9)+1}/{(no+1)} is false(contradition)";
            st += "\r" + _GenMessage2true(USLK, Q, no);
            st += "\r" + _GenMessage2false(USLK, Q, no);
            return(st);
        }
        public string _GenMessage2false(USuperLink USLK, UCell P, int no)
        {
            GroupedLink Pdes = (GroupedLink)USLK.chainDesLKF[P.rc, no];           //��
            string      st   = "";

            if (Pdes != null)
            {
                st += "   " + _chainToString2(P, Pdes, -(no + 1));                      //��_chainToString2
            }
            return(st);
        }
        public string _GenMessage2true(USuperLink USLK, UCell PX, int noX)
        {
            GroupedLink Pdes = (GroupedLink)USLK.chainDesLKT[PX.rc, noX];            //��
            string      st   = "";

            if (Pdes != null)
            {
                st += "   " + _chainToString2(PX, Pdes, -(noX + 1));                     //��_chainToString2
            }
            return(st);
        }
        private string GenMessage2FakeProposition(int rc0, Bit81[] fakeP, USuperLink USLK, UCell Q)     //q
        {
            string st = "";

            foreach (var no in pBDL[rc0].FreeB.IEGet_BtoNo())
            {
                if (fakeP[no].IsHit(rc0))
                {
                    st += $"ForceChain_Cell r{(rc0/9+1)}c{(rc0%9)+1}/{(no+1)} is false(contradition)";

                    st += "\r" + pSprLKsMan._GenMessage2true(USLK, Q, no);
                    st += "\r" + pSprLKsMan._GenMessage2false(USLK, Q, no);
                }
            }
            return(st);
        }
        //##### There is a bug #####
        public USuperLink get_L2SprLK(int rc, int no, bool FullSearchB, bool DevelopB)
        {
            USuperLink USLK = null;

            if (FullSearchB || !L2SprLkB81[no].IsHit(rc))                                          // Search when Unconditional or Unprocessed
            {
                USLK = Eval_SuperLinkChain(rc, no, Gbreak: false, typeSel: 3, DevelopB: DevelopB); // Origin(rc#no)
                L2SprLkB81[no].BPSet(rc);                                                          // Set the searched flag
                if (DevelopB)
                {
                    developDisp(rc, no, USLK, DevelopB);
                }
                L2SprLK[rc, no] = USLK;
            }

            USLK = L2SprLK[rc, no];
            //if(DevelopB) developDisp( rc, no, USLK, DevelopB );
            return(USLK);
        }
示例#7
0
        private string _GenMessage(USuperLink USLK, UCell P, int no)
        {
            string st           = "";
            var    pQtrue       = USLK.Qtrue;
            var    pQfalse      = USLK.Qfalse;
            var    pchainDesLKT = USLK.chainDesLKT;
            var    pchainDesLKF = USLK.chainDesLKF;

            if (pQfalse[no].IsHit(P.rc))
            {
                GroupedLink Pdes = (GroupedLink)pchainDesLKF[P.rc, no];
                st += _chainToString(P, Pdes, -(no + 1)) + "\r";
            }
            if (pQtrue[no].IsHit(P.rc))
            {
                GroupedLink Pdes = (GroupedLink)pchainDesLKT[P.rc, no];
                st += _chainToString(P, Pdes, no + 1) + "\r";
            }
            return(st);
        }
        public static DevelopWin devWin;         //## development

        // *=*=* Updated to radiation search *=*=*
        public bool GroupedNiceLoopEx( )
        {
            Prepare();
            pSprLKsMan.PrepareSuperLinkMan(AllF: true);

            bool DevelopB = false;

            foreach (var P0 in pBDL.Where(p => (p.FreeB > 0)))
            {
                foreach (var noH in P0.FreeB.IEGet_BtoNo())
                {
                    int noB = (1 << noH);
                    foreach (var GLKH in pSprLKsMan.IEGet_SuperLinkFirst(P0, noH))
                    {
                        UCell      P000       = GLKH.UGCellsA[0]; //P000=P0
                        USuperLink GNL_Result = pSprLKsMan.GNL_EvalSuperLinkChain(GLKH, P000.rc, DevelopB: DevelopB);
                        if (GNL_Result != null)                   //***** Solved
                        {
                            string st3 = "";
                            string st  = _chainToStringGNL(GNL_Result, ref st3);
                            if (DevelopB)
                            {
                                WriteLine($"***** solved:{st}");
                            }

                            if (__SimpleAnalizerB__)
                            {
                                return(true);
                            }
                            if (!pAnMan.SnapSaveGP(true))
                            {
                                return(true);
                            }

                            //return true;
                        }
                    }
                }
            }
            return(false);
        }
        // *** development is over ***
        public USuperLink get_L2SprLKEx(int rc0, int no0, bool FullSearchB, bool DevelopB)
        {
            USuperLink USLK = null;

            if (FullSearchB || !L2SprLkB81[no0].IsHit(rc0))                     // Search when Unconditional or Unprocessed
            {
                USLK = Eval_SuperLinkChainEx(rc0, no0, DevelopB: DevelopB);     // Origin(rc0#no0)

                if (USLK == null)
                {
                    return(null);
                }
                L2SprLkB81[no0].BPSet(rc0);  // Set the searched flag
                //if(DevelopB) developDispEx( rc0, no0, USLK, DevelopB );
                L2SprLK[rc0, no0] = USLK;    //origin#no0
            }

            USLK = L2SprLK[rc0, no0];
            //if(DevelopB) developDispEx( rc0, no0, USLK, DevelopB );
            return(USLK);
        }
示例#10
0
        public List <GroupedLink> Convert_ChainToList_GNL(USuperLink GNL_Result)
        {
            if (GNL_Result == null)
            {
                return(null);
            }

            var         SolLst = new List <GroupedLink>();
            GroupedLink GLKnxt = GNL_Result.resultGLK;

            //===================== convert chain to list ===========================
            GroupedLink X = GLKnxt;

            while (X != null && SolLst.Count < 50)
            {
                SolLst.Add(X);
                X = X.preGrpedLink as GroupedLink;
            }
            SolLst.Reverse();

            return(SolLst);
        }
//============================================================================================================
        public bool GenMessage2(USuperLink USLK, UCell P, int no)
        {
            var pQtrue  = USLK.Qtrue;
            var pQfalse = USLK.Qfalse;

            if (!pQfalse[no].IsHit(P.rc) || !pQtrue[no].IsHit(P.rc))
            {
                return(false);
            }

            var pchainDesLKT = USLK.chainDesLKT;                    //��
            var pchainDesLKF = USLK.chainDesLKF; �@�@               //��

            GroupedLink Pdes = (GroupedLink)pchainDesLKT[P.rc, no]; //��
            string      st   = "";

            if (Pdes != null)
            {
                st += "   " + _chainToString2(P, Pdes, -(no + 1)); //��_chainToString2
            }
            Pdes = (GroupedLink)pchainDesLKF[P.rc, no]; �@         //��
            if (Pdes != null)
            {
                if (st.Length > 4)
                {
                    st += "\r";
                }
                else
                {
                    st = "";
                }
                st += "   " + _chainToString2(P, Pdes, no + 1);                             //��_chainToString2
            }
            USLK.stMsg = st;
            return(true);
        }
示例#12
0
        public void developDisp(int rc0, int no0, USuperLink USLK, bool DevelopB)
        {
            if (USLK == null || USLK.Qtrue == null)
            {
                return;
            }
            List <UCell> qBDL = new List <UCell>();

            pBDL.ForEach(p => qBDL.Add(p.Copy()));

            var pQtrue       = USLK.Qtrue;
            var pQfalse      = USLK.Qfalse;
            var pchainDesLKT = USLK.chainDesLKT;
            var pchainDesLKF = USLK.chainDesLKF;

            foreach (var P in qBDL)
            {
                if (P.No != 0)
                {
                    continue;
                }
                int noT = 0, noF = 0;
                foreach (var no in P.FreeB.IEGet_BtoNo())
                {
                    if (pQtrue[no].IsHit(P.rc))
                    {
                        noT |= (1 << no);
                    }
                    if (pQfalse[no].IsHit(P.rc))
                    {
                        noF |= (1 << no);
                    }
                }
                if (noT > 0)
                {
                    P.SetNoBBgColor(noT, Colors.Red, Colors.LemonChiffon);
                }
                if (noF > 0)
                {
                    P.SetNoBBgColorRev(noF, Colors.Red, Colors.LemonChiffon);
                }
                if ((noT & noF) > 0)
                {
                    P.SetNoBBgColor(noT & noF, Colors.White, Colors.PowderBlue);
                    P.SetNoBColorRev(noT & noF, Colors.Blue);
                }
            }
            qBDL[rc0].SetNoBBgColor(1 << no0, Colors.Red, Colors.Yellow);

            devWin.Set_dev_GBoard(qBDL, dispOn: false);

            if (DevelopB)
            {
                string stMsg = "";
                foreach (var P in pBDL)
                {
                    if (P.No != 0)
                    {
                        continue;
                    }
                    foreach (var no in P.FreeB.IEGet_BtoNo())
                    {
                        if (pQfalse[no].IsHit(P.rc) && pQtrue[no].IsHit(P.rc))
                        {
                            WriteLine("------------error");
                        }
                        string st = _GenMessage(USLK, P, no);
                        if (st.Length > 4)
                        {
                            WriteLine(st);
                            stMsg += st;
                        }
                    }
                }
                USLK.stMsg = stMsg;
            }
        }
        public bool ForceChain_CellEx( )
        {
            if (GNPXApp000.GMthdOption["ForceChainCellHouseOn"] != "1")
            {
                return(false);
            }

            GroupedLink._IDsetB = false;  //ID set for debug

            Prepare();
            pSprLKsMan.PrepareSuperLinkMan(AllF: true);
            string dspOpt = GNPXApp000.GMthdOption["ForceLx"];

            Bit81[] sPass = new Bit81[9];
            for (int k = 0; k < 9; k++)
            {
                sPass[k] = new Bit81();
            }

            bool solvedA = false;

            foreach (var P0 in pBDL.Where(p => (p.FreeB > 0)))                      //origin cell
            {
                Bit81[] sTrue = new Bit81[9];
                for (int k = 0; k < 9; k++)
                {
                    sTrue[k] = new Bit81(all_1: true);
                }

                bool solvedB = false;
                foreach (var no0 in P0.FreeB.IEGet_BtoNo())
                {
                    int        noB  = (1 << no0);
                    USuperLink USLK = pSprLKsMan.get_L2SprLKEx(P0.rc, no0, FullSearchB: true, DevelopB: false);
                    if (USLK == null || !USLK.SolFound)
                    {
                        goto nextSearch;
                    }
                    for (int k = 0; k < 9; k++)
                    {
                        sTrue[k] &= (USLK.Qtrue[k] - USLK.Qfalse[k]);
                    }
                }

                for (int nox = 0; nox < 9; nox++)
                {
                    sTrue[nox].BPReset(P0.rc);
                    if (!sTrue[nox].IsZero())
                    {
                        solvedB = true;
                    }
                }

                if (solvedB)
                {
                    solvedA = true;
                    _ForceChainCellDispEx(sPass, sTrue, P0.rc); //q
                    if (!SDK_Ctrl.MltAnsSearch && dspOpt != "ForceL2")
                    {
                        break;
                    }
                }

nextSearch:
                continue;
            }
            if (solvedA && !SDK_Ctrl.MltAnsSearch && dspOpt == "ForceL2")
            {
                _ForceChainCellDispEx(sPass, null, -1);
            }

            return(SolCode > 0);
        }
        private bool _ForceChainCellDispEx(Bit81[] sPass, Bit81[] sTrue, int rc0)       //q
        {
            string dspOpt = GNPXApp000.GMthdOption["ForceLx"];

            if (rc0 < 0)    //dspOpt:"ForceL2"
            {
                Result = ResultLong = "ForceChain_Cell";
                if (__SimpleAnalizerB__)
                {
                    return(true);
                }
                pAnMan.SnapSaveGP(true);
                return(SolCode > 0);
            }

            UCell  P0 = pBDL[rc0];
            string st0 = "", st2 = "";

            for (int nox = 0; nox < 9; nox++)
            {
                if (sTrue[nox].IsZero())
                {
                    continue;
                }

                foreach (var rc in sTrue[nox].IEGet_rc())
                {
                    if (sPass[nox].IsHit(rc))
                    {
                        continue;
                    }
                    sPass[nox].BPSet(rc);

                    UCell Q = pBDL[rc];
                    Q.FixedNo = nox + 1;
                    int elm = Q.FreeB.DifSet(1 << nox);
                    Q.CancelB = elm;
                    SolCode   = 1;

                    if (SolInfoB)                       //SolInfoB:Flag whether to generate solution information
                    {
                        if (dspOpt != "ForceL2")
                        {
                            P0.SetNoBBgColor(P0.FreeB, Colors.Green, Colors.Yellow);
                        }
                        Q.SetNoBBgColor(1 << nox, Colors.Red, Colors.LightGreen);
                        Q.SetNoBColorRev(elm, Colors.Red);

                        st0 = $"ForceChain_Cell r{(Q.r+1)}c{(Q.c+1)}/{(nox+1)} is true";    //st0:Title of each solution

                        string st1 = "";
                        foreach (var no in pBDL[rc0].FreeB.IEGet_BtoNo())
                        {
                            USuperLink USLK = pSprLKsMan.get_L2SprLKEx(rc0, no, FullSearchB: false, DevelopB: false);
                            st1 += "\r" + pSprLKsMan._GenMessage2true(USLK, Q, nox);          //st1:Exact GroupedLink path
                        }
                        st2     = st0 + st1;                                                  //st2:Description of each solution
                        Result  = ResultLong = st0;
                        extRes += "\r" + st2;                                                 //(Description of each solution)
                        extRes  = extRes.TrimStart();

                        if (dspOpt == "ForceL0")
                        {
                            if (__SimpleAnalizerB__)
                            {
                                return(true);
                            }
                            if (!pAnMan.SnapSaveGP(false))
                            {
                                return(true);
                            }
                            extRes = ""; st2 = "";
                        }
                    }
                }
                if (SolInfoB && dspOpt == "ForceL1" && st2 != "")
                {
                    Result = ResultLong = $"ForceChain_Cell (#{nox+1})";

                    if (__SimpleAnalizerB__)
                    {
                        return(true);
                    }
                    if (!pAnMan.SnapSaveGP(false))
                    {
                        return(true);
                    }
                    st2    = "";
                    extRes = "";
                }
            }
            return(SolCode > 0);
        }
        public USuperLink GNL_EvalSuperLinkChain(GroupedLink GLK_000, int rc0, bool DevelopB = false)
        {
            try{
                if (DevelopB)
                {
                    WriteLine("\r\r10 *1st:" + GLK_000.GrLKToString()); __Debug_ChainPrint(GLK_000);
                }
                int dbX = 0;
                _dbCC = 0;

                int        no0        = GLK_000.no;
                USuperLink GNL_Result = new USuperLink(rc0, no0);
                var        Qtrue      = GNL_Result.Qtrue;
                var        Qfalse     = GNL_Result.Qfalse;
                Qtrue  = GNL_Result.Qtrue;
                Qfalse = GNL_Result.Qfalse;
                var rcQue = new Queue <GroupedLink>();

                GLK_000.preGrpedLink = null;                                            //sentinel(right GroupedLink's preGrpedLink is null)
                GLK_000.UsedCs       = GLK_000.UGCellsB.B81;                            //Set Used

                int contDiscontF = 0;
                rcQue.Enqueue(GLK_000); //Enqueue first GLK

                {                       //====================== First GLK Process ==============================================================
                    GroupedLink RR = GLK_000;
                    int         no2 = RR.no2, no2B = 1 << no2;
                    if (RR.type == S)                       //---------- Check connection conditions. case StrongLink(F->T) ----------
                    {
                        if (RR.UGCellsB.Count == 1)         //if the link's next element is a single cell
                        {
                            UCell RRnxtC = RR.UGCellsB[0];  //RRnxtC:next cell
                            Qtrue[no2].BPSet(RRnxtC.rc);    //set RRnxtC.rc#no2 is true
                            foreach (int nox in RRnxtC.FreeB.IEGet_BtoNo().Where(q => (q != no2)))
                            {
                                Qfalse[nox].BPSet(RRnxtC.rc);                             //set RRnxtC.rc#no2 to false
                                GroupedLink RRR = new GroupedLink(RRnxtC, no2, nox, W);   //GLK_ViVal:GLink in cell(RRnxtC#no2 WeakLink)
                                RRR.preGrpedLink = RR;                                    //set preLink
                                rcQue.Enqueue(RRR);                                       //enqueue next-GLink to RadiationSearchQueue
                                if (DevelopB)
                                {
                                    WriteLine($"        11 S ->RRnxtC[rc:{RRnxtC.rc}]#{nox} is false."); __Debug_ChainPrint(RRR);
                                }
                            }
                        }
                    }
                    else if (RR.type == W)               //---------- Check connection conditions. case WeakLink(T->F) ----------
                    {
                        foreach (UCell P in RR.UGCellsB) //foreach next GLink
                        {
                            if ((P.FreeB & no2B) > 0)
                            {
                                Qfalse[no2].BPSet(P.rc);                                //set P.rc#no2 is true
                                if (DevelopB)
                                {
                                    WriteLine($"        12 W *Rad->{P}   #{no2} is false.");
                                }
                            }
                        }
                    }
                }

                //====================== Radiation Search ==============================================================
                while (rcQue.Count > 0)
                {
                    {   //----- Distinct -----
                        var Q2 = rcQue.ToList().Distinct();
                        rcQue.Clear();
                        foreach (var X in Q2)
                        {
                            rcQue.Enqueue(X);
                        }
                        //if(DevelopB){ WriteLine(); foreach(var P in rcQue) WriteLine($"--rcQue---{P.GrLKToString()}"); WriteLine(); }
                    }

                    GroupedLink R = rcQue.Dequeue();                                                            //dequeue next element(pre-GLink)
                    if (DevelopB)
                    {
                        WriteLine($"\r20�� {dbX++}---Queue:" + R.GrLKToString()); __Debug_ChainPrint(R);
                    }

                    foreach (GroupedLink RR in IEGet_SuperLink(R).Where(p => p.AvailableF))
                    {
                        if (_IsLooped(RR))
                        {
                            continue;
                        }
                        if (R.type != RR.type && R.UGCellsA.Equals(RR.UGCellsB))
                        {
                            continue;                                                                               //Skip back_links
                        }
                        if (!(R.UsedCs & RR.UGCellsB.B81).IsZero())
                        {
                            continue;
                        }
                        RR.preGrpedLink = R;                                                //set preLink
                        RR.UsedCs       = R.UsedCs | RR.UGCellsB.B81;
                        rcQue.Enqueue(RR);                                                  //enqueue next-GLink to RadiationSearchQueue
                        if (DevelopB)
                        {
                            __Debug_ChainPrint(RR); WriteLine($"��   {dbX++}-{++chkX}--RR:" + RR.GrLKToString());
                        }

                        int no2 = RR.no2; //no2:next digit
                        if (RR.type == S) //========== Check connection conditions. case StrongLink(F->T) ==========
                        //if(!(RR.UGCellsB.B81&Qtrue[RR.no2]).IsZero() )  continue;   //xxx if the next element is already setted true, go to the next process
                        {
                            if (RR.UGCellsB.Count == 1)                                        //if the link's next element is a single cell
                            {
                                UCell P = RR.UGCellsB[0];                                      //RRnxtC:next cell

                                if (P.rc == rc0)                                               //Check Loop completion
                                {
                                    GNL_Result.resultGLK = RR;
                                    SolCode = GroupedNLEx_CheckSolution(GNL_Result, ref contDiscontF);  //There are cells/#n that can be excluded.
                                    if (SolCode > 0)
                                    {
                                        goto  LoopCompletion;                               //Established Sudoku solution
                                    }
                                    goto ErrorTrial;                                        //Failed
                                }

                                if (Qtrue[no2].IsHit(P.rc))
                                {
                                    RR.AvailableF = false; continue;
                                }                                                           //AvailableF=false
                                Qtrue[no2].BPSet(P.rc);                                     // set P.rc#no2 is true
                                if (DevelopB)
                                {
                                    WriteLine($"        30S ->P:{P}  +#{no2} is true.");
                                }

                                foreach (int nox in P.FreeB.IEGet_BtoNo().Where(q => (q != no2)))                               // P.rc#no2:True => #nox(!=no2):False
                                {
                                    if (Qfalse[nox].IsHit(P.rc))
                                    {
                                        continue;
                                    }
                                    Qfalse[nox].BPSet(P.rc);                                //set P.rc#no2 to false
                                    if (DevelopB)
                                    {
                                        WriteLine($"        31S ->P:{P}  -#{nox} is false.");
                                    }
                                }
                            }
                        }

                        else if (RR.type == W)                         //========== Check connection conditions. case WeakLink(T->F) ==========
                        {
                            if (!(RR.UGCellsB.B81 & Qfalse[RR.no2]).IsZero())
                            {
                                continue;                                                                               //if the next element is setted false, go to the next process
                            }
                            foreach (UCell P in RR.UGCellsB)                                                            //foreach next GLink
                            {
                                if (Qfalse[no2].IsHit(P.rc))
                                {
                                    continue;
                                }
                                Qfalse[no2].BPSet(P.rc);                                                                    //set P.rc#no2 is true
                                if (DevelopB)
                                {
                                    WriteLine($"       -40W *RR:{P}  -#{no2} is false.");
                                }
                            }
                            rcQue.Enqueue(RR);                                              //enqueue next-GLink to RadiationSearchQueue

                            if (RR.UGCellsB.Count == 1)                                     //if the link's next element is a single cell
                            {
                                UCell P = RR.UGCellsB[0];
                                if (P.FreeBC == 2)                                                                          //If the next is a binary cell
                                {
                                    int nox = P.FreeB.DifSet(1 << no2).BitToNum();
                                    //if(!_Check_LogicalError_GNL(no2,P.rc,Qtrue) )  goto ErrorTrial; //No check required!
                                    //if(Qtrue[nox].IsHit(P.rc)){ RR.AvailableF=false; continue; }//AvailableF=false. No check required!
                                    Qtrue[nox].BPSet(P.rc);                                   //set P.rc#no2 is true

                                    GroupedLink RRR = new GroupedLink(P, no2, nox, S);        //GLK_ViVal:GLink in cell(P#no2 StrongLink)
                                    RRR.preGrpedLink = RR;                                    //set preLink
                                    if (DevelopB)
                                    {
                                        WriteLine($"       +41W *RR:{P}  -#{nox} is true. :{RRR.GrLKToString()}");
                                    }

                                    if (P.rc == rc0)
                                    {
                                        GNL_Result.resultGLK = RR;
                                        SolCode = GroupedNLEx_CheckSolution(GNL_Result, ref contDiscontF);
                                        if (SolCode > 0)
                                        {
                                            goto  LoopCompletion;                          //Solution found
                                        }
                                        goto ErrorTrial;
                                    }
                                }
                            }
                        }
                    }
                }
                return(null);

ErrorTrial:
                return(null);

LoopCompletion:
                GNL_Result.contDiscontF = contDiscontF;

                if (DevelopB)
                {
                    L2SprLkB81[no0].BPSet(rc0);                                                        // Set the searched flag
                    if (DevelopB)
                    {
                        developDisp(rc0, no0, GNL_Result, DevelopB);
                    }
                    L2SprLK[rc0, no0] = GNL_Result;
                }

                return(GNL_Result);
            }
            catch (Exception ex) {
                WriteLine($"{ex.Message}+\r{ex.StackTrace}");
            }
            return(null);
        }
        //##### There is a bug #####
        public USuperLink Eval_SuperLinkChain(int rc0, int no0, bool Gbreak, int typeSel, bool DevelopB)
        {
            try{
                int dbX = 0;

                USuperLink USLK        = new USuperLink(rc0, no0);
                var        Qtrue       = USLK.Qtrue;
                var        Qfalse      = USLK.Qfalse;
                var        chainDesLKT = USLK.chainDesLKT;
                var        chainDesLKF = USLK.chainDesLKF;
                var        rcQue       = new Queue <GroupedLink>();

                UCell P0   = pBDL[rc0];                 //Origin Cell
                int   no0B = 1 << no0;                  //Origin Digit
                Qtrue[no0].BPSet(rc0);
                GroupedLink GLKnoR0 = new GroupedLink(P0, no0, no0, W, rootF: true);
                GLKnoR0.preGrpedLink  = null;
                chainDesLKT[rc0, no0] = GLKnoR0;

                if ((typeSel & 2) > 0)//====================== Start with WeakLink(origin:rc#no0) ======================
                {
                    foreach (var GLKH in IEGet_SuperLinkFirst(P0, no0).Where(X => X.type == W))
                    {
                        if (DevelopB)
                        {
                            WriteLine("*1st:" + GLKH.GrLKToString());
                        }
                        GLKH.UsedCs      |= GLKH.UGCellsB.B81;                                          //set usedcells(accumulate)
                        GLKH.preGrpedLink = GLKnoR0;                                                    //set pre-GLink
                        rcQue.Enqueue(GLKH);                                                            //enqueue next-GLink to RadiationSearchQueue

                        foreach (var P in GLKH.UGCellsB.Where(p => (p.FreeB & no0B) > 0))
                        {
                            int no2 = GLKH.no2;
                            Qfalse[no2].BPSet(P.rc);                                                            //set p.rc#no2 to false
                            chainDesLKF[P.rc, no2] = GLKH;                                                      //record in retroactive chain
                            if (Gbreak && Qtrue[no2].IsHit(P.rc) && GenMessage2(USLK, pBDL[P.rc], no2))
                            {
                                goto FTBreak;                                                                   //found error
                            }
                            if (P.FreeBC == 2)                                                                  //If the next is a binary cell
                            {
                                int nox = P.FreeB.DifSet(1 << no2).BitToNum();                                  //nox:another digit in the cell
                                Qtrue[nox].BPSet(P.rc);                                                         //P.rc#nox is true
                                GroupedLink GLKbv = new GroupedLink(P, no2, nox, S);                            //GLKbv:GLink in cell
                                GLKbv.preGrpedLink     = GLKH;                                                  //set preLink
                                chainDesLKT[P.rc, nox] = GLKbv;                                                 //record in retroactive chain
                                if (DevelopB)
                                {
                                    WriteLine($"        12 W *Rad->{P}  --#{no2} is false.");
                                }
                                if (Gbreak && Qfalse[nox].IsHit(P.rc) && GenMessage2(USLK, pBDL[P.rc], nox))
                                {
                                    goto FTBreak;                                                                                                         //found error
                                }
                            }
                        }
                    }

                    //S start cell, non-conscious digits
                    foreach (var nox in P0.FreeB.IEGet_BtoNo().Where(n => (n != no0)))              //non-conscious digits in originCell
                    {
                        Qfalse[nox].BPSet(rc0);                                                     // is false
                    }
                }

                if ((typeSel & 1) > 0)//====================== Start with StrongLink(origin:rc#no0) ======================
                {
                    foreach (var GLKH in IEGet_SuperLinkFirst(P0, no0).Where(X => X.type == S))
                    {
                        int         nox     = GLKH.no2;
                        GroupedLink GLKnoR1 = new GroupedLink(P0, no0, nox, W, rootF: false);           //nextGLink
                        GLKnoR1.preGrpedLink  = GLKnoR0;                                                //set pre-GLink to next-GLink
                        chainDesLKF[rc0, nox] = GLKnoR1;                                                //record in retroactive chain

                        GLKH.UsedCs      |= GLKH.UGCellsB.B81;                                          //set usedcells(accumulate)
                        GLKH.preGrpedLink = GLKnoR1;                                                    //set pre-GLink
                        rcQue.Enqueue(GLKH);                                                            //enqueue next-GLink to RadialSearchQueue
                        if (GLKH.UGCellsB.Count == 1)                                                   //if the link's next element is a single cell
                        {
                            int no2 = GLKH.no2;                                                         //no2:next digit
                            var P   = GLKH.UGCellsB[0];                                                 //P:next cell
                            Qtrue[no2].BPSet(P.rc);                                                     //set P.rc#no2 is true
                            chainDesLKT[P.rc, no2] = GLKH;                                              //record in retroactive chain
                            if (Gbreak && Qfalse[no2].IsHit(P.rc) && GenMessage2(USLK, pBDL[P.rc], no2))
                            {
                                goto FTBreak;                                                                 //found error
                            }
                            Qtrue[nox].BPSet(P.rc);                                                           //set P.rc#no is true

                            GroupedLink GLKno = new GroupedLink(P, nox, no2, W);                              //GLKno:GLink in cell
                            GLKno.preGrpedLink     = GLKH;                                                    //set preLink
                            chainDesLKF[P.rc, no2] = GLKno;                                                   //record in retroactive chain
                            if (Gbreak && Qtrue[nox].IsHit(P.rc) && GenMessage2(USLK, pBDL[P.rc], nox))
                            {
                                goto FTBreak;                                                                                                //found error
                            }
                        }
                    }
                }

                //====================== Radiation Search ===============================
                while (rcQue.Count > 0)
                {
                    GroupedLink R = rcQue.Dequeue();                                                                //dequeue next element
                    if (DevelopB)
                    {
                        WriteLine($"{dbX++}---Queue:" + R.GrLKToString());
                    }

                    foreach (var GLKH in IEGet_SuperLink(R))                                    //foreach next GLink
                    {
                        if (DevelopB)
                        {
                            WriteLine($"   {dbX++}--GLKH:" + GLKH.GrLKToString());
                        }
                        if (R.type != GLKH.type && R.UGCellsA.Equals(GLKH.UGCellsB))
                        {
                            continue;                                                                               //Skip back links
                        }
                        GLKH.preGrpedLink = R;                                                                      //set preLink
                        int no2 = GLKH.no2;                                                                         //no2:next digit
                        if (GLKH.type == S)                                                                         //Check connection conditions. case StrongLink
                        {
                            if (!(GLKH.UGCellsB.B81 & Qtrue[GLKH.no2]).IsZero())
                            {
                                continue;                                                                               //if the next element is setted true, go to the next process
                            }
                            if (GLKH.UGCellsB.Count == 1)                                                               //if the link's next element is a single cell
                            {
                                var P = GLKH.UGCellsB[0];                                                               //P:next cell
                                Qtrue[no2].BPSet(P.rc);                                                                 //set P.rc#no2 is true
                                chainDesLKT[P.rc, no2] = GLKH;                                                          //record in retroactive chain
                                if (Gbreak && Qfalse[no2].IsHit(P.rc) && GenMessage2(USLK, pBDL[P.rc], no2))
                                {
                                    goto FTBreak;                                                                                                         //found error
                                }
                                foreach (var nox in P.FreeB.IEGet_BtoNo().Where(q => (q != no2)))
                                {
                                    Qfalse[nox].BPSet(P.rc);                                                                      //set p.rc#no2 to false
                                    GroupedLink GLKno = new GroupedLink(P, no2, nox, W);                                          //GLKbv:GLink in cell(P#no2 WeakLink)
                                    GLKno.preGrpedLink     = GLKH;                                                                //set preLink
                                    chainDesLKF[P.rc, nox] = GLKno;                                                               //record in retroactive chain

                                    if (Gbreak && Qtrue[nox].IsHit(P.rc) && GenMessage2(USLK, pBDL[P.rc], nox))
                                    {
                                        goto FTBreak;                                                                                                            //found error
                                    }
                                    if (DevelopB)
                                    {
                                        WriteLine($"        31S ->P:{P}  --#{nox} is false.");
                                    }
                                }
                            }
                        }
                        if (GLKH.type == W)                                                                         //Check connection conditions. case WeakLink
                        {
                            if (!(GLKH.UGCellsB.B81 & Qfalse[GLKH.no2]).IsZero())
                            {
                                continue;                                                                               //if the next element is setted false, go to the next process
                            }
                            foreach (var P in GLKH.UGCellsB)                                                            //foreach next GLink
                            {
                                Qfalse[no2].BPSet(P.rc);                                                                //set P.rc#no2 is true
                                chainDesLKF[P.rc, no2] = GLKH;                                                          //record in retroactive chain
                                if (Gbreak && Qtrue[no2].IsHit(P.rc) && GenMessage2(USLK, pBDL[P.rc], no2))
                                {
                                    goto FTBreak;                                                                                                        //found error
                                }
                                if (DevelopB)
                                {
                                    WriteLine($"        40S ->P:{P}  ++#{no2} is false.");
                                }
                            }

                            if (GLKH.UGCellsB.Count == 1)                                                               //if the link's next element is a single cell
                            {
                                var P = GLKH.UGCellsB[0];
                                if (P.FreeBC == 2)                                                                            //If the next is a binary cell
                                {
                                    int nox = P.FreeB.DifSet(1 << no2).BitToNum();
                                    Qtrue[nox].BPSet(P.rc);                                                                                   //set P.rc#no2 is true
                                    if (DevelopB)
                                    {
                                        WriteLine($"        41S ->P:{P}  ++#{nox} is true.");
                                    }
                                    GroupedLink GLKno = new GroupedLink(P, no2, nox, S);                                          //GLKbv:GLink in cell(P#no2 StrongLink)
                                    GLKno.preGrpedLink     = GLKH;                                                                //set preLink
                                    chainDesLKT[P.rc, nox] = GLKno;                                                               //record in retroactive chain
                                    if (Gbreak && Qfalse[nox].IsHit(P.rc) && GenMessage2(USLK, pBDL[P.rc], nox))
                                    {
                                        goto FTBreak;                                                                                                             //found error
                                    }
                                }
                            }
                        }
                        rcQue.Enqueue(GLKH);                                                                        //enqueue next-GLink to RadiationSearchQueue
                    }
                }

                USLK.SolFound = true;                                                                       //Solution found
                return(USLK);

FTBreak:        //Failed
                USLK.SolFound = false;
                return(USLK);
            }
            catch (Exception ex) {
                WriteLine($"{ex.Message}+\r{ex.StackTrace}");
            }
            return(null);
        }
        public bool ForceChain_HouseEx( )
        {
            if (GNPXApp000.GMthdOption["ForceChainCellHouseOn"] != "1")
            {
                return(false);
            }

            GroupedLink._IDsetB = false;  //ID set for debug

            Prepare();
            pSprLKsMan.PrepareSuperLinkMan(AllF: true);
            string dspOpt = GNPXApp000.GMthdOption["ForceLx"];

            Bit81[] sPass = new Bit81[9];
            for (int k = 0; k < 9; k++)
            {
                sPass[k] = new Bit81();
            }

            bool solvedA = false;

            for (int hs0 = 0; hs0 < 27; hs0++)
            {
                int noBs = pBDL.IEGetCellInHouse(hs0).Aggregate(0, (Q, P) => Q | (P.FreeB));

                bool solvedB = false;
                foreach (var no0 in noBs.IEGet_BtoNo())
                {
                    int     noB   = (1 << no0);
                    Bit81[] sTrue = new Bit81[9];
                    for (int k = 0; k < 9; k++)
                    {
                        sTrue[k] = new Bit81(all_1: true);
                    }

                    foreach (var P0 in pBDL.IEGetCellInHouse(hs0, noB))
                    {
                        USuperLink USLK = pSprLKsMan.get_L2SprLK(P0.rc, no0, FullSearchB: false, DevelopB: false);
                        if (USLK == null || !USLK.SolFound)
                        {
                            goto nextSearch;
                        }

                        for (int k = 0; k < 9; k++)
                        {
                            sTrue[k] &= (USLK.Qtrue[k] - USLK.Qfalse[k]);
                            sTrue[k].BPReset(P0.rc);
                        }
                    }

                    for (int nox = 0; nox < 9; nox++)
                    {
                        if (!sTrue[nox].IsZero())
                        {
                            solvedB = true; break;
                        }
                    }

                    if (solvedB)
                    {
                        solvedA = true;
                        _ForceChainHouseDispEx(sPass, sTrue, hs0, no0);
                        if (!SDK_Ctrl.MltAnsSearch && dspOpt == "ForceL0")
                        {
                            return(true);
                        }
                    }
                }

                if (solvedA && dspOpt == "ForceL1")
                {
                    _ForceChainHouseDispEx(sPass, null, hs0, -1);
                    if (!SDK_Ctrl.MltAnsSearch)
                    {
                        return(true);
                    }
                }

nextSearch:
                continue;
            }
            if (solvedA && !SDK_Ctrl.MltAnsSearch && dspOpt == "ForceL2")
            {
                _ForceChainHouseDispEx(sPass, null, -1, -1);
            }

            return(SolCode > 0);
        }
        public string _chainToStringGNL(USuperLink GNL_Result, ref string st3)
        {
            string st = "";

            if (GNL_Result == null)
            {
                return(st);
            }

            GroupedLink GLKnxt = GNL_Result.resultGLK;
            //pSprLKsMan.Debug_ChainPrint(GLKnxt);
            var         SolLst = pSprLKsMan.Convert_ChainToList_GNL(GNL_Result);
            GroupedLink GLKorg = SolLst[0];

            {//===================== cells coloring ===========================
                foreach (var LK in SolLst)
                {
                    bool bALK = LK is ALSLink;
                    int  type = (LK is ALSLink)? S: LK.type;//ALSLink, in ALS, is S
                    foreach (var P1 in LK.UGCellsA.Select(p => pBDL[p.rc]))
                    {
                        //WriteLine($"---------- {P1}");
                        int noB = (1 << LK.no);
                        if (!bALK)
                        {
                            P1.SetCellBgColor(SolBkCr);
                        }
                        if (type == S)
                        {
                            P1.SetNoBColor(noB, AttCr2);
                        }
                        else
                        {
                            P1.SetNoBColor(noB, AttCr3);
                        }
                    }

                    if (type == W)
                    {
                        foreach (var P2 in LK.UGCellsB.Select(p => pBDL[p.rc]))
                        {
                            int noB2 = (1 << LK.no);
                            if (!bALK)
                            {
                                P2.SetCellBgColor(SolBkCr);
                            }
                            P2.SetNoBColor(noB2, AttCr);
                        }
                    }
                }

                int cx = 2;
                foreach (var LK in SolLst)      // ALS
                {
                    ALSLink ALK = LK as ALSLink;
                    if (ALK == null)
                    {
                        continue;
                    }
                    Color crG = _ColorsLst[cx++];
                    foreach (var P in ALK.ALSbase.B81.IEGet_rc().Select(rc => pBDL[rc]))
                    {
                        P.SetCellBgColor(crG);
                    }
                }
            }

            {//===================== result report ===========================
                st3 = "";
                int SolType = GNL_Result.contDiscontF;
                if (SolType == 1)
                {
                    st = "Nice Loop(Cont.)";             //<>continuous
                }
                else                                     //<>discontinuous
                {
                    int rc = GLKorg.UGCellsA[0].rc;
                    var P  = pBDL[rc];
                    st = "Nice Loop(Discont.) r" + (rc / 9 + 1) + "c" + (rc % 9 + 1);
                    int dcTyp = GLKorg.type * 10 + GLKnxt.type;
                    switch (dcTyp)
                    {
                    case 11: st += $" is {(GLKorg.no+1)}";     P.SetCellBgColor(SolBkCr2); break;

                    case 12: st += $" is not {(GLKnxt.no+1)}"; P.CancelB = 1 << GLKnxt.no; break;

                    case 21: st += $" is not {(GLKorg.no+1)}"; P.CancelB = 1 << GLKorg.no; break;

                    case 22: st += $" is not {(GLKorg.no+1)}"; P.CancelB = 1 << GLKorg.no; break;
                    }
                }

                string st2 = __chainToStringGNLsub(SolLst, ref st3);
                st         = st3 + st;
                Result     = st;
                ResultLong = st + "\r" + st2;
            }
            return(st);
        }
        public bool ForceChain_ContradictionEx( )
        {
            GroupedLink._IDsetB = false;  //ID set for debug
            string dspOpt = GNPXApp000.GMthdOption["ForceLx"];
            string st0 = "", st2 = "";

            Prepare();
            pSprLKsMan.PrepareSuperLinkMan(AllF: true);
            Bit81[] GLC = new Bit81[9];
            for (int k = 0; k < 9; k++)
            {
                GLC[k] = new Bit81();
            }

            foreach (var P0 in pBDL.Where(p => p.No == 0))
            {
                foreach (var no in P0.FreeB.IEGet_BtoNo())
                {
                    int        noB  = (1 << no);
                    USuperLink USLK = pSprLKsMan.get_L2SprLKEx(P0.rc, no, FullSearchB: false, DevelopB: false);
                    if (USLK != null)
                    {
                        Bit81 sContradict = new Bit81();

                        for (int k = 0; k < 9; k++)
                        {
                            sContradict = USLK.Qtrue[k] & USLK.Qfalse[k];
                            if (sContradict.IsZero())
                            {
                                continue;
                            }

                            foreach (var Q in sContradict.IEGet_rc().Select(rc => pBDL[rc]))
                            {
                                P0.CancelB |= noB;
                                P0.SetCellBgColor(Colors.LightGreen);
                                int E = P0.FreeB.DifSet(P0.CancelB);
                                SolCode = (E.BitCount() == 1)? 1: 2;

                                if (SolInfoB)
                                {
                                    if (dspOpt != "ForceL2")
                                    {
                                        Q.SetNoBBgColor(Q.FreeB, Colors.Green, Colors.Yellow);
                                    }
                                    P0.SetNoBColorRev(noB, Colors.Red);
                                    if (E.BitCount() == 1)
                                    {
                                        P0.SetNoBColor(E, Colors.Red);
                                    }
                                    GLC[no].BPSet(P0.rc);
                                    st0    = $"ForceChain_Contradiction r{(P0.r+1)}c{(P0.c+1)}/#{(no+1)} is false";
                                    Result = ResultLong = st0;

                                    string stX = pSprLKsMan._GenMessage2true(USLK, Q, k);
                                    stX += "\r" + pSprLKsMan._GenMessage2false(USLK, Q, k);

                                    if (st2 != "")
                                    {
                                        st2 += "\r";
                                    }
                                    st2   += (st0 + "\r" + stX);
                                    st2    = st2.Trim();
                                    extRes = st2;
                                    if (dspOpt == "ForceL0")
                                    {
                                        if (__SimpleAnalizerB__)
                                        {
                                            return(true);
                                        }
                                        if (!pAnMan.SnapSaveGP(false))
                                        {
                                            return(true);
                                        }
                                        st2 = "";
                                    }
                                }
                                goto LNextSearch;      //One contradictory cell is enough
                            }
                        }
                    }

LNextSearch:
                    if (SolInfoB && dspOpt == "ForceL1" && st2 != "")
                    {
                        Result = ResultLong = $"ForceChain_Contradiction {P0.rc.ToRCString()}";
                        extRes = st2;
                        if (__SimpleAnalizerB__)
                        {
                            return(true);
                        }
                        if (!pAnMan.SnapSaveGP(false))
                        {
                            return(true);
                        }
                        st2 = "";
                    }
                }
            }
            if (SolInfoB && dspOpt == "ForceL2" && st2 != "")
            {
                Result = ResultLong = "ForceChain_Contradiction";
                extRes = st2;
                if (__SimpleAnalizerB__)
                {
                    return(true);
                }
                if (!pAnMan.SnapSaveGP(false))
                {
                    return(true);
                }
            }
            _developDisp2Ex(GLC);                                                       //37
            return(SolCode > 0);
        }
        //Search for groupedLink_sequence starting from rc0#no0 as true.
        public USuperLink Eval_SuperLinkChainEx(int rc0, int no0, bool DevelopB)
        {
            try{
                int dbX = 0;
                _dbCC = 0;

                USuperLink GNL_Result  = new USuperLink(rc0, no0);
                var        Qtrue       = GNL_Result.Qtrue;
                var        Qfalse      = GNL_Result.Qfalse;
                var        chainDesLKT = GNL_Result.chainDesLKT;
                var        chainDesLKF = GNL_Result.chainDesLKF;

                var rcQue = new Queue <GroupedLink>();

                UCell P0   = pBDL[rc0];                 //Origin Cell
                int   no0B = 1 << no0;                  //Origin Digit
                Qtrue[no0].BPSet(rc0);

                //P is Cell.  R,RR,RRR is GroupedLink
                {//====================== Start with WeakLink(origin:rc#no0) ======================
                    foreach (var R in IEGet_SuperLinkFirst(P0, no0).Where(X => X.type == W))
                    {
                        if (DevelopB)
                        {
                            Write("*1st:" + R.GrLKToString()); __Debug_ChainPrint(R);
                        }

                        R.UsedCs       = R.UGCellsA.B81;            //set usedcells(accumulate)
                        R.preGrpedLink = null;                      //GLKnoR0;                              //set pre-GLink
                        rcQue.Enqueue(R);                           //enqueue next-GLink to RadiationSearchQueue

                        foreach (var P in R.UGCellsB.Where(p => (p.FreeB & no0B) > 0))
                        {
                            int no2 = R.no2;
                            Qfalse[no2].BPSet(P.rc);                              //set p.rc#no2 to false
                            chainDesLKF[P.rc, no2] = R;                           //��                              //record in retroactive chain
                            if (DevelopB)
                            {
                                WriteLine($"        12 W *Rad->{P}  --#{no2} is false.");
                            }
                        }
                    }
                    foreach (var nox in pBDL[rc0].FreeB.IEGet_BtoNo().Where(p => p != no0))
                    {
                        Qfalse[nox].BPSet(rc0);
                    }
                }

                //====================== Radiation Search ===============================
                while (rcQue.Count > 0)
                {
                    {   //----- Distinct -----
                        var Q2 = rcQue.ToList().Distinct();
                        rcQue.Clear();
                        foreach (var X in Q2)
                        {
                            rcQue.Enqueue(X);
                        }
                        //if(DevelopB){ WriteLine(); foreach(var P in rcQue) WriteLine($"--rcQue---{P.GrLKToString()}"); WriteLine(); }
                    }

                    GroupedLink R = rcQue.Dequeue();                                                         //dequeue next element
                    if (DevelopB)
                    {
                        WriteLine($"\r{dbX++}---Queue:" + R.GrLKToString());
                    }

                    foreach (var RR in IEGet_SuperLink(R).Where(p => p.AvailableF)) //foreach next GLink
                    {
                        RR.preGrpedLink = R;                                        //set preLink
                        if (!(R.UsedCs & RR.UGCellsB.B81).IsZero())
                        {
                            continue;                                                    //Skip by used Cells
                        }
                        if (DevelopB)
                        {
                            WriteLine($"\r   {dbX++}--RR:" + RR.GrLKToString());
                        }

                        RR.UsedCs = R.UsedCs | RR.UGCellsA.B81;
                        if (DevelopB)
                        {
                            __Debug_ChainPrint(RR); WriteLine($"��   {dbX++}-{++chkX}--RR:" + RR.GrLKToString());
                        }

                        int no2 = RR.no2;                               //no2:next digit
                        if (RR.type == S)                               // F->T   *=*=* Check connection conditions. case StrongLink *=*=*
                        {
                            if (RR.UGCellsB.Count == 1)                 //if the link's next element is a single cell
                            {
                                var P = RR.UGCellsB[0];                 //P:next cell
                                if (Qtrue[no2].IsHit(P.rc))
                                {
                                    continue;                                            //Already setted. Eliminate unnecessary trials and speed up.
                                }
                                Qtrue[no2].BPSet(P.rc);                                  //set P.rc#no2 is true
                                chainDesLKT[P.rc, no2] = RR;                             //record in retroactive chain
                                if (DevelopB)
                                {
                                    WriteLine($"        31S ->P:{P}  ++#{no2} is true.");
                                }

                                foreach (var nox in P.FreeB.IEGet_BtoNo().Where(q => (q != no2)))
                                {
                                    Qfalse[nox].BPSet(P.rc);                                                                 //set p.rc#nox to false
                                    if (DevelopB)
                                    {
                                        WriteLine($"        32S ->P:{P}  --#{nox} is false.");
                                    }
                                }
                            }
                        }

                        else if (RR.type == W)                          // T->F   *=*=* Check connection conditions. case WeakLink *=*=*
                        {
                            foreach (var P in RR.UGCellsB)              //foreach next GLink
                            {
                                Qfalse[no2].BPSet(P.rc);                //set P.rc#no2 is false
                                if (DevelopB)
                                {
                                    WriteLine($"        40W ->P:{P}  ++#{no2} is false.");
                                }
                                chainDesLKF[P.rc, no2] = RR;                                                             //record in retroactive chain
                            }

                            if (RR.UGCellsB.Count == 1)                                                              //if the link's next element is a single cell
                            {
                                var P = RR.UGCellsB[0];
                                if (P.FreeBC == 2)                                                                       //If the next is a binary cell
                                {
                                    int nox = P.FreeB.DifSet(1 << no2).BitToNum();
                                    if (Qtrue[nox].IsHit(P.rc))
                                    {
                                        continue;                                        //Already setted. Eliminate unnecessary trials and speed up.
                                    }
                                    Qtrue[nox].BPSet(P.rc);                              //set P.rc#no2 is true
                                    if (DevelopB)
                                    {
                                        WriteLine($"        41W ->P:{P}  ++#{nox} is true.");
                                    }

                                    GroupedLink RRR = new GroupedLink(P, no2, nox, S);                                       //GLKbv:GLink in cell(P#no2 StrongLink)
                                    RRR.preGrpedLink       = RR;                                                             //set preLink
                                    chainDesLKT[P.rc, nox] = RRR;                                                            //record in retroactive chain
                                }
                            }
                        }
                        rcQue.Enqueue(RR);                                                                       //enqueue next-GLink to RadiationSearchQueue                                              //enqueue next-GLink to RadiationSearchQueue
                    }
                }

                GNL_Result.SolFound = true;                                                              //Solution found
                return(GNL_Result);
            }
            catch (Exception ex) {
                WriteLine($"{ex.Message}+\r{ex.StackTrace}");
            }
            return(null);
        }
        public bool ExtKrFishSubEx(int sz, int no, int FMSize, bool FinnedF)
        {
            int BaseSel = 0x7FFFFFF, CoverSel = 0x7FFFFFF;
            int noB = (1 << no);

            string  krfSolMsg = "";
            FishMan FMan      = new FishMan(this, FMSize, no, sz, (sz >= 3));

            foreach (var Bas in FMan.IEGet_BaseSet(BaseSel, FinnedF:FinnedF))     //Generate BaseSet
            {
                foreach (var Cov in FMan.IEGet_CoverSet(Bas, CoverSel, FinnedF))  //Generate CoverSet
                {
                    Bit81 FinB81 = Cov.FinB81;
                    //dbCC++;//##############
                    if (FinnedF != FinB81.IsZero())
                    {
                        //WriteLine( $"dbCC:{dbCC} \rbas:{Bas.BaseB81}\rCov:{Cov.CoverB81}" );//######
                        //WriteLine( $"Bas.HouseB:{Bas.HouseB.ToBitString27()}");
                        //WriteLine( $"Cov.HouseB:{Cov.HouseC.ToBitString27()}");

                        Bit81 UsedB = Bas.BaseB81;
                        foreach (var Hb in Bas.HouseB.IEGet_BtoNo(27))
                        {
                            Bit81 E = Bas.BaseB81 & HouseCells[Hb];
                            if (FinnedF)
                            {
                                E |= FinB81;                                    //Finned
                            }
                            if (E.IsZero())
                            {
                                continue;
                            }

                            foreach (var P in pBDL.Where(p => !UsedB.IsHit(p.rc)))
                            {
                                foreach (var noZ in P.FreeB.IEGet_BtoNo())
                                {
                                    int        noZb = (1 << noZ);
                                    USuperLink USLK = pSprLKsMan.get_L2SprLKEx(P.rc, no, FullSearchB: false, DevelopB: false);
                                    //WriteLine( $" USuperLink rc:{P.rc} no:{noZ+1}" );
                                    if (!USLK.SolFound)
                                    {
                                        continue;
                                    }
                                    Bit81 Ef = E - USLK.Qfalse[no];
                                    if (!Ef.IsZero())
                                    {
                                        continue;
                                    }

                                    //Accurate analysis
                                    USLK = pSprLKsMan.get_L2SprLKEx(P.rc, noZ, FullSearchB: true, DevelopB: false);//#####
                                    Ef   = E - USLK.Qfalse[no];
                                    if (!Ef.IsZero())
                                    {
                                        continue;
                                    }
                                    P.CancelB |= noZb;
                                    SolCode    = 2;

                                    if (SolInfoB)
                                    {
                                        _KrFish_FishResultEx(no, sz, Bas, Cov);
                                        krfSolMsg += $"\r{_krfMsg2}  r{(P.r+1)}c{(P.c+1)}/{(noZ+1)} is false";
                                        foreach (var rc in E.IEGet_rc())
                                        {
                                            krfSolMsg += "\r" + pSprLKsMan._GenMessage2false(USLK, pBDL[rc], no);
                                        }
                                    }
                                    //goto LSolFound;
                                }
                            }

                            //	LSolFound:
                            if (SolCode > 0)
                            {
                                if (SolInfoB)
                                {
                                    extRes = krfSolMsg;
                                }
                                if (__SimpleAnalizerB__)
                                {
                                    return(true);
                                }
                                if (!pAnMan.SnapSaveGP(false))
                                {
                                    return(true);
                                }
                            }
                        }
                    }
                }
            }
            return(false);
        }
        private bool _ForceChainHouseDispEx(Bit81[] sPass, Bit81[] sTrue, int hs0, int no0)
        {
            string dspOpt = GNPXApp000.GMthdOption["ForceLx"];

            if (hs0 < 0)//  dspOpt:ForceL2"
            {
                Result = ResultLong = "ForceChain_House";
                if (__SimpleAnalizerB__)
                {
                    return(true);
                }
                pAnMan.SnapSaveGP(true);
                return(SolCode > 0);
            }


            string st0 = "", st2 = "";

            for (int nox = 0; nox < 9; nox++)
            {
                if (sTrue != null)
                {
                    if (sTrue[nox].IsZero())
                    {
                        continue;
                    }

                    foreach (var rc in sTrue[nox].IEGet_rc())
                    {
                        if (sPass[nox].IsHit(rc))
                        {
                            continue;
                        }
                        sPass[nox].BPSet(rc);

                        UCell Q = pBDL[rc];
                        Q.FixedNo = nox + 1;
                        int elm = Q.FreeB.DifSet(1 << nox);
                        Q.CancelB = elm;
                        SolCode   = 1;

                        if (SolInfoB)
                        {
                            Q.SetNoBBgColor(1 << nox, Colors.Red, Colors.LightGreen);
                            Q.SetNoBColorRev(elm, Colors.Red);

                            st0 = $"ForceChain_House({_HouseToString(hs0)}/#{(no0+1)}) r{(Q.r+1)}c{(Q.c+1)}/#{(nox+1)} is true";
                            string st1 = "";
                            foreach (var P in pBDL.IEGetCellInHouse(hs0, 1 << no0))
                            {
                                USuperLink USLK = pSprLKsMan.get_L2SprLK(P.rc, no0, FullSearchB: true, DevelopB: false);                        //Accurate path
                                st1 += "\r" + pSprLKsMan._GenMessage2true(USLK, Q, nox);
                                if (dspOpt != "ForceL2")
                                {
                                    P.SetNoBBgColor(1 << no0, Colors.Green, Colors.Yellow);
                                }
                            }

                            st2     = st0 + st1;
                            extRes += "\r" + st2;                             //(Description of each solution)
                            extRes  = extRes.TrimStart();

                            if (dspOpt == "ForceL0")
                            {
                                Result = ResultLong = st0;
                                if (__SimpleAnalizerB__)
                                {
                                    return(true);
                                }
                                if (!pAnMan.SnapSaveGP(false))
                                {
                                    return(true);
                                }
                                extRes = ""; st2 = "";
                                if (!SDK_Ctrl.MltAnsSearch)
                                {
                                    return(true);
                                }
                            }
                        }
                    }
                }

                if (SolInfoB && dspOpt == "ForceL1" && st2 != "")
                {
                    st0    = $"ForceChain_House({_HouseToString(hs0)}/#{(no0+1)})";
                    Result = ResultLong = st0;
                    if (__SimpleAnalizerB__)
                    {
                        return(true);
                    }
                    if (!pAnMan.SnapSaveGP(false))
                    {
                        return(true);
                    }
                    extRes = ""; st2 = "";
                    if (!SDK_Ctrl.MltAnsSearch)
                    {
                        return(true);
                    }
                }
            }
            return(SolCode > 0);
        }