src/puzzle.cpp
/*  process to find a nested chain in dynamic mode (level 4)
    only basic strong and weak links
	but dynamic search (using basic sets)

*/
process to find a nested chain in dynamic mode (level 4)
only basic strong and weak links
but dynamic search (using basic sets)
process to find a nested chain in dynamic mode ( level 4 ) only basic strong and weak links but dynamic search ( using basic sets )
int PUZZLE::CaseNestedLevel4( USHORT tag,USHORT target)  {
	if(0) {
		EE.E("\n\nnested level 4 for tag ");
		zpln.ImageTag(tag);
		EE.E("  target ");
		zpln.ImageTag(target);
		EE.Enl();
	}
	chain4_to = chain4_dpn.t; 
	for(int i = 0; i < 640; i++)
		chain4_tsets[i] = 0;
	chain4_npas = 0;
	chain4_steps[0]=(*cum);  
	chain4_steps[0].Set(tag);  
	chain4_allsteps = chain4_cumsteps[0] = chain4_steps[0];  
	chain4_buf[0]=tag;        
	chain4_tx[0] = chain4_buf;
	chain4_itx[0] = 1; 
	nested_aig2 = 1;
	while(nested_aig2 && chain4_npas++ <= pasmax) {
		nested_aig2=0; 
		chain4_cum = &chain4_cumsteps[chain4_npas-1];
		chain4_step = &chain4_steps[chain4_npas];
		chain4_ta = chain4_tx[chain4_npas-1];
		chain4_ita = chain4_itx[chain4_npas-1];
		chain4_tx[chain4_npas]=&chain4_ta[chain4_ita];
		NestedChainWhile(tag);                    
		if(!nested_aig2)
			return 0;			
		chain4_cumsteps[chain4_npas] = chain4_allsteps;   
		(*chain4_step) = chain4_allsteps;
		(*chain4_step)-=(*chain4_cum);  
		(*chain4_step).String(chain4_tx[chain4_npas],chain4_itx[chain4_npas] );
        if(opdiag){   
		  EE.E(chain4_npas);EE.E("pas ncase lvl4 ");Image((*chain4_step),"step",0);
		  Image(chain4_allsteps,"chain4_allsteps",0);
		  Image(allsteps,"allsteps",0);
		  EE.Enl();
		}
	    if((*chain4_step).IsEmpty() ||chain4_npas>30 ){
        EE.Enl("check if null or 30 pas");
		return 0;
		}
		if(chain4_allsteps.On(target)){ 
			if(0){ 
               EE.Enl("target reached step"); EE.Enl( chain4_npas);
			   EE.E(" target ="); zpln.ImageTag(target);EE.Esp();
			   if(chain4_npas==1){
				   Image(chain4_steps[1],"step1",0);
				   Image(chain4_steps[0],"step0",0);
				   Image(chain4_allsteps,"chain4_allsteps",0);
 				   Image(allsteps,"allsteps",0);
				   stop_rating=1;
 			   }
			}
			USHORT itt=NestedChainGoBack(target);
			if(!itt) return 0; 
			chain4_bf|=back4_bfsource;		
			return itt;
		}
	}
return 0;}
int PUZZLE :: CaseNestedLevel4 ( USHORT tag , USHORT target ) { if ( 0 ) { EE . E ( " \n \n " ) ; zpln . ImageTag ( tag ) ; EE . E ( " " ) ; zpln . ImageTag ( target ) ; EE . Enl ( ) ; } chain4_to = chain4_dpn . t ; for ( int i = 0 ; i < 640 ; i ++ ) chain4_tsets [ i ] = 0 ; chain4_npas = 0 ; chain4_steps [ 0 ] = ( * cum ) ; chain4_steps [ 0 ] . Set ( tag ) ; chain4_allsteps = chain4_cumsteps [ 0 ] = chain4_steps [ 0 ] ; chain4_buf [ 0 ] = tag ; chain4_tx [ 0 ] = chain4_buf ; chain4_itx [ 0 ] = 1 ; nested_aig2 = 1 ; while ( nested_aig2 && chain4_npas ++ <= pasmax ) { nested_aig2 = 0 ; chain4_cum = & chain4_cumsteps [ chain4_npas - 1 ] ; chain4_step = & chain4_steps [ chain4_npas ] ; chain4_ta = chain4_tx [ chain4_npas - 1 ] ; chain4_ita = chain4_itx [ chain4_npas - 1 ] ; chain4_tx [ chain4_npas ] = & chain4_ta [ chain4_ita ] ; NestedChainWhile ( tag ) ; if ( ! nested_aig2 ) return 0 ; chain4_cumsteps [ chain4_npas ] = chain4_allsteps ; ( * chain4_step ) = chain4_allsteps ; ( * chain4_step ) -= ( * chain4_cum ) ; ( * chain4_step ) . String ( chain4_tx [ chain4_npas ] , chain4_itx [ chain4_npas ] ) ; if ( opdiag ) { EE . E ( chain4_npas ) ; EE . E ( " " ) ; Image ( ( * chain4_step ) , " " , 0 ) ; Image ( chain4_allsteps , " " , 0 ) ; Image ( allsteps , " " , 0 ) ; EE . Enl ( ) ; } if ( ( * chain4_step ) . IsEmpty ( ) || chain4_npas > 30 ) { EE . Enl ( " " ) ; return 0 ; } if ( chain4_allsteps . On ( target ) ) { if ( 0 ) { EE . Enl ( " " ) ; EE . Enl ( chain4_npas ) ; EE . E ( " " ) ; zpln . ImageTag ( target ) ; EE . Esp ( ) ; if ( chain4_npas == 1 ) { Image ( chain4_steps [ 1 ] , " " , 0 ) ; Image ( chain4_steps [ 0 ] , " " , 0 ) ; Image ( chain4_allsteps , " " , 0 ) ; Image ( allsteps , " " , 0 ) ; stop_rating = 1 ; } } USHORT itt = NestedChainGoBack ( target ) ; if ( ! itt ) return 0 ; chain4_bf |= back4_bfsource ; return itt ; } } return 0 ; }
process to find a nested chain in dynamic mode (level 4)
only basic strong and weak links
but dynamic search (using basic sets)
process to find a nested chain in dynamic mode ( level 4 ) only basic strong and weak links but dynamic search ( using basic sets )
//Image(allsteps,"allsteps depart",0); // we use the table  for nested // start with the known status // plus the tag // and expand the tag in cycle one // initial is tag to go forward //--------------------- loop  forward // while cycle // nothing happenned finished should not be // check if target has been reached // we compute back the length and  the sequence  // we store the chain  if ok // should always be ok // end while