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(); }
int main(int args, const char * argv[]) { int cpu = GetCPU(args, argv); New(); LifeState* pat = NewState("14bo$15bo13bobo$13b3o13b2o$30bo$3bobo5bo$4b2o3bobo16bo$4bo5b2o14b2o$27b2o3$4bo4b2o4bo3bo12bo$5bo4b2o4bobo12bo$3b3o3bo5b2ob2o11b3o3$16b2ob2o$16bo3bo$17bobo$16b2ob2o$4b3o23b3o$6bo23bo$5bo12bo12bo$17bobo$2o16bo16b2o$b2o31b2o$o35bo$9bo17bo$9b2o15b2o$8bobo15bobo2$20b3o$20bo$21bo2$15b3o$17bo$16bo!", -10, -10); LifeState* gld = NewState("obo$b2o$bo!", 8, -9); LifeIterator *iter = NewIterator(gld, -20, -20, 40, 40, 4); printf("\nSearching..."); do { New(); PutState(pat); PutState(iter); Run(37); if(IsDart() == YES) { printf("\n Found it!! \n"); Print(); New(); PutState(pat); PutState(iter); printf("\n"); PrintRLE(); printf("\n\n"); Print(); printf("\n\n\n"); Print(iter); getch(); printf("\nsearching..."); } }while(Next(iter) == SUCCESS); printf("\nFinished"); getch(); }
int main() { //Always start with new New(); printf("\n\n================LifeAPISample with explanation: ============="); printf("\n\n----- Blockic seeds for glider reflection example: ---\n\n\n\n"); Continue(); //create block and glider states LifeState* blck = NewState("2o$2o!"); LifeState* gld = NewState("2o$obo$o!"); //create iterators for glider and block (the second block is at (0,0)) //The iterators replace 3 loops, on x, y, and s - you just use (Next), they also work together. //start at (-10, -19) - iterate x in width of 20, y in width of 10 LifeIterator *blckiter1= NewIterator(blck, -10, -10, 20, 10); //start at (-16, 6) - iterate x in width of 35, y remains. LifeIterator *glditer= NewIterator(gld, -16, 5, 35, 1); // Let's measure performance (remove all Continue(); statements to see the real time). clock_t t = clock(); do { //clear previous junk from GlobalState New(); //PutState works with LifeState and LifeIterator //Place block at (0,0) PutState(blck); //place block and glider, by their iterators data. PutState(glditer); PutState(blckiter1); //Get population (to avoid blocks placed on same spot) int pop = GetPop(); //block + block + glider if(pop != 5 + 4 + 4) continue; Run(1); //Check if blocks are interfering. if(pop != GetPop()) continue; //Just iterate - the glider will run all over tha place - we're on torus anyway Run(180); //potential glider if(GetPop() == 5) { int min = GlobalState->min; int max = GlobalState->max; //evolve Run(16); if(GetPop() == 5 && !(min == GlobalState->min && max == GlobalState->max)) { //Success! let's report it here. //We do the same as we did previously to get here: New(); PutState(glditer); PutState(blckiter1); PutState(blck); printf("\n\n SUCCESS!! \n\n"); printf("Here is the blockic seed: \n\n"); //The iterators state is change only on Next. Print(); PrintRLE(); printf("\n\nYou can copy-paste the rle into golly (remember to remove \"new line\" symbols)!! \n\n"); Continue(); } } } //You can use Next for both iterators (works for up to 6) while(Next(blckiter1, glditer) == SUCCESS); t = clock() - t; printf ("Total time: %d miliseconds\n",t); printf("\n\n\n\n\n THE END !!!\n\n\n\n\n\n"); getch(); return 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(); }