private bool _ALSXZ_SinglyLinked(UALS UA, UALS UB, int RCC, int EnoB) // *=*=* SinglyLinked subroutine *=*=* { bool solF = false; foreach (var no in EnoB.IEGet_BtoNo()) { int EnoBx = 1 << no; Bit81 UEz = new Bit81(); //Covered cells foreach (var P in UA.UCellLst.Where(p => (p.FreeB & EnoBx) > 0)) { UEz.BPSet(P.rc); } foreach (var P in UB.UCellLst.Where(p => (p.FreeB & EnoBx) > 0)) { UEz.BPSet(P.rc); } Bit81 Elm = (new Bit81(pBDL, EnoBx)) - (UA.B81 | UB.B81); //Scan Cells foreach (var rc in Elm.IEGet_rc()) { if ((UEz - ConnectedCells[rc]).IsZero()) { pBDL[rc].CancelB |= EnoBx; solF = true; } } } return(solF); }
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
private bool _CheckSolution_ALSChain(UALSPair LK0, UALSPair LKn, Bit81 rcUsed, Stack <UALSPair> SolStack) { int ElmBH = LK0.ALSpre.FreeB.BitReset(LK0.nRCC); //non-RCC digit of First ALS int ElmBT = LKn.ALSnxt.FreeB.BitReset(LKn.nRCC); //non-RCC digit of Last ALS int ElmB = ElmBH & ElmBT; if (ElmB == 0) { return(false); //if no common digits then Failure. } foreach (int Eno in ElmB.IEGet_BtoNo()) //Eno is one of common digits { int EnoB = (1 << Eno); Bit81 Ez = new Bit81(); //Negative cell candidate foreach (var P in LK0.ALSpre.UCellLst.Where(p => (p.FreeB & EnoB) > 0)) { Ez.BPSet(P.rc); } foreach (var P in LKn.ALSnxt.UCellLst.Where(p => (p.FreeB & EnoB) > 0)) { Ez.BPSet(P.rc); } Bit81 TBD = (new Bit81(pBDL, EnoB)) - rcUsed; //Exclude cells in the chain foreach (var rc in TBD.IEGet_rc()) { if ((Ez - ConnectedCells[rc]).IsZero()) { pBDL[rc].CancelB |= EnoB; SolCode = 2; } //found solution } } if (SolCode > 0) { _SolResult_ALSChain(SolStack); if (__SimpleAnalizerB__) { return(true); } if (!pAnMan.SnapSaveGP(true)) { return(true); } } return(false); }
static public Bit81[] HouseCells; //Row(0-8) Collumn(9-17) Block(18-26) static private void Create_ConnectedCells() { if (ConnectedCells != null) { return; } ConnectedCells = new Bit81[81]; //ConnectedCellsRev = new Bit81[81]; for (int rc = 0; rc < 81; rc++) { Bit81 BS = new Bit81(); foreach (var q in __IEGetCellsConnectedRC(rc).Where(q => q != rc)) { BS.BPSet(q); } BS.BPReset(rc); ConnectedCells[rc] = BS; //ConnectedCellsRev[rc] = BS ^ 0x7FFFFFF; } HouseCells = new Bit81[27]; for (int tfx = 0; tfx < 27; tfx++) { Bit81 tmp = new Bit81(); foreach (var q in __IEGetCellInHouse(tfx)) { tmp.BPSet(q); } HouseCells[tfx] = tmp; } }
public UCellLink(int tfx, int type, int no, UCell UCe1, UCell UCe2, bool SFlag = false) { this.tfx = tfx; this.type = type; this.no = no; this.SFlag = SFlag; this.UCe1 = UCe1; this.UCe2 = UCe2; this.ID = tfx; BVFlag = UCe1.FreeBC == 2 && UCe2.FreeBC == 2; B81 = new Bit81(rc1); B81.BPSet(rc2); }
//Link in ALS(when 1-number is excluded and locked, other digits are in one house) public void QSearch_AlsInnerLink() { if (ALSLst == null) { PrepareALSLinkMan(1); } if (ALSLst.Count == 0) { return; } if (AlsInnerLink != null) { return; } foreach (var Pals in ALSLst.Where(p => (p.Size >= 2 && p.singly))) { List <int> noLst = Pals.FreeB.IEGet_BtoNo().ToList(); Permutation prm = new Permutation(noLst.Count, 2);//using permutation while (prm.Successor(2)) { int noS = noLst[prm.Index[0]]; int noD = noLst[prm.Index[1]]; UGrCells GS = Pals.SelectNoCells(noS); //ALS cell group with noS UGrCells GD = Pals.SelectNoCells(noD); //ALS cell group with noD Bit81 B81D = new Bit81(); GD.ForEach(q => B81D.BPSet(q.rc)); for (int tfx = 0; tfx < 27; tfx++) { if (!(B81D - pHouseCells[tfx]).IsZero()) { continue; } _SetGroupedLink(Pals, GS, GD, tfx); } } } if (AlsInnerLink == null || AlsInnerLink.Count <= 0) { return; } AlsInnerLink.Sort(); int ID = 0; AlsInnerLink.ForEach(P => P.ID = (ID++)); // AlsInnerLink.ForEach(P=>{ // // if( P.ALSbase.Size==2 && P.tfx==18 ){ // WriteLine($"ALSLink {P.UGCellsA.GCToString()} -> tfx:{P.tfx} {P.UGCellsB.GCToString()}" ); // // } // } ); }
public bool EndoFinnedFMFish_sub(int sz, int no, int FMSize, bool FinnedF, bool EndoF = false, bool CannF = false) { int noB = (1 << no); int BaseSel = 0x7FFFFFF, CoverSel = 0x7FFFFFF; FishMan FMan = new FishMan(this, FMSize, no, sz, (sz >= 3)); foreach (var Bas in FMan.IEGet_BaseSet(BaseSel, FinnedF:FinnedF, EndoFlg:EndoF)) //BaseSet { foreach (var Cov in FMan.IEGet_CoverSet(Bas, CoverSel, CannF)) //CoverSet { if (pAnMan.CheckTimeOut()) { return(false); } Bit81 FinB81 = Cov.FinB81 | Bas.EndoFin; Bit81 E = Cov.CoverB81 - Bas.BaseB81; Bit81 ELM = new Bit81(); //see latest viewpoint foreach (var rc in E.IEGet_rc()) { if ((FinB81 - ConnectedCells[rc]).Count == 0) { ELM.BPSet(rc); } } if (ELM.Count > 0) { foreach (var P in ELM.IEGetUCeNoB(pBDL, noB)) { P.CancelB = noB; SolCode = 2; } if (SolCode > 0) { if (SolInfoB) { _Fish_FishResult(no, sz, Bas, Cov, (FMSize == 27)); //27:Franken/Mutant } //WriteLine(ResultLong); if (__SimpleAnalizerB__) { return(true); } if (!pAnMan.SnapSaveGP(true)) { return(true); } } } } } return(false); }
private Bit81 _SelectLink_XChain(List <int> LKRec, int rcS, Bit81 ELM, int noB) { Bit81 LKRecB = new Bit81(); foreach (var P in ELM.IEGetUCeNoB(pBDL, noB)) { int rcX = P.rc; LKRecB.BPSet(rcX); while (rcX != rcS) { rcX = LKRec.Find(p => (p & 0xFF) == rcX); if (rcX == 0) { break; } rcX = (rcX >> 8); LKRecB.BPSet(rcX); } } return(LKRecB); }
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()); }
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; }
private Bit81 _SelectLink_XYChain(List <int> LinkRecord, int rcS, int rcE, int noB, ref string stRet) { //(Extract and display directly related solution chain) Bit81 XYchainB = new Bit81(); int rcX = rcE; XYchainB.BPSet(rcX); List <int> Q = new List <int>(); if (SolInfoB) { Q.Add(rcX); } while (rcX != rcS) { rcX = LinkRecord.Find(p => (p & 0xFF) == rcX); if (rcX == 0) { break; } rcX = (rcX >> 8); XYchainB.BPSet(rcX); if (SolInfoB) { Q.Add(rcX); } } if (SolInfoB) { Q.Reverse(); string st = ""; Q.ForEach(p => st += "-[" + (p / 9 * 10 + p % 9 + 11) + "]"); stRet = ">" + st.Substring(1); } return(XYchainB); }
public UALS(int ID, int Size, int tfx, int FreeB, List <UCell> UCellLst) { this.ID = ID; this.Size = Size; this.tfx = tfx; this.singly = true; this.FreeB = FreeB; this.Level = FreeB.BitCount() - Size; this.B81 = new Bit81(); this.rcbFilter = new Bit81(); this.UCellLst = UCellLst; this.LockedNoDir = null; UCellLst.ForEach(P => { rcbDir |= ((1 << (P.b + 18)) | (1 << (P.c + 9)) | (1 << (P.r))); rcbFilter |= pConnectedCells[P.rc]; B81.BPSet(P.rc); }); }
private void _DeathBlossom_SolResult(List <LinkCellALS> LKCAsol, UCell SC, int no, bool stmLink = false) { string st0 = "ALS Death Blossom"; if (stmLink) { st0 += "Ext"; } Color cr = _ColorsLst[0];////Colors.Gold; SC.SetNoBBgColor(SC.FreeB, AttCr3, cr); string st = $"\r Cell r{(SC.r+1)}c{(SC.c+1)} #{SC.FreeB.ToBitStringNZ(9)}"; bool Overlap = false; Bit81 OV = new Bit81(); int k = 0, noB = (1 << no); foreach (var LK in LKCAsol) { int noB2 = 1 << LK.nRCC; cr = _ColorsLst[++k]; LK.ALS.UCellLst.ForEach(P => { P.SetNoBBgColor(noB, AttCr, cr); P.SetNoBBgColor(noB2, AttCr3, cr); if (OV.IsHit(P.rc)) { Overlap = true; } OV.BPSet(P.rc); }); st += $"\r -#{(LK.nRCC+1)}-ALS{k} {LK.ALS.ToStringRCN()}"; } if (Overlap) { st0 += " [overlapping]"; } Result = st0; if (SolInfoB) { ResultLong = st0 + st; } }
//=================== MultiColoring ================================== public bool MultiColor_Type1( ) { Prepare(); CeLKMan.PrepareCellLink(1); //Generate StrongLink for (int no = 0; no < 9; no++) { int noB = (1 << no); List <Bit81[]> MCRL = _Coloring(no).ToList(); if (MCRL == null || MCRL.Count < 2) { continue; } var cmb = new Combination(MCRL.Count, 2); while (cmb.Successor()) { Bit81[] CRLa = MCRL[cmb.Index[0]]; Bit81[] CRLb = MCRL[cmb.Index[1]]; for (int na = 0; na < 2; na++) { Bit81 HCRLa = new Bit81(); foreach (var rc in CRLa[na].IEGet_rc()) { HCRLa |= ConnectedCells[rc]; } for (int nb = 0; nb < 2; nb++) { if ((HCRLa & CRLb[nb]).IsZero()) { continue; } Bit81 BD0 = new Bit81(pBDL, noB); Bit81 ELMtry = BD0 - (CRLa[na] | CRLb[nb] | CRLa[1 - na] | CRLb[1 - nb]); if (ELMtry.Count == 0) { continue; } bool solF = false; Bit81 ELM = new Bit81(); foreach (var rc in ELMtry.IEGet_rc()) { if (!ConnectedCells[rc].IsHit(CRLa[1 - na])) { continue; } if (!ConnectedCells[rc].IsHit(CRLb[1 - nb])) { continue; } pBDL[rc].CancelB = noB; ELM.BPSet(rc); solF = true; } if (solF) { Color CrA = _ColorsLst[0]; foreach (var P in ELM.IEGet_rc().Select(p => pBDL[p])) { P.SetNoBBgColor(noB, AttCr, CrA); } for (int k = 0; k < 2; k++) { Bit81[] CRLX = MCRL[cmb.Index[k]]; Color Cr1 = _ColorsLst[k]; Color Cr2 = Cr1; Cr2.A = (byte)120; foreach (var P in CRLX[1 - k].IEGet_rc().Select(p => pBDL[p])) { P.SetNoBBgColor(noB, AttCr, Cr1); } foreach (var P in CRLX[k].IEGet_rc().Select(p => pBDL[p])) { P.SetNoBBgColor(noB, AttCr, Cr2); } } SolCode = 2; string SolMsg = "MultiColoring Type1 #" + (no + 1); Result = SolMsg; if (SolInfoB) { ResultLong = SolMsg; } if (__SimpleAnalizerB__) { return(true); } if (!pAnMan.SnapSaveGP(true)) { return(true); } solF = false; } } } } } return(false); }
//Coloring is an algorithm that connects the focused digit with a strong link. //http://csdenpe.web.fc2.com/page46.html public bool Color_Trap( ) { Prepare(); CeLKMan.PrepareCellLink(1); //Generate StrongLink for (int no = 0; no < 9; no++) { int noB = (1 << no); foreach (Bit81[] CRL in _Coloring(no)) { Bit81 HitB = new Bit81(); Bit81 ELM = (new Bit81(pBDL, noB)) - (CRL[0] | CRL[1]); foreach (var rc in ELM.IEGet_rc()) { Bit81 HB = HouseCells[18 + rc.ToBlock()]; if (((ConnectedCells[rc] - HB) & CRL[0]).IsZero()) { continue; } if (((ConnectedCells[rc] - HB) & CRL[1]).IsZero()) { continue; } HitB.BPSet(rc); } if (!HitB.IsZero()) { Color Cr = _ColorsLst[0]; Color Cr1 = Cr; Cr1.A = (byte)120; //Color.FromArgb(120,Cr.R,Cr.G,Cr.B); foreach (var P in HitB.IEGet_rc().Select(p => pBDL[p])) { P.CancelB = noB; } foreach (var P in CRL[0].IEGet_rc().Select(p => pBDL[p])) { P.SetNoBBgColor(noB, AttCr, Cr); } foreach (var P in CRL[1].IEGet_rc().Select(p => pBDL[p])) { P.SetNoBBgColor(noB, AttCr, Cr1); } SolCode = 2; string SolMsg = "Coloring Trap #" + (no + 1); Result = SolMsg; if (SolInfoB) { ResultLong = SolMsg; } if (__SimpleAnalizerB__) { return(true); } if (!pAnMan.SnapSaveGP(true)) { return(true); } HitB = new Bit81(); } } } return(false); }
private bool _ALSXZ_DoublyLinked(UALS UA, UALS UB, int RCC) // *=*=* DoublyLinked subroutine *=*=* //----- RCC ----- { Bit81 UEz = new Bit81(); //Covered cells bool solF = false; foreach (int no in RCC.IEGet_BtoNo()) { int noB = 1 << no; UEz.Clear(); foreach (var P in UA.UCellLst.Where(p => (p.FreeB & noB) > 0)) { UEz.BPSet(P.rc); } foreach (var P in UB.UCellLst.Where(p => (p.FreeB & noB) > 0)) { UEz.BPSet(P.rc); } Bit81 Elm = (new Bit81(pBDL, noB)) - (UA.B81 | UB.B81); //Scan Cells foreach (var rc in Elm.IEGet_rc()) { if ((UEz - ConnectedCells[rc]).IsZero()) { pBDL[rc].CancelB |= noB; solF = true; } } } //----- ALS element digit other than RCC ----- int nRCC = UA.FreeB.DifSet(RCC); foreach (int no in nRCC.IEGet_BtoNo()) { int noB = 1 << no; UEz.Clear(); foreach (var P in UA.UCellLst.Where(p => (p.FreeB & noB) > 0)) { UEz.BPSet(P.rc); } Bit81 Elm = (new Bit81(pBDL, noB)) - (UA.B81 | UB.B81); //Scan Cells foreach (var rc in Elm.IEGet_rc()) { if ((UEz - ConnectedCells[rc]).IsZero()) { pBDL[rc].CancelB |= noB; solF = true; } } } nRCC = UB.FreeB.DifSet(RCC); foreach (int no in nRCC.IEGet_BtoNo()) { int noB = 1 << no; UEz.Clear(); foreach (var P in UB.UCellLst.Where(p => (p.FreeB & noB) > 0)) { UEz.BPSet(P.rc); } Bit81 Elm = (new Bit81(pBDL, noB)) - (UA.B81 | UB.B81); //Scan Cells foreach (var rc in Elm.IEGet_rc()) { if ((UEz - ConnectedCells[rc]).IsZero()) { pBDL[rc].CancelB |= noB; solF = true; } } } return(solF); }
private bool _ALS_DeathBlossomSubEx(int sz, bool stmLinked = false) { int szM = (stmLinked? sz - 1: sz); foreach (var SC in pBDL.Where(p => p.FreeBC == sz)) //Stem Cell { if (pAnMan.CheckTimeOut()) { return(false); } List <LinkCellALS> LinkCeAlsLst = ALSMan.LinkCeAlsLst[SC.rc]; if (LinkCeAlsLst == null || LinkCeAlsLst.Count < sz) { continue; } int nxt = 0, PFreeB = SC.FreeB; var cmb = new Combination(LinkCeAlsLst.Count, szM); //Select szM ALSs in Combination while (cmb.Successor(nxt)) { int FreeB = SC.FreeB, AFreeB = 0x1FF; for (int k = 0; k < szM; k++) { nxt = k; var LK = LinkCeAlsLst[cmb.Index[k]]; //Link[cell-ALS] if ((FreeB & (1 << LK.nRCC)) == 0) { goto LNxtCmb; } FreeB = FreeB.BitReset(LK.nRCC); //nRCC:RCC of stemCell-ALS AFreeB &= LK.ALS.FreeB; if (AFreeB == 0) { goto LNxtCmb; } } if (stmLinked) { if (FreeB.BitCount() != 1 || (FreeB & AFreeB) == 0) { continue; } int no = FreeB.BitToNum(); int noB = FreeB; Bit81 Ez = new Bit81(); for (int k = 0; k < szM; k++) { var ALS = LinkCeAlsLst[cmb.Index[k]].ALS; var UClst = ALS.UCellLst; foreach (var P in UClst.Where(p => (p.FreeB & noB) > 0)) { Ez.BPSet(P.rc); } } foreach (var P in ConnectedCells[SC.rc].IEGet_rc().Select(rc => pBDL[rc])) { if ((P.FreeB & noB) == 0) { continue; } if ((Ez - ConnectedCells[P.rc]).IsZero()) { P.CancelB = noB; SolCode = 2; } } if (SolCode < 1) { continue; } var LKCAsol = new List <LinkCellALS>(); Array.ForEach(cmb.Index, nx => LKCAsol.Add(LinkCeAlsLst[nx])); _DeathBlossom_SolResult(LKCAsol, SC, no, stmLinked); if (__SimpleAnalizerB__) { return(true); } if (!pAnMan.SnapSaveGP(true)) { return(true); } } else if (FreeB == 0 && AFreeB > 0) { AFreeB = AFreeB.DifSet(SC.FreeB); foreach (var no in AFreeB.IEGet_BtoNo()) { int noB = (1 << no); Bit81 Ez = new Bit81(); for (int k = 0; k < sz; k++) { var ALS = LinkCeAlsLst[cmb.Index[k]].ALS; var UClst = ALS.UCellLst; foreach (var P in UClst.Where(p => (p.FreeB & noB) > 0)) { Ez.BPSet(P.rc); } } foreach (var P in pBDL.Where(p => (p.FreeB & noB) > 0)) { if ((Ez - ConnectedCells[P.rc]).IsZero()) { P.CancelB = noB; SolCode = 2; } } if (SolCode < 1) { continue; } var LKCAsol = new List <LinkCellALS>(); Array.ForEach(cmb.Index, nx => LKCAsol.Add(LinkCeAlsLst[nx])); _DeathBlossom_SolResult(LKCAsol, SC, no, stmLinked); if (__SimpleAnalizerB__) { return(true); } if (!pAnMan.SnapSaveGP(true)) { return(true); } } } LNxtCmb: continue; } } return(false); }
public bool ExtFishSub(int sz, int no, int FMSize, int BaseSel, int CoverSel, bool FinnedF, bool _Fdef = true) { int noB = (1 << no); bool extFlag = (sz >= 3 && ((BaseSel | CoverSel).BitCount() > 18)); if (_Fdef) { FMan = new FishMan(this, FMSize, no, sz, extFlag); } foreach (var Bas in FMan.IEGet_BaseSet(BaseSel, FinnedF:FinnedF)) //select BaseSet { if (pAnMan.CheckTimeOut()) { return(false); } foreach (var Cov in FMan.IEGet_CoverSet(Bas, CoverSel, FinnedF)) //select CoverSet { Bit81 FinB81 = Cov.FinB81; Bit81 ELM = null; var FinZeroB = FinB81.IsZero(); if (!FinnedF && FinZeroB) //===== no Fin ===== { if (!FinnedF && (ELM = Cov.CoverB81 - Bas.BaseB81).Count > 0) { foreach (var P in ELM.IEGetUCeNoB(pBDL, noB)) { P.CancelB = noB; SolCode = 2; } if (SolCode > 0) //solved!( { if (SolInfoB) { _Fish_FishResult(no, sz, Bas, Cov, (FMSize == 27)); //FMSize 18:regular 27:Franken/Mutant } if (__SimpleAnalizerB__) { return(true); } if (!pAnMan.SnapSaveGP(true)) { return(true); } } } } else if (FinnedF && !FinZeroB) //===== Finned ===== { Bit81 Ecand = Cov.CoverB81 - Bas.BaseB81; ELM = new Bit81(); foreach (var P in Ecand.IEGetUCeNoB(pBDL, noB)) { if ((FinB81 - ConnectedCells[P.rc]).Count == 0) { ELM.BPSet(P.rc); } } if (ELM.Count > 0) //there are cells/digits can be excluded { foreach (var P in ELM.IEGet_rc().Select(p => pBDL[p])) { P.CancelB = noB; SolCode = 2; } if (SolCode > 0) //solved! { if (SolInfoB) { _Fish_FishResult(no, sz, Bas, Cov, (FMSize == 27)); //FMSize 18:regular 27:Franken/Mutant } if (__SimpleAnalizerB__) { return(true); } if (!pAnMan.SnapSaveGP(true)) { return(true); } } } } continue; } } return(false); }
public new void Add(UCell P) { base.Add(P); B81.BPSet(P.rc); }
private bool _ALSXYWingSub(int szT) { //(ALS sorted by size) foreach (var UC in ALSMan.ALSLst.Where(p => p.Size <= szT - 2)) { if (!UC.singly) { continue; } int szS = szT - UC.Size; UALS UA, UB, UApre = null; int nxt = 0, RccAC = -1, RccBC = -1; var cmb = new Combination(ALSMan.ALSLst.Count, 2); while (cmb.Successor(nxt)) { nxt = 0; UA = ALSMan.ALSLst[cmb.Index[0]]; if (!UA.singly || UA == UC || UA.Size > szS - 1) { continue; } if (UA != UApre) { RccAC = ALSMan.Get_AlsAlsRcc(UA, UC); //RCC if (RccAC.BitCount() != 1) { continue; } UApre = UA; } UB = ALSMan.ALSLst[cmb.Index[1]]; if (!UB.singly || UB.Size > (szS - UA.Size)) { continue; //Skip using "Sort by size" } nxt = 1; if (UB == UC || UB.Size != (szS - UA.Size)) { continue; } if (!(UA.B81 & UB.B81).IsZero()) { continue; //Overlap } RccBC = ALSMan.Get_AlsAlsRcc(UB, UC); //RCC if (RccBC.BitCount() != 1) { continue; } if (RccAC == RccBC) { continue; } int EFrB = (UA.FreeB & UB.FreeB).DifSet(RccAC | RccBC); if (EFrB == 0) { continue; } foreach (var no in EFrB.IEGet_BtoNo()) { int noB = (1 << no); Bit81 UE = new Bit81(); foreach (var P in UA.UCellLst.Where(p => (p.FreeB & noB) > 0)) { UE.BPSet(P.rc); } foreach (var P in UB.UCellLst.Where(p => (p.FreeB & noB) > 0)) { UE.BPSet(P.rc); } Bit81 TBD = (new Bit81(pBDL, noB)) - (UA.B81 | UB.B81 | UC.B81); foreach (var rc in TBD.IEGet_rc()) { if (!(UE - ConnectedCells[rc]).IsZero()) { continue; } pBDL[rc].CancelB = noB; SolCode = 2; } if (SolCode > 0) //===== ALS XY-Wing found ===== { ALSXYWing_SolResult(UA, UB, UC, RccAC, RccBC); if (__SimpleAnalizerB__) { return(true); } if (!pAnMan.SnapSaveGP(true)) { return(true); } } } } } return(false); }
private bool _XYZwingALSSub(int wsz) //simple UVWXYZwing { List <UCell> FBCX = pBDL.FindAll(p => p.FreeBC == wsz); if (FBCX.Count == 0) { return(false); } foreach (var P0 in FBCX) //Forcused Cell { int b0 = P0.b; //Forcused Block for (int no = 0; no < 9; no++) { int noB = 1 << no; Bit81 P0con = (new Bit81(pBDL, noB)) & ConnectedCells[P0.rc]; Bit81 Pin = P0con & HouseCells[18 + b0]; for (int dir = 0; dir < 2; dir++) //dir 0:row 1:col { int rcDir = (dir == 0)? P0.r: (9 + P0.c); Bit81 Pin2 = Pin - HouseCells[rcDir]; //ALS candidate position in the block if (Pin2.IsZero()) { continue; } Bit81 Pout = (P0con & HouseCells[rcDir]) - HouseCells[18 + P0.b]; //ALS candidate position outside the block foreach (var ALSout in ALSMan.IEGetCellInHouse(1, noB, Pout, rcDir)) //ALS out of Forcused Block { int FreeBOut2 = ALSout.FreeB.DifSet(noB); Bit81 EOut = new Bit81(); //#no existence position(outer-ALS) foreach (var P in ALSout.UCellLst.Where(p => (p.FreeB & noB) > 0)) { EOut.BPSet(P.rc); } foreach (var ALSin in ALSMan.IEGetCellInHouse(1, noB, Pin2, 18 + b0)) { int FreeBin2 = ALSin.FreeB.DifSet(noB); Bit81 Ein = new Bit81(); //#no existence position(inner-ALS) foreach (var P in ALSin.UCellLst.Where(p => (p.FreeB & noB) > 0)) { Ein.BPSet(P.rc); } int Cover = P0.FreeB.DifSet(ALSout.FreeB | ALSin.FreeB); if (Cover != 0) { continue; //Numbers in inner-ALS and outer-ALS cover numbers in the Forcused cell } Bit81 Epat = EOut | Ein; //Cells covered by excluded Cells&Digit if (Epat.IsZero()) { continue; } bool SolFound = false; string msg3 = ""; int FreeBin3 = P0.FreeB.DifSet(FreeBOut2 | FreeBin2); foreach (var E in pBDL.Where(p => (p.FreeB & noB) > 0)) { if (E.rc == P0.rc || Pout.IsHit(E.rc) || Pin2.IsHit(E.rc)) { continue; } if (!(Epat - ConnectedCells[E.rc]).IsZero()) { continue; } if (FreeBin3 > 0 && !ConnectedCells[E.rc].IsHit(P0.rc)) { continue; } E.CancelB = noB; SolFound = true; msg3 += " " + E.rc.ToRCString(); } if (SolFound) { SolCode = 2; string[] xyzWingName = { "XYZ-Wing", "WXYZ-Wing", "VWXYZ-Wing", "UVWXYZ-Wing" }; string SolMsg = xyzWingName[wsz - 3] + "(ALS)"; if (SolInfoB) { P0.SetNoBBgColor(P0.FreeB, AttCr, SolBkCr2); foreach (var P in ALSin.UCellLst) { P.SetNoBBgColor(P.FreeB, AttCr, SolBkCr); } foreach (var P in ALSout.UCellLst) { P.SetNoBBgColor(P.FreeB, AttCr, SolBkCr); } string msg0 = " Pivot: " + P0.rc.ToRCString(); string st = ""; foreach (var P in ALSin.UCellLst) { st += " " + P.rc.ToRCString(); } string msg1 = " in: " + st.ToString_SameHouseComp(); st = ""; foreach (var P in ALSout.UCellLst) { st += " " + P.rc.ToRCString(); } string msg2 = " out: " + st.ToString_SameHouseComp(); st = ""; foreach (var rc in Pin2.IEGet_rc()) { st += " " + rc.ToRCString(); } Result = SolMsg + msg0 + msg1 + msg2; ResultLong = SolMsg + "\r" + msg0 + "\r " + msg1 + "\r " + msg2 + "\r Eliminated: " + msg3.ToString_SameHouseComp(); } if (__SimpleAnalizerB__) { return(true); } if (!pAnMan.SnapSaveGP(true)) { return(true); } foreach (var E in pBDL.Where(p => (p.FreeB & noB) > 0)) { E.CancelB = 0; } SolFound = false; } } } } } } return(false); }
private int _GroupedNL_CheckSolution(GroupedLink GLK0, GroupedLink GLKnxt, Stack <GroupedLink> SolStack, Bit81 UsedCs) { bool SolFound = false; int SolType = pSprLKsMan.Check_SuperLinkSequence(GLKnxt, GLK0)? 1: 2; //1:Continuous 2:DisContinuous if (SolType == 1) //<>continuous { List <GroupedLink> SolLst = SolStack.ToList(); //___Debug_Print_GNLChain(SolStack); SolLst.Reverse(); SolLst.Add(GLK0); Bit81 UsedCsTmp = new Bit81(UsedCs); SetUsed(ref UsedCsTmp, GLKnxt); 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 (UsedCsTmp.IsHit(P.rc)) { continue; } if (!(SolBP - ConnectedCells[P.rc]).IsZero()) { continue; } if ((P.FreeB & noB) == 0) { continue; } P.CancelB |= noB; //exclusion digit SolFound = true; } } var LKpre = SolLst[0]; foreach (var LK in SolLst.Skip(1)) { if (LKpre.type == S && LK.type == S && LK.UGCellsA.Count == 1) { var P = pBDL[LK.UGCellsA[0].rc]; //(for MultiAns code) int noB2 = P.FreeB - ((1 << LKpre.no2) | (1 << LK.no)); if (noB2 > 0) { P.CancelB |= noB2; SolFound = true; } } LKpre = LK; } if (SolFound) { SolCode = 1; } } else { //<>discontinuous int dcTyp = GLK0.type * 10 + GLKnxt.type; UCell P = pBDL[GLK0.UGCellsA[0].rc]; //(for MultiAns code) switch (dcTyp) { case 11: P.FixedNo = GLK0.no + 1; //Cell number determination P.CancelB = P.FreeB.DifSet(1 << (GLK0.no)); SolCode = 1; SolFound = true; //(1:Fixed) break; case 12: P.CancelB = 1 << GLKnxt.no; SolCode = 2; SolFound = true; break;//(2:Exclude from candidates) case 21: P.CancelB = 1 << GLK0.no; SolCode = 2; SolFound = true; break; case 22: if (GLK0.no == GLKnxt.no) { P.CancelB = 1 << GLK0.no; SolFound = true; SolCode = 2; } break; } } if (SolFound) { return(SolType); } return(-1); }