private IEnumerable <Bit81[]> _Coloring(int no)
        {
            Bit81[] CRL = new Bit81[2];
            CRL[0] = new Bit81(); CRL[1] = new Bit81();
            Bit81 TBD = new Bit81(pBDL, (1 << no));
            int   rc1 = TBD.FindFirstrc();

            while (rc1 >= 0)
            {
                Queue <int> rcQue = new Queue <int>();
                rcQue.Enqueue(rc1 << 1);
                CRL[0].BPSet(rc1);
                TBD.BPReset(rc1);
                while (rcQue.Count > 0)
                {
                    rc1 = rcQue.Dequeue();
                    int kx = 1 - (rc1 & 1);
                    rc1 >>= 1;
                    TBD.BPReset(rc1);
                    foreach (var P in CeLKMan.IEGetRcNoType(rc1, no, 1))
                    {
                        int rc2 = P.rc2;
                        if (!(CRL[0] | CRL[1]).IsHit(rc2) && TBD.IsHit(rc2))
                        {
                            CRL[kx].BPSet(rc2); rcQue.Enqueue((rc2 << 1) | kx);
                        }
                    }
                }
                yield return(CRL);

                if ((rc1 = TBD.FindFirstrc()) < 0)
                {
                    yield break;
                }
                CRL    = new Bit81[2];
                CRL[0] = new Bit81(); CRL[1] = new Bit81();
            }
            yield break;
        }
        private IEnumerable <Bit81[]> _GetXChain(int no, List <int> LKRec)
        {
            Bit81 TBD = new Bit81(pBDL, (1 << no));

            int rcS;

            while ((rcS = TBD.FindFirstrc()) >= 0)                  //rcS:Set the origin cell.
            {
                TBD.BPReset(rcS);                                   //Reset TBD to Processed.

                //===== Repeatedly coloring processing. initialize =====
                Bit81[] CRL = new Bit81[3];                           //Coloring 2 groups(CRL[0] and CRL[1]).
                CRL[0]    = new Bit81(); CRL[1] = new Bit81(rcS); CRL[2] = new Bit81();
                CRL[0].ID = rcS;
                Queue <int> rcQue = new Queue <int>();
                rcQue.Enqueue((rcS << 1) | 1);                        //(First StrongLink)

                //===== Repeatedly coloring processing. start =====
                LKRec.Clear();                                      //clear chain recorder.
                bool firstLK = true;
                while (rcQue.Count > 0)
                {
                    int rcX = rcQue.Dequeue();                                     //recorded [cell and color]
                    int swF = 1 - (rcX & 1);                                       //next color(inversion S-W)
                    int rc1 = (rcX >> 1);                                          //next cell

                    foreach (var LKx in CeLKMan.IEGetRcNoType(rc1, no, (swF + 1))) //LKx:link connected to cell rc1
                    {
                        int rc2 = LKx.rc2;                                         //anather cell of LKx
                        if ((CRL[0] | CRL[1]).IsHit(rc2))
                        {
                            continue;                               //already colored
                        }
                        CRL[swF].BPSet(rc2);                        //coloring
                        rcQue.Enqueue((rc2 << 1) | swF);            //enqueue(next cell and color)
                        LKRec.Add(rc1 << 8 | rc2);                  //chain record
                        if (firstLK)
                        {
                            CRL[2].BPSet(rc2);                      //record colored cells from rcS(source cell)
                        }
                    }
                    firstLK = false;
                }
                if (CRL[1].Count > 0)
                {
                    yield return(CRL);
                }
                //----- Repeatedly coloring processing. end -----
            }
            yield break;
        }
示例#3
0
        private IEnumerable <Bit81[]> _RPColoring( )
        {
            if (BVCellLst.Count < 4)
            {
                yield break;
            }

            Bit81 TBD = new Bit81();

            BVCellLst.ForEach(p => TBD.BPSet(p.rc));

            int rc1;

            while ((rc1 = TBD.FindFirstrc()) >= 0)
            {
                Bit81[] CRL = new Bit81[2];
                CRL[0] = new Bit81(); CRL[1] = new Bit81();
                Queue <int> rcQue = new Queue <int>();
                rcQue.Enqueue(rc1 << 1);
                CRL[0].BPSet(rc1);
                int FreeB = pBDL[rc1].FreeB;
                CRL[0].ID = FreeB;

                while (rcQue.Count > 0)
                {
                    int rcX = rcQue.Dequeue();
                    int kx  = 1 - (rcX & 1);
                    rc1 = rcX >> 1;
                    TBD.BPReset(rc1);

                    Bit81 Chain = TBD & ConnectedCells[rc1];
                    foreach (var rc2 in Chain.IEGet_rc())
                    {
                        if (!TBD.IsHit(rc2))
                        {
                            continue;
                        }
                        if (pBDL[rc2].FreeB != FreeB)
                        {
                            continue;
                        }
                        rcQue.Enqueue((rc2 << 1) | kx);
                        CRL[kx].BPSet(rc2);
                        TBD.BPReset(rc2);
                    }
                }
                yield return(CRL);
            }
            yield break;
        }
示例#4
0
        public bool IsLinked9(Bit81 HB81)
        {
            Bit81 Colored = new Bit81(), Processed = new Bit81();
            int   rc0 = HB81.FindFirstrc();

            Colored.BPSet(rc0);
            while (true)
            {
                Bit81 T = Colored - Processed;
                if ((rc0 = T.FindFirstrc()) < 0)
                {
                    break;
                }

                Processed.BPSet(rc0);
                Colored |= HB81 & pConnectedCells[rc0];
                if (HB81.IsHit(rc0))
                {
                    Colored.BPSet(rc0);
                }
            }
            return((HB81 - Colored).IsZero());
        }
        //XY-Chain is an algorithm using Locked which occurs in the concatenation of bivalues.
        //http://csdenpe.web.fc2.com/page49.html
        public bool XYChain()
        {
            Prepare();
            CeLKMan.PrepareCellLink(1);                //Generate StrongLink

            List <int> LKRec = new List <int>();

            foreach (var CRL in _GetXYChain(LKRec))
            {
                int rcS = CRL[0].ID, no = CRL[1].ID, noB = (1 << no);

                Bit81 ELM = ConnectedCells[rcS] - (CRL[0] | CRL[1]);
                if (ELM.IsZero())
                {
                    continue;
                }

                Bit81 ELM2     = new Bit81();
                bool  XYChainF = false;
                foreach (var E in ELM.IEGetUCeNoB(pBDL, noB))
                {
                    if (CRL[0].IsHit(ConnectedCells[E.rc]))
                    {
                        E.CancelB = noB; XYChainF = true;
                        ELM2     |= CRL[0] & ConnectedCells[E.rc];
                        break;
                    }
                }
                if (!XYChainF)
                {
                    continue;
                }

                //===== XY-Chain found =====
                SolCode = 2;
                String SolMsg = "XY Chain";
                Result = SolMsg;

                int rcE;
                foreach (var P in ELM2.IEGetUCeNoB(pBDL, noB))
                {
                    P.SetNoBBgColor(noB, AttCr, SolBkCr);
                }
                Bit81 ELM2cpy = ELM2.Copy();
                while ((rcE = ELM2.FindFirstrc()) >= 0)
                {
                    string stR      = "";
                    Bit81  XYchainB = _SelectLink_XYChain(LKRec, rcS, rcE, noB, ref stR) - ELM2cpy;
                    if (SolInfoB)
                    {
                        SolMsg += "\r " + stR;
                    }

                    foreach (var P in XYchainB.IEGetUCeNoB(pBDL, 0x1FF))
                    {
                        P.SetNoBBgColor(P.FreeB, AttCr, SolBkCr2);
                    }
                    ELM2.BPReset(rcE);
                }
                if (SolInfoB)
                {
                    ResultLong = SolMsg;
                }
                pBDL[rcS].SetNoBBgColor(noB, AttCr, SolBkCr);

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