private void _NL_SolResult(UCellLink LK0, UCellLink LKnxt, Stack <UCellLink> SolStack, int SolType)
        {
            string st = "";

            List <UCellLink> SolLst = SolStack.ToList();

            SolLst.Reverse();
            SolLst.Add(LK0);

            foreach (var LK in SolLst)
            {
                int   noB = (1 << LK.no);
                UCell P1 = pBDL[LK.rc1], P2 = pBDL[LK.rc2];
                P2.SetCellBgColor(SolBkCr);
                if (LK.type == S)
                {
                    P1.SetNoBColor(noB, AttCr); P2.SetNoBColor(noB, AttCr3);
                }
                else
                {
                    P2.SetNoBColor(noB, AttCr); P1.SetNoBColor(noB, AttCr3);
                }
            }

            if (SolType == 1)
            {
                st = "Nice Loop(Continuous)";             //continuous
            }
            else                                          //discontinuous
            {
                st = $"Nice Loop(Discontinuous) r{(LK0.rc1/9+1)}c{(LK0.rc1%9+1)}";
                int dcTyp = LK0.type * 10 + LKnxt.type;
                switch (dcTyp)
                {
                case 11: st += $" is {(LK0.no+1)}";       break;    //S->S

                case 12: st += $" is not {(LKnxt.no+1)}"; break;    //S->W

                case 21: st += $" is not {(LK0.no+1)}";   break;    //W->S

                case 22: st += $" is not {(LK0.no+1)}";   break;    //W->W
                }
            }

            Result     = st;
            ResultLong = st + "\r" + _ToRCSequenceString(SolStack);
        }
Exemple #2
0
        private void _developDisp2Ex(Bit81[] GLC)
        {
            List <UCell> qBDL = new List <UCell>();

            pBDL.ForEach(p => qBDL.Add(p.Copy()));
            foreach (var P in qBDL.Where(q => q.FreeB > 0))
            {
                int E = 0;
                for (int n = 0; n < 9; n++)
                {
                    if (GLC[n].IsHit(P.rc))
                    {
                        E |= (1 << n);
                    }
                }
                if (E > 0)
                {
                    UCell Q = pBDL[P.rc];
                    P.SetNoBBgColor(E, Colors.White, Colors.PowderBlue);
                    P.SetNoBColorRev(E, Colors.Blue);

                    Q.SetNoBBgColor(E, Colors.White, Colors.PowderBlue);
                    Q.SetNoBColorRev(E, Colors.Red);
                    int sb = Q.FreeB.DifSet(E);
                    Q.CancelB = E;
                    if (sb.BitCount() == 1)
                    {
                        Q.FixedNo = sb.BitToNum() + 1;
                        SolCode   = 1;
                    }
                    else if (sb.BitCount() == 0)
                    {
                        Q.SetCellBgColor(Colors.Violet);
                    }
                }
            }
            devWin.Set_dev_GBoard(qBDL);
        }
        //XYwing is an algorithm that consists of two WeakLinks with common cells.
        //http://csdenpe.web.fc2.com/page42.html
        public bool XYwing( )
        {
            Prepare();
            CeLKMan.PrepareCellLink(2);                                         //Generate WeakLinks

            if (BVCellLst == null)
            {
                BVCellLst = pBDL.FindAll(p => (p.FreeBC == 2));                 //Generate BVs(BV:bivalue).
            }
            if (BVCellLst.Count < 3)
            {
                return(false);
            }

            bool XYwing = false;

            foreach (var P0 in BVCellLst)                                       //Choose one BV_Cell(=>PS)
            {
                List <UCellLink> BVLKLst = CeLKMan.IEGetRcNoBTypB(P0.rc, 0x1FF, 2).Where(R => R.BVFlag).ToList();
                //Extract WeakLinks starting from P0
                //foreach( var P in BVLKLst ) WriteLine(P);
                if (BVLKLst.Count < 2)
                {
                    continue;
                }

                var cmb = new Combination(BVLKLst.Count, 2);
                int nxt = 1;
                while (cmb.Successor(nxt))                                              //Combine two WLinks from BVLKLst
                {
                    UCellLink LKA = BVLKLst[cmb.Index[0]], LKB = BVLKLst[cmb.Index[1]]; //(
                    UCell     Q = LKA.UCe2, R = LKB.UCe2;
                    if (Q.rc == R.rc || LKA.no == LKB.no)
                    {
                        continue;                                               //Two WLinks have different end and different digits
                    }
                    Bit81 Q81 = ConnectedCells[LKA.rc2] & ConnectedCells[LKB.rc2];
                    if (Q81.Count <= 0)
                    {
                        continue;                                               //Two WLinks have cells connected indirectly
                    }
                    int noB = Q.FreeB.DifSet(1 << LKA.no) & R.FreeB.DifSet(1 << LKB.no);
                    if (noB == 0)
                    {
                        continue;                                               //Two WLinks have common digit(=>no).
                    }
                    int no = noB.BitToNum();

                    string msg2 = "";
                    foreach (var A in Q81.IEGetUCeNoB(pBDL, noB))
                    {
                        if (A == P0 || A == Q || A == R)
                        {
                            continue;
                        }
                        A.CancelB = noB; XYwing = true;                             //cell(A)/digit(no) can be excluded
                        if (SolInfoB)
                        {
                            msg2 += $" {A.rc.ToRCNCLString()}(#{no+1})";
                        }
                    }

                    if (XYwing)
                    {
                        SolCode = 2;
                        P0.SetNoBColor(P0.FreeB, AttCr); P0.SetCellBgColor(SolBkCr);
                        Q.SetCellBgColor(SolBkCr); R.SetCellBgColor(SolBkCr);

                        string msg0 = $" Pivot: {_XYwingResSub(P0)}";
                        string msg1 = $" Pin: {_XYwingResSub(R)} ,{_XYwingResSub(Q)}";
                        Result = "XY Wing" + msg0;
                        if (SolInfoB)
                        {
                            ResultLong = $"XY Wing\r     {msg0}\r       {msg1}\r Eliminated:{msg2}";
                        }

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