SEclone  URs ULs common process

I start in the code for URs UL by the common part to both.

Common process to UR’s UL’s

 

URs and ULs have a common process  for patterns where 2 cells with extra candidates are located in the same row; column or box.

That process, part of the class CRIN   It is split in 2 files, the second one dedicated to hidden and nacked sets.

 

The first file  "c\_05a_  RIN_el.cpp" has the entry points and solve patterns with dual values. I skip here the comments at the head of the file (need a final check of content).

 

The process is launched for all rows, column, boxes containing the 2 cells.

So the common part is in fact T2-el.

 

int CRIN::T2(USHORT action)

{int ir1=T2_el(GetElPlus(),action ),ir2; if(ir1==1) return 1;

 int eb=t81f[pp1].eb;

 if(eb==t81f[pp2].eb)ir2= T2_el(eb+18,action );

 if(ir2==1) return 1;

 if((ir1+ir2)==0)return 0; else return 2;}

 

 

 

// same but el is now identified

int CRIN::T2_el(USHORT el,USHORT action)

{//look mode 1 for a bivalue of one of the common digits

 //    ImageRI("");E$.E("UR/UL el ");E$.E(el+1 );E$.E(" action=");E$.Enl(action );

if(action & 1) //   this is a "basis" 

  if(Jum(el,chc1))

    {int ir1=T81t[pp1].Change(chc2)+T81t[pp2].Change(chc2);

     if(ir1){;E$.E("UR/UL bivalue ");E$.Enl(chc1+1);return 1;}

    }

  else if(Jum(el,chc2))

   {int ir1=T81t[pp1].Change(chc1)+T81t[pp2].Change(chc1);

     if(ir1){E$.E("UR/UL bivalue ");E$.Enl(chc2+1 );return 1;}

   }

 

       // first look  for cells having a potential for hidden/direct locked sets

int ir=0; aig_hid=0; nth=ntd=nnh=0;

wh=wc;wd=wr;wnh=wr;wnd=wc;wdp.f=0;

zwel.Init(); // to prepare clearing of naked sets

for(int i=0;i<9;i++)

  {int ppi=divf.el81[el][i];if((ppi==pp1)||(ppi==pp2))continue;

   UNP v=T81t[ppi].v;  if(v.typ) continue; // given or assigned

              // count and store cells including common digits

   zwel.Set(ppi);//will contain all active cells out of the UR at the end

   CB9CH  ww=v.cand&wc;

   if(ww.f)  {th[nth++]=ppi;  wh|=v.cand;

              if(ww.f==wc.f)aig_hid=1;}

   else // naked locked set  can not have common digits       

   { wnh|=v.cand;

     tnh[nnh++]=ppi; // nnh to check at least one cell without common digits

     ww=v.cand&wr;

     if(ww.f)  {td[ntd++]=ppi;  wd|=v.cand;} else wnd|=v.cand;

   }

 }

 

if(!nnh) return 0;//all cells have common digits nothing to do

 

int nk_value=nth-nnh;// we have the "k" value if =

 

//  hidden pair

if(nth<2 && (action==1)&& nk_value)  //  hidden pair if active

{if(T81t[th[0]].Keep(wc))     { E$.Enl("UR/UL hidden pair");return 1;}  }

 

if(action<2) return 2; // store it if not basic

 

 

 // we now look  for  a hidden or nacked set of the appropriate length

 

if(nk_value) // consider hidden set, action = number of nth cells

            if(T2_el_set_hidden(action)) return 1;

if(T2_el_set_nacked(action-1)) return 1;

 

 return 0;

}

 

 

 

Common process to UR’s UL’s hidden or nacked sets

 

 

That process looks exclusively for hidden or nacked sets in the row; column or box.

That process, part of the class CRIN can be found here

 

 

#include "c\_05a_  RIN_el2.cpp"

 

With the following code

 

 

// we are now looking for nacked or hidden sets not  pair

// we have not so many possible patterns,

// we try to catch them per pattern

// it need more code, but it should be faster and easier to debug

 

// look for hidden 

int CRIN::T2_el_set_hidden(USHORT len)

{      // first pattern, take it if direct

 if(nth==len)   // not the expected length

 { // identify extra digits in hidden locked set

 CB9CH whh=wh-wnh;  // all digits of the assumed locked set

 if(whh.QC()-(nth+1)) return 0;

 //go for the a hidden set if active

  int ir1=0;

  for(int i=0;i<nth;i++)  ir1+=T81t[th[i]].Keep(whh);

  if(ir1) { E$.E("UR/UL hls whh="); E$.Enl(whh.String());

              E$.Enl("UR/UL hidden locked set"); return 1;}   

 }

 if(nth==2 && len==3)

// second pattern with nth=2 but a hidden quad

// adding another cell

 {     for(int i=0;i<nnh;i++)

   {CB9CH wa=wh|T81t[tnh[i]].v.cand,wb,wx;

    for(int j=0;j<nnh;j++) if(j-i) wb|=T81t[tnh[j]].v.cand;

       wx=wa-wb-wr; // must not be an extra digit included in the UR

       if(wx.QC()==4) // we got it

       {int ir1=0; ir1+=T81t[tnh[i]].Keep(wx);

     for(int k=0;k<nth;k++)  ir1+=T81t[th[k]].Keep(wx);

     if(ir1) { E$.E("UR/UL hls wx="); E$.Enl(wx.String());

              E$.Enl("UR/UL hidden locked set"); return 1;}   

       }

   }

 }

 

return 0;}

 

// look for nacked sets n

int CRIN::T2_el_set_nacked(USHORT len)

 {if(ntd<(nautres-1)) return 0;  // minimum without extra digit

 

 if(ntd && (nautres==2)&&(len==1)) // look for a nacked pair

  {for(int i=0;i<ntd;i++)

   {int i8=td[i];CB9CH ww=T81t[i8].v.cand; 

    if( ww.f==wr.f) // we got it    

       { ZINFL zwel1=zwel; zwel1.Clear(i8);

         if(T81->Clear(zwel1,wr  ))

              { E$.Enl("UR/UL nacked pair");return 1;}

       }}

  }

 

 if(len<2) return 0;// nothing else if a pair is expected

 

// first   pattern is nacked triplet no extra digit

if(nautres==3 && ntd>2 && len==2)

 { ZINFL zwel1=zwel; int n=0; 

   for (int i=0;i<ntd;i++)      if(!(T81t[td[i]].v.cand-wr).f) 

                                  { n++; zwel1.Clear(td[i]);}

   if(n==2 && T81->Clear(zwel1,wr  ))

                     { E$.Enl("UR/UL nacked LS3");return 1;}

 }

 

// second  pattern : directly correct (may be with extra digit)

if(((ntd+1)==wd.QC())  && (len== ntd))

 { ZINFL zwel1=zwel;

   for (int i=0;i<ntd;i++)  zwel1.Clear(td[i]);

   if(T81->Clear(zwel1,wd  ))

              { E$.E("UR/UL nacked LS");E$.Enl(ntd+1);return 1;}

 }

// third  pattern is  "one cell in excess"

//should cover several situations

if(ntd>=nautres && (len==(ntd-1)))

 { for (int i=0;i<ntd;i++)

       {CB9CH wdx=wr;    // wr is the minimum fo the nacked lock set

        for (int j=0;j<ntd;j++) if(j-i) wdx|=T81t[td[j]].v.cand;

        // check if now correct

             if(ntd==wdx.QC()) //  one cell less ntd must be number of digits

       { ZINFL zwel1=zwel;

        for (int j=0;j<ntd;j++)  if(j-i)zwel1.Clear(td[j]);

              if(T81->Clear(zwel1,wdx  ))

                 { E$.E("UR/UL nacked LS");E$.Enl(ntd);return 1;}

       }

     }

  }

 

// fourth pattern,  we look now for something with 1 extra cell "over all"

// have an example of naked quad, but can be simpler

if(nnh>=nautres && (len==(nnh-1)))

 {for (int i=0;i<nnh;i++)

       {CB9CH wdx=wr;    // wr is the minimum fo the nacked lock set

        for (int j=0;j<nnh;j++) if(j-i) wdx|=T81t[tnh[j]].v.cand;

        // check if now correct

        if(nnh==wdx.QC()) //  one cell less nnnh must be number of digits

       { ZINFL zwel1=zwel;

        for (int j=0;j<nnh;j++)  if(j-i)zwel1.Clear(tnh[j]);

        if(T81->Clear(zwel1,wdx  ))

                 { E$.E("UR/UL nacked LS");E$.Enl(nnh);return 1;}

       }

     }

}

// fifth pattern,  we look now for something with 2 extra cells "over all"

if(nnh>=(nautres+1)&& (len==(nnh-2)) )

 {for (int i1=0;i1<nnh-1;i1++)for (int i2=i1+1;i2<nnh;i2++)

       {CB9CH wdx=wr;    // wr is the minimum fo the nacked lock set

        for (int j=0;j<nnh;j++)

                if((j-i1) &&(j-i2))    wdx|=T81t[tnh[j]].v.cand;

        // check if now correct

     if((nnh-1)==wdx.QC()) //  one cell less ntd must be number of digits

       { ZINFL zwel1=zwel;

        for (int j=0;j<nnh;j++) 

                      if((j-i1) &&(j-i2))zwel1.Clear(tnh[j]);

        if(T81->Clear(zwel1,wdx  ))

                 { E$.E("UR/UL nacked LS");E$.Enl(nnh-1);return 1;}

       }

     }

  }

 

// sixth pattern,  we look now for something with 3 extra cells "over all"

// has been seen

if(nnh>=(nautres+2)&& (len==(nnh-3)) )

 {//E$.Enl("look for nacked LS + extra digit less 3 cells");

        for (int i1=0;i1<nnh-2;i1++)for (int i2=i1+1;i2<nnh-1;i2++)

     for (int i3=i2+1;i3<nnh;i3++)

       {CB9CH wdx=wr;    // wr is the minimum fo the nacked lock set

        for (int j=0;j<nnh;j++)

                if((j-i1) &&(j-i2)&&(j-i3))    wdx|=T81t[tnh[j]].v.cand;

        // check if now correct

     if((nnh-2)==wdx.QC())

       { ZINFL zwel1=zwel;

        for (int j=0;j<nnh;j++) 

                      if((j-i1) &&(j-i2)&&(j-i3))zwel1.Clear(tnh[j]);

         if(T81->Clear(zwel1,wdx  ))

                 { E$.E("UR/UL nacked LS");E$.Enl(nnh-2);return 1;}

       }

     }

  }   

return 0;}