Beispiel #1
0
int main()
{
	New();
	
	LifeState* snakePair = NewState("2ob2o$o3bo$bobo$2ob2o!", -15, -7);
	LifeTarget* target = NewTarget(snakePair);
	
	//For lower part
	LifeState* synth = NewState("obo$b2o$bo13$4bo$4b2o$3bobo$11b3o$11bo$12bo$18bo$17b2o$17bobo!", -20, -20);
	LifeState* gld = NewState("bo$2o$obo!", -6, 13, 1, 0, 0, 1);
	LifeIterator* iter = NewIterator(gld, -30, -30, 60, 60, 4);
	LifeTarget* targetEmpty = NewTarget(Captures[1], NewState("5o2bo2b5o$5ob3ob5o$6obob6o$5o2bo2b5o$15o$15o$15o$15o$15o$15o$15o$15o$15o$15o$15o$15o!", -20, -7));

	//For upper part
	//LifeState* synth = NewState("obo$b2o$bo13$4bo$4b2o$3bobo$11b3o$11bo$12bo$18bo$17b2o$17bobo5$11bo$10b2o$10bobo!", -20, -20);
	//LifeTarget* targetEmpty = NewTarget(Captures[1], NewState("15o$15o$15o$15o$15o$15o$15o$15o$15o$15o$15o$5o2bo2b5o$5ob3ob5o$6obob6o$5o2bo2b5o!", -20, -18));
	//LifeState* gld = NewState("2bo$2o$b2o!", -2, -23, 1, 0, 0, -1);
	//LifeIterator* iter = NewIterator(gld, -30, -10, 60, 60, 4);
	
	do
	{
		New();
		
		PutState(synth);
		PutState(iter);
		
		
		Run(210);
		Capture(0);
		Run(2);
		
		//if(ContainsTarget(targetEmpty) == NO && ContainsTarget(target) == YES && GetPop() != 12 + 5)
		if(ContainsTarget(targetEmpty) == NO && ContainsTarget(target) == YES)// && !AreEqual(0))
		{
			Print();
			
			New();
			
			PutState(synth);
			PutState(iter);
			
			PrintRLE();
			//Print();
			
			printf("\nSUCCESS\n");
			getchar();
			printf("\nSearching\n");
			
		}
	}
	while(Next(iter) == SUCCESS);
	
	printf("\nFinish\n");
	
	getchar();
}
Beispiel #2
0
STATIC RET_T imply( TARGET *targ, const char *drive, const char *dir,
    const char *fname, const char *ext, bool must )
/********************************************************************
 * targ     is the target to be implied
 * drive    is the drive of the target
 * dir      is the path of the target
 * fname    is the portion of targ's name without the extension
 * ext      is the extension of targ's name
 * must     must we make this target?
 *
 * RET_SUCCESS - performed cmds,
 * RET_WARN unable to imply,
 * RET_ERROR - perform failed
 */
{
    SUFFIX      *srcsuf;
    CREATOR     *cur;
    SUFFIX      *cursuf;
    TARGET      *imptarg = NULL;
    RET_T       ret;
    bool        newtarg;
    UINT32      startcount;
    char        *buf;
    SLIST       *curslist;
    SLIST       *slist;     // Slist chosen for sufsuf
    SLIST       *slistDef;  // Slist that has dependent path = ""
    SLIST       *slistEmptyTargDepPath;
    bool        UseDefaultSList;
    int         slistCount;

    srcsuf = FindSuffix( ext );
    if( srcsuf == NULL || srcsuf->creator == NULL ) {
        PrtMsg( DBG | INF | IMP_ENV_M, targ->node.name, M_HAS_NO_IMPLICIT );
        return( RET_WARN );
    }
    PrtMsg( DBG | INF | IMP_ENV_M, targ->node.name, M_CHECKING_IMPLICIT );
    startcount = cListCount;

    for( cur = srcsuf->creator; cur != NULL; cur = cur->next ) {
        cursuf = cur->suffix;

        /* allocate a buffer */
        buf = MallocSafe( _MAX_PATH );
        slist = NULL;
        slistDef = NULL;
        slistEmptyTargDepPath = NULL;

        ret = RET_ERROR;

        UseDefaultSList = true;
        /* find path in SLIST */
        slistCount = 0;
        for( curslist = cur->slist; curslist != NULL && ret != RET_SUCCESS; curslist = curslist->next ) {
            _makepath( buf, drive, dir, NULL, NULL );
            FixName( buf );
            /*
             * note the path of the current target must match the
             * path as specified in the slist
             */
            if( stricmp( buf, curslist->targ_path ) == 0 ) {
                /* build filename for implied target */
                _makepath( buf, NULL, curslist->dep_path, fname, cursuf->node.name );
                /* try to find this file on path or in targets */
                ret = TrySufPath( buf, buf, &imptarg, false );
                if( ret == RET_SUCCESS ) {
                    slist = curslist;
                    /* later on we need to check if implied target does not */
                    /* exist we need to create it on the first directory we */
                    /* see on the SLIST since                               */
                    /* the first on the list is the one that was defined    */
                    /* last in the makefile                                 */
                } else if( slistDef == NULL ) {
                    slistDef = curslist;
                }
            }
            if( *curslist->targ_path == NULLCHAR && *curslist->dep_path == NULLCHAR ) {
                slistEmptyTargDepPath = curslist;
            }

            if( slistCount > 0 && slistEmptyTargDepPath != NULL ) {
                UseDefaultSList = false;
            }
            ++slistCount;
        }

        if( UseDefaultSList && slist == NULL && !Glob.compat_nmake ) {
            _makepath( buf, NULL, NULL, fname, cursuf->node.name );
            /* try to find this file on path or in targets */
            ret = TrySufPath( buf, buf, &imptarg, false );
            switch( ret ) {
            case RET_WARN:
                break;
            case RET_ERROR:
                if( !Glob.compat_nmake ) {
                    slistDef = slistEmptyTargDepPath;
                }
                break;
            case RET_SUCCESS:
                slist = slistEmptyTargDepPath;
                break;
            }
        }

        if( ret == RET_ERROR && slistDef == NULL ) {
            /*
             * No Default Slist found so must continue and find
             * another slist
             */
            FreeSafe( buf );
            continue;
        }

        if( (ret == RET_SUCCESS && imptarg == NULL) || ret == RET_ERROR ) {
            /* Either file doesn't exist, or it exists and we don't already
             * have a target for it.  Either way, we create a new target.
             */
            if( ret == RET_ERROR ) {
                slist = slistDef;
                /* file doesn't exist, assume in directory */
                /* pointed to by the slistDef              */
                _makepath( buf, NULL, slist->dep_path, fname, cursuf->node.name );

            }
            newtarg = true;
            imptarg = NewTarget( buf );
            FreeSafe( buf );        /* don't need any more */
            getStats( imptarg );
            imptarg->busy = true;   /* protect against recursion */
            if( imply( imptarg, NULL, slist->dep_path, fname, cursuf->node.name, false ) == RET_ERROR ) {
                imptarg->error = true;
            }
            if( startcount != cListCount && (Glob.noexec || Glob.query) ) {
                imptarg->touched = true;
                imptarg->executed = true;
            }
            imptarg->updated = true;
            imptarg->busy = false;
        } else {
            /* We already know about imptarg, so just update it */
            assert( imptarg != NULL );
            FreeSafe( buf );        /* don't need any more */
            newtarg = false;        /* this isn't a new target */
            Update( imptarg );
        }

        /* We've tried our best to make the imptarg, check if it exists
         * after our efforts.
         */
        if( targExists( imptarg ) ) {
            /* it exists - now we perform the implicit cmd list, and return */
            ret = implyMaybePerform( targ, imptarg, slist->cretarg, must );
            if( newtarg && !Glob.noexec ) {
                /* destroy the implied target, because the info in the target
                 * structure is nicely stored on disk (unless Glob.noexec)
                 */
                KillTarget( imptarg->node.name );
            }
            implyDebugInfo( targ, startcount );
            return( ret );
        } else if( newtarg ) {
            /* we created an unsuccessful target - so destroy it */
            KillTarget( imptarg->node.name );
        }

        /* We couldn't imply with this suffix... try next one */
    }
    implyDebugInfo( targ, startcount );
    return( RET_WARN );
}
Beispiel #3
0
int main()
{
	printf("\n\n================LifeAPISample with explanation: =============\n\n");
	printf("\n\n           Target with two gliders search example: \n\n");
	
	//Always start with New();
	New();
	
	//Initial pattern
	LifeState* pat =  NewState("obo$b2o$bo9$4bo$4b2o$3bobo$7b3o$7bo$8bo$14bo$13b2o$13bobo!", -20, -20);
	
	//target and inverse target
	LifeState* target =  NewState("$b2ob2o$bo3bo$2bobo$b2ob2o3$3bo$2bobo$3bo!", -18, -10);
	LifeState* inverse = NewState("7o$o2bo2bo$ob3obo$2obob2o$o2bo2bo$7o$7o$3ob3o$2obob2o$3ob3o$7o!", -18, -10);
	
	//Life target object contains the on and the off cells
	LifeTarget * fulltarget = NewTarget(target, inverse);
	
	//glider with (+1, -1) direction at (0,0)
	LifeState* gld =  NewState("b2o$obo$2bo!", 0, 0);
	
	New();
	PutState(pat);
	Print();
	printf("\n\n We have durty snake pair synthesis \n\n");
	Continue();
	Run(21);
	Print();
	Continue();
	printf("\n\n It destoryed after 2 generations \n\n");
	Run(2);
	Print();
	Continue();
	
	printf("\n\n We want to place 2 gliders to reach this configuration \n\n");
	
	New();
	PutState(target);
	Print();
	
	Continue();

	New();
	PutState(inverse);
	Print();
	
	printf("\n\n While all these cells should be off \n\n");
	Continue();

	printf("\n\nSearching... \n\n");
	
	//Gldier iterators always have 4 states
	LifeIterator *iter1 = NewIterator(gld, -27, 2, 15, 15, 4);
	LifeIterator *iter2 = NewIterator(gld, -27, 2, 15, 15, 4);
	
	do
	{
		if(Validate(iter1, iter2) == FAIL)
			continue; 
			
		New();
		
		PutState(pat);
		PutState(iter1);
		PutState(iter2);
		
		//100 should be enough
		Run(100);
		
		//ContainsTarget checks both "on" and "off" cells
		if(ContainsTarget(fulltarget) == YES)
		{
			printf("\nFound!\n\n");
			
			New();
			
			PutState(pat);
			PutState(iter1);
			PutState(iter2);

			PrintRLE();
			printf("\n\n");
			
			Print();
			
			Run(100);
			
			Print();
			
			Continue();
			printf("\Searching...\n\n");
		}
	}while(Next(iter1, iter2, "none") == SUCCESS);
	
	printf("\nFinished");
	getch();
}