int IsDart() { int pop40 = YES; //Let's make sure it's dart //it's population will drop to 34 and back to 40 - it's either some crazy p3 oscillator or dart. for(int i = 0; i < 10; i++) { if(GetPop() != 40) { pop40 = NO; break; } Run(1); if(GetPop() != 34) { pop40 = NO; break; } Run(2); } return pop40; }
int IsCollision() { int collision = NO; int pop = GetPop(); for(int i = 0; i < 6; i++) { Run(1); if(GetPop() != pop) { collision = YES; break; } } return collision; }
void LoadGraphin() { short lp; highest = -1; lp = 0; while (lp<14) { values[lp] = GetPop(lp); if (values[lp]>highest) highest = values[lp]; lp++; } if (highest == 0) highest = 1; lp = 0; while (lp<14) { odrvals[lp] = drvals[lp]; drvals[lp] = ((80 * values[lp]) / highest); lp++; } }
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("x = 0, y = 0, rule = B3/S23\n"); #pragma omp parallel { New(); LifeState* blck = NewState("2o$o$b3o$3bo!"); LifeState* gldL = NewState("3o$2bo$bo!"); LifeState* gldR = NewState("bo$o$3o!"); LifeIterator *iterL = NewIterator(gldL, -10, 5, 10, 1); LifeIterator *iterR1 = NewIterator(gldR, 0, -15, 10, 10, 4); LifeIterator *iterR2 = NewIterator(gldR, 0, -15, 10, 10, 4); int initPop = GetPop(blck); do{ #pragma omp single nowait { if(Validate(iterR1, iterR2) != FAIL) { New(); PutState(blck); PutState(iterL); PutState(iterR1); PutState(iterR2); int collide = NO; for(int i = 0; i < 4; i++) { if(GetPop() != 5 * 3 + initPop) { collide = YES; break; } Run(1); } if(collide != YES) { for(int i = 0; i < 300; i++) { Run(1); uint64_t gld = LocateAtX(GlobalState, _glidersTarget[0], 2); int found = NO; if(strlen(GlobalState->emittedGliders->value) != 0) break; int gen = GlobalState->gen; if(gld != 0 && GetPop() == 5) { found = YES; for(int j = 0; j < 4; j++) { if(GlobalState->gen%4 == 0) break; Run(1); } Capture(0); Move(Captures[0], (GlobalState->gen) / 4 + 4, (GlobalState->gen) / 4 + 4); Evolve(Captures[0], 2); New(); PutState(blck); PutState(iterL); PutState(iterR1); PutState(iterR2); PutState(Captures[0]); Run(gen); uint64_t gld = LocateAtX(GlobalState, _glidersTarget[0], 2); if(gld != 0 && GetPop() == 10) { New(); PutState(blck); PutState(iterL); PutState(iterR1); PutState(iterR2); PutState(Captures[0]); #pragma omp critical { printf(GetRLE(GlobalState)); printf("100$"); } } } if(found == YES) break; } } } } }while(Next(iterL, iterR1, iterR2, NO)); } printf("!"); printf("\n\nFINISH"); getchar(); }