SEclone  solving main routine  jdk.Traite()

 

Here really start the solving process.

After a small number of “opening” tasks, we enter an endless loop “while”.

  (the limit of 1000 is set “just in case” )

Here the process is cancelled after the search of BUGs

 

A loop start with a control of end conditions in case an ED or EP filter has been set;

Then, the new cycle is prepared.

And start the analysis of solving techniques in the way Sudoku Explainer wants them.

Note: the start of the cycle is included in the former jdk.cpp file

 

int JDK::Traite()

{//================== assign clues to start

 cInit(1); PKInit();

 T81->init();  //initial candidats au lieu de Traite_Init();

 for(int i=0; i<81;i++)  // first assignment from clues

     {int w=gg.pg[i];if(w>'0' && w<='9') T81->Fixer(w-'1',i,2);}

 cReport(); // and preparing T81 from PM per digit

 

aigstop=0; 

o$.Init();

E$.Enl( );// new line in case test is done

 

 //===========================================================

while (o$.cycle++<1000)  

  { if   (aigstop){o$.Seterr(5); break; }

 

    if(o$.is_ed_ep())return 0;// ed pur et filtres

 

    if   (!Recale())  {o$.Seterr(6);break;}

    if   (!gg.NBlancs()) break; // finished

       if   (Directs ())

         {o$.Step(LastCell); if(o$.ir>1)return 0; else if(o$.ir)continue;

          if( FaitDirects(LastCell)) {o$.SetEr();continue;}   //1.0

 

          o$.Step(SingleBox); if(o$.ir>1)return 0; else if(o$.ir)continue;

          if( FaitDirects(SingleBox)) {o$.SetEr();continue;}  //1.2

 

          o$.Step(Single_R_C); if(o$.ir>1)return 0; else if(o$.ir)continue;

          if( FaitDirects(Single_R_C)) {o$.SetEr();continue;}  //1.5

         }

       Actifs(); // update of active cells must be done from here

 

       o$.Step(Single_after_Locked); if(o$.ir>1)return 0; else if(o$.ir)continue;

    if(TraiteLocked(Single_after_Locked)){o$.SetEr();continue;}  //1.7

 

       o$.Step(HiddenPair_single); if(o$.ir>1)return 0; else if(o$.ir)continue;

    if(yt.Tiroirs(2,1,1)){o$.SetEr();continue;}  //2.0

 

 

       if   (Directs ())

         {o$.Step(NakedSingle); if(o$.ir>1)return 0; else if(o$.ir)continue;

          if( FaitDirects(NakedSingle)) {o$.SetEr();continue;}}  //2.3

 

 

    o$.Step(HiddenTriplet_single); if(o$.ir>1)return 0; else if(o$.ir)continue;

    if(yt.Tiroirs(3,1,1)){o$.SetEr();continue;}  //2.5

 

       o$.Step( Locked_box); if(o$.ir>1)return 0; else if(o$.ir)continue;

    if(TraiteLocked( Locked_box)){o$.SetEr();continue;}  //2.6

 

       o$.Step( Locked_RC); if(o$.ir>1)return 0; else if(o$.ir)continue;

    if(TraiteLocked( Locked_RC)){o$.SetEr();continue;}  //2.8

 

       o$.Step(NakedPair); if(o$.ir>1)return 0; else if(o$.ir)continue;

    if(yt.Tiroirs(2,0,0)){o$.SetEr();continue;}  //3.0

 

 

       o$.Step(XWing); if(o$.ir>1)return 0; else if(o$.ir)continue;

    if(yt.XW(2)){o$.SetEr();continue;}  //3.2

 

       o$.Step(HiddenPair); if(o$.ir>1)return 0; else if(o$.ir)continue;

    if(yt.Tiroirs(2,1,0)){o$.SetEr();continue;}  //3.4

 

       o$.Step(Naked_triplet); if(o$.ir>1)return 0; else if(o$.ir)continue;

    if(yt.Tiroirs(3,0,0)){o$.SetEr();continue;}  //3.6

 

       o$.Step(swordfish); if(o$.ir>1)return 0; else if(o$.ir)continue;

    if(yt.XW(3)){o$.SetEr();continue;}  //3.8

 

       o$.Step(HiddenTriplet); if(o$.ir>1)return 0; else if(o$.ir)continue;

    if(yt.Tiroirs(3,1,0)){o$.SetEr();continue;}  //4.0

 

 

    jdk.Copie_T_c(); // to be done now

    zpaires.CreerTable(); // pour filtrage, on doit l'avoir

 

 

 

       o$.Step(XYWing); if(o$.ir>1)return 0; else if(o$.ir)continue;

    if(zpaires.XYWing()){o$.SetEr();continue;}  //4.2

 

       o$.Step(XYZWing); if(o$.ir>1)return 0; else if(o$.ir)continue;

    if(zpaires.XYZWing()){o$.SetEr();continue;}  //4.4

 

    If(o$.ot)T81->Candidats();

 

       o$.Step(UniqueRect1); if(o$.ir>1)return 0; else if(o$.ir)continue;

    if(T81->RIN()){o$.SetEr();continue;}  //4.5

 

       o$.Step(UniqueRect2); if(o$.ir>1)return 0; else if(o$.ir)continue;

    if(y$t.Traite(46)){o$.SetEr();continue;}  //4.6 t

       if(zpaires.UL()){o$.SetEr();continue;}   

 

 

       o$.Step(UniqueRect3); if(o$.ir>1)return 0; else if(o$.ir)continue;

    if(y$t.Traite(47)){o$.SetEr();continue;} //4.7

       if(tult.Traite(47)){o$.SetEr();continue;}

 

       o$.Step(UniqueLoop1); if(o$.ir>1)return 0; else if(o$.ir)continue;

    if(y$t.Traite(48)){o$.SetEr();continue;} //4.7

       if(tult.Traite(48)){o$.SetEr();continue;}  //4.8

                             

       o$.Step(UniqueLoop2); if(o$.ir>1)return 0; else if(o$.ir)continue;

       if(tult.Traite(49)){o$.SetEr();continue;}  //4.9

 

       o$.Step(NakedQuad); if(o$.ir>1)return 0; else if(o$.ir)continue;

       if(tult.Traite(50)){o$.SetEr();continue;}  //4.9

    if(yt.Tiroirs(4,0,0)){o$.SetEr();continue;}  //5.0

 

       o$.Step(UniqueLoop3); if(o$.ir>1)return 0; else if(o$.ir)continue;

       if(tult.Traite(51)){o$.SetEr();continue;}  //5.1

 

       o$.Step(Jellyfish); if(o$.ir>1)return 0; else if(o$.ir)continue;

       if(tult.Traite(52)){o$.SetEr();continue;}  //5.2

    if(yt.XW(4)){o$.SetEr();continue;}  //5.2

 

       o$.Step(HiddenQuad); if(o$.ir>1)return 0; else if(o$.ir)continue;

    if(yt.Tiroirs(4,1,0)){o$.SetEr();continue;}  //5.4

 

 

       o$.Step(BUG); if(o$.ir>1)return 0; else if(o$.ir)continue;

    if(zpaires.BUG()){o$.SetEr();continue;}  //5.6 a 6.1

 

 

// this is the start of processes using the tagging infrastructure.

 

      aigstop=2; break; // set error code and exit

     }    

//========================================================================= 

 E$.E("fin traitement aigstop=");E$.Enl(aigstop );

 gg.Image("fin");

return aigstop;}

 

 

 

Naming the techniques is done in the file (not complete)

 

#include "h\_00_  rat_enum.h"            // enum list of solving techniques

 

 

enum SolvingTechnique {

    LastCell=10,                       // last cell in row column box

    SingleBox=12,               // single box

    Single_R_C=15,              // single row column

    Single_after_Locked=17,         // locked in box -> clearing row/col ?? giving a fix??

    PointingClaiming=19,        // unknown

    HiddenPair_single=20,           // hidden pair -> hidden fix

    NakedSingle=23,                         // cell one candidate

    HiddenTriplet_single=25,    // Hidden triplet -> fix

    Locked_box=26,                          // locked in box  no fix

    Locked_RC=28,                           // locked in row/col  no fix

    NakedPair=30,               // 2 cells containing 2 digits

    XWing=32,                   // XWing

    HiddenPair=34,              // 2 digits locked in 2 cell

    Naked_triplet=36,           // 3 cells containing 3 digits  

    swordfish=38,               // swordfish  

    HiddenTriplet=40,           // 3 digits in 3 cells

    XYWing=42,

    XYZWing=44,

    UniqueRect1=45,              // UR type(s)  basic, on digit active, twins

    UniqueRect2=46,              // UR hidden locked setlocked set

    UniqueRect3=47,              // UR naked locked set

    UniqueLoop1=48,              // UL  locked set also URnaked quad

    UniqueLoop2=49,              // UL naked locked set

    NakedQuad=50,

    UniqueLoop3=51,              // UL highest rating

    Jellyfish=52,

    HiddenQuad=54,

    BUG=56,                      // in fact 5.6 to 6.1

 

    AlignedPairExclusion=62,   

       AIC_X_cycle=65,

    Forcing_ChainX=66,          //  at least 6.6 6.7 f(length)

       AIC_XY=70,

       AlignedTripletExclusion=75 ,

    NishioForcingChain=75 ,

    MultipleForcingChain=80,

    DynamicForcingChain=85,

    DynamicForcingChainPlus=90,

    NestedForcingChain

};