public UGrCells SelectNoCells(int no)
        {
            int          noB  = 1 << no;
            List <UCell> UCsS = UCellLst.FindAll(Q => (Q.FreeB & noB) > 0);
            UGrCells     GCs  = new UGrCells(tfx, no);

            GCs.Add(UCsS);
            return(GCs);
        }
        private void SearchGroupedLink()
        {
            try{
                UGrCells[] LQ = new UGrCells[3];
                for (int no = 0; no < 9; no++)
                {
                    int   noB   = 1 << no;
                    Bit81 BPnoB = new Bit81(pBDL, noB);

                    //------------------------------------------
                    for (int tfx = 0; tfx < 18; tfx++)
                    {
                        Bit81 BPnoB2 = BPnoB & pHouseCells[tfx];

                        List <Bit81> houseLst = new List <Bit81>();
                        List <int>   tfxLst   = new List <int>();
                        for (int k = 0; k < 9; k++)
                        {
                            int   hx = (tfx < 9)? (k + 9): k;
                            Bit81 BX = BPnoB2 & pHouseCells[hx];
                            if (BX.IsZero())
                            {
                                continue;
                            }
                            houseLst.Add(BX);
                            tfxLst.Add(hx);
                        }
                        for (int k = 0; k < 3; k++)
                        {
                            int hx = (tfx < 9)? (tfx / 3 * 3 + k): ((tfx - 9) / 3 + k * 3);
                            hx += 18;
                            Bit81 BX = BPnoB2 & pHouseCells[hx];
                            if (BX.IsZero())
                            {
                                continue;
                            }
                            houseLst.Add(BX);
                            tfxLst.Add(hx);
                        }

                        if (houseLst.Count < 2)
                        {
                            continue;
                        }
                        Permutation prm = new Permutation(houseLst.Count, 2);
                        while (prm.Successor())
                        {
                            int   na = prm.Index[0], nb = prm.Index[1];
                            Bit81 HA = houseLst[na];
                            Bit81 HB = houseLst[nb];
                            if (!(HA & HB).IsZero())
                            {
                                continue;
                            }
                            UGrCells LA = new UGrCells(tfxLst[na], no);
                            UGrCells LB = new UGrCells(tfxLst[nb], no);
                            foreach (var P in HA.IEGetUCeNoB(pBDL, 0x1FF))
                            {
                                LA.Add(P);
                            }
                            foreach (var P in HB.IEGetUCeNoB(pBDL, 0x1FF))
                            {
                                LB.Add(P);
                            }
                            SetGroupedLink(tfxLst[nb], W, no, LA, LB);
                            if (!(BPnoB2 - (HA | HB)).IsZero())
                            {
                                continue;
                            }
                            SetGroupedLink(tfxLst[nb], S, no, LA, LB);
                        }
                    }

                    //------------------------------------------
                    for (int tfx = 18; tfx < 27; tfx++)
                    {
                        int bx = tfx - 18;
                        int b0 = (bx / 3 * 27 + (bx % 3) * 3); //Cell number at the top left of the block

                        Bit81        BPnoB2   = BPnoB & pHouseCells[tfx];
                        List <Bit81> houseLst = new List <Bit81>();
                        List <int>   tfxLst   = new List <int>();
                        for (int k = 0; k < 3; k++)
                        {
                            int   r0 = (b0 / 9 + k);
                            Bit81 BX = BPnoB2 & pHouseCells[r0];
                            if (BX.IsZero())
                            {
                                continue;
                            }
                            houseLst.Add(BX);
                            tfxLst.Add(r0);
                        }
                        for (int k = 0; k < 3; k++)
                        {
                            int   c0 = (b0 % 9) + k;
                            Bit81 BX = BPnoB2 & pHouseCells[c0 + 9];
                            if (BX.IsZero())
                            {
                                continue;
                            }
                            houseLst.Add(BX);
                            tfxLst.Add(c0 + 9);
                        }

                        if (houseLst.Count >= 2)
                        {
                            Permutation prm = new Permutation(houseLst.Count, 2);
                            while (prm.Successor())
                            {
                                int   na = prm.Index[0], nb = prm.Index[1];
                                Bit81 HA = houseLst[na];
                                Bit81 HB = houseLst[nb] - HA;
                                if (HB.IsZero())
                                {
                                    continue;
                                }
                                UGrCells LA = new UGrCells(tfxLst[na], no);
                                UGrCells LB = new UGrCells(tfxLst[nb], no);
                                foreach (var P in HA.IEGetUCeNoB(pBDL, 0x1FF))
                                {
                                    LA.Add(P);
                                }
                                foreach (var P in HB.IEGetUCeNoB(pBDL, 0x1FF))
                                {
                                    LB.Add(P);
                                }
                                SetGroupedLink(tfxLst[nb], W, no, LA, LB);
                                if (!(BPnoB2 - (HA | HB)).IsZero())
                                {
                                    continue;
                                }
                                SetGroupedLink(tfxLst[nb], S, no, LA, LB);
                            }
                        }
                        if (houseLst.Count >= 1)
                        {
                            for (int na = 0; na < houseLst.Count; na++)
                            {
                                Bit81    HA = houseLst[na];
                                UGrCells LA = new UGrCells(tfxLst[na], no);
                                foreach (var P in HA.IEGetUCeNoB(pBDL, 0x1FF))
                                {
                                    LA.Add(P);
                                }
                                foreach (var rc in BPnoB2.IEGet_rc())
                                {
                                    if (HA.IsHit(rc))
                                    {
                                        continue;
                                    }
                                    UGrCells LB = new UGrCells(-9, no, pBDL[rc]);
                                    SetGroupedLink(tfxLst[na], W, no, LA, LB);
                                    SetGroupedLink(-9, W, no, LB, LA);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex) {
                WriteLine(ex.Message);
                WriteLine(ex.StackTrace);
            }
        }
Exemple #3
0
        public IEnumerable <GroupedLink> IEGet_SuperLink(GroupedLink GLKpre)
        {
            int  SWCtrl = GLKpre.type;
            bool ALSpre = GLKpre is ALSLink;

            if (GLKpre.UGCellsB.Count == 1)
            {
                UCell            U    = GLKpre.UGCellsB[0];
                List <UCellLink> Plst = CeLKMan.CeLK81[U.rc];
                if (Plst != null)
                {
                    foreach (var LK in Plst)
                    {
                        if (ALSpre && LK.type != W)
                        {
                            continue;
                        }
                        GroupedLink GLK = new GroupedLink(LK);
                        if (Check_SuperLinkSequence(GLKpre, GLK))
                        {
                            yield return(GLK);
                        }
                    }
                }
            }

            if (GNPXApp000.GMthdOption["GroupedCells"] == "1")
            {
                foreach (var GP in GLKMan.GrpCeLKLst)
                {
                    if (ALSpre && GP.type != W)
                    {
                        continue;
                    }
                    if (!GLKpre.UGCellsB.EqualsRC(GP.UGCellsA))
                    {
                        continue;
                    }
                    if (GLKpre.no2 != GP.no)
                    {
                        continue;
                    }
                    if (Check_SuperLinkSequence(GLKpre, GP))
                    {
                        yield return(GP);
                    }
                }
            }

            if (GNPXApp000.GMthdOption["ALS"] == "1" && ALSMan.AlsInnerLink != null)
            {
                if (GLKpre.type == W)
                {
                    foreach (var GP in ALSMan.AlsInnerLink.Where(p => (p.ALSbase.Level == 1)))
                    {
                        if (GLKpre.no2 != GP.no)
                        {
                            continue;
                        }
                        if (GLKpre.UGCellsB.Equals(GP.UGCellsA))
                        {
                            yield return(GP);
                        }
                    }
                }
            }

            if (ALSpre)
            {
                ALSLink ALK   = GLKpre as ALSLink;
                int     noB   = 1 << ALK.no2;
                Bit81   BPnoB = new Bit81(pBDL, noB);

                Bit81 BP = BPnoB & ALK.UGCellsB.B81;
                //      ALK.UGCellsB.ForEach(P=>{ if((P.FreeB&noB)>0) BP.BPSet(P.rc); });

                Bit81 UsedCs = GLKpre.UsedCs;
                for (int tfx = 0; tfx < 27; tfx++)
                {
                    Bit81 HS = BPnoB & pHouseCells[tfx];
                    if (!(BP - HS).IsZero())
                    {
                        continue;
                    }
                    if ((HS - BP).IsZero())
                    {
                        continue;
                    }

                    Bit81 NxtBP = HS - BP - UsedCs;
                    if (NxtBP.IsZero())
                    {
                        continue;
                    }

//C                        WriteLine("\n tfx:"+tfx );
//C                        WriteLine( "   BP:"+BP );
//C                        WriteLine( "   HS:"+HS );
//C                        WriteLine( "HS-BP:"+(HS-BP) );
//C                        WriteLine( "NxtBP:"+NxtBP );

                    List <UCell> NxtCs = NxtBP.ToList().ConvertAll(rc => pBDL[rc]);
                    for (int k = 1; k < (1 << NxtCs.Count); k++)
                    {
                        UGrCells NxtGrpdCs = new UGrCells(tfx, ALK.no2);
                        int      kb        = k;
                        for (int n = 0; n < NxtCs.Count; n++)
                        {
                            if ((kb & 1) > 0)
                            {
                                NxtGrpdCs.Add(new UGrCells(NxtCs[n], ALK.no2));
                            }
                            kb >>= 1;
                        }
                        GroupedLink GP = new GroupedLink(GLKpre.UGCellsB, NxtGrpdCs, tfx, W);
//C                        WriteLine( GP );
                        yield return(GP);
                    }
                }
            }
            yield break;
        }