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() { long long evolved_cells = 0; clock_t begin; //omp_set_num_threads(8); #pragma omp parallel { New(); LifeState* snark = NewState("3o$o4bo$obobo$obo2bo$o$ob3o!", -3, -3); New(); PutState(snark); int cycle = 0; for (int i = 0; i < 1243; i++) { Run(1); cycle += (64 * (2 + (GlobalState->max - GlobalState->min))); } #pragma omp single begin = clock(); #pragma omp for for (int iter_ix = 0; iter_ix < 30000; iter_ix++) { New(); PutState(snark); Run(1243); #pragma omp critical evolved_cells += cycle; } } clock_t end = clock(); double elapsed_secs = double(end - begin) / CLOCKS_PER_SEC; std::cout << (evolved_cells / 1000000000) / elapsed_secs << " BCO/s \n"; getchar(); }
void CConnectMR::Offover() { if (*_ppatmr != NULL) { (*_ppatmr)->UnInitOffline(); delete (*_ppatmr); *_ppatmr = NULL; } long ret = STATE_CONNECT_CLOSE; PutState(&ret); }
void CConnectMR::UninitATMR() { if (*_ppatmr != NULL) { CAudioTalkMR* patmr = *_ppatmr; (*_ppatmr)->UnInitialize(); delete (*_ppatmr); *_ppatmr = NULL; //MessageBox(NULL, _T("end"), NULL, MB_OK); } long ret = STATE_CONNECT_CLOSE; PutState(&ret); }
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(); }
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(); }
int CConnectMR::Connect() { long ret; int nPort = SERVER_PORT; char szBuffer[BUFFER_SIZE]; int nAddrLen; int nRet; SOCKET s; SOCKADDR_IN sa; WSAData wsaData; WORD wVersion = MAKEWORD(2,2); nRet = WSAStartup(wVersion, &wsaData); if (SOCKET_ERROR == nRet) { TRACEMSG("Socket init error\n"); ret = STATE_CONNECT_SOCKET; PutState(&ret); return ret; } s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (INVALID_SOCKET == s) { TRACEMSG("Socket was created failse:%d\n", WSAGetLastError()); ret = STATE_CONNECT_SOCKET; PutState(&ret); WSACleanup(); return ret; } int timeout=6000; //收发超时6秒 if(setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, (char*)&timeout, sizeof(timeout))) { TRACEMSG("socket setsockopt() failse:%d\n", WSAGetLastError()); ret = STATE_CONNECT_SOCKET; PutState(&ret); closesocket(s); WSACleanup(); return ret; } nAddrLen = sizeof(SOCKADDR_IN); memset(&sa, 0, nAddrLen); sa.sin_family = AF_INET; sa.sin_port = htons(nPort); //sa.sin_addr.s_addr = inet_addr("127.0.0.1"); sa.sin_addr.s_addr = inet_addr(_ip); nRet = connect(s, (LPSOCKADDR)&sa, nAddrLen); if (SOCKET_ERROR == nRet) { TRACEMSG("socket connect() failse:%d\n", WSAGetLastError()); ret = STATE_CONNECT_CONNECTSVR; PutState(&ret); closesocket(s); WSACleanup(); return ret; } memset(szBuffer, 0, BUFFER_SIZE); szBuffer[0] = '1'; szBuffer[1] = _type + '0'; //身份 strcpy(&szBuffer[2], _name); nRet = send(s, szBuffer, 2+strlen(_name), 0); if (SOCKET_ERROR == nRet) { TRACEMSG("Socket send() failse:%d\n", WSAGetLastError()); ret = STATE_CONNECT_SEND; PutState(&ret); closesocket(s); WSACleanup(); return ret; } _connecting = true; while (_connecting) { //_connecting = false; memset(szBuffer, 0, BUFFER_SIZE); nRet = recv(s, szBuffer, BUFFER_SIZE, 0); if (nRet == -1 && WSAGetLastError() == WSAETIMEDOUT) { if (_connecting) { // 超时 ret = STATE_CONNECT_TIMEOUT; } else { ret = STATE_CONNECT_CLOSE; closesocket(s); WSACleanup(); return ret; } } else if (nRet <= 0) //断开连接 { printf("Sokcet:%d, was disconnected.\n", s); ret = STATE_CONNECT_RECV; break; } else { printf("Socket:%d, %d, send data:%s\n", s, nRet, szBuffer); // 处理数据 if (nRet > 0) { char flag = *(char*)szBuffer; TRACE("Server ECHO back:%c\n", flag); if (flag == '0') { if (_type == IDENTITY_EXPERT || _type == IDENTITY_LISTENER) { // 等待作业员来连接 ret = STATE_CONNECT_WAITFOR; PutState(&ret); continue; } else { // 木有找到接线员,等等再说 //MessageBox(NULL, _T("木有找到接线员,请稍候再连接!"), _T("Frss"), MB_OK); ret = STATE_CONNECT_NOLISTENER; break; } } else if (flag == '1') { if (nRet > 4) { char* tarIp = inet_ntoa(*(in_addr*)(szBuffer+1)); TRACE("Server ECHO back: ip: %s\n", tarIp); if (nRet > 5) { char name[256]; strncpy(name, szBuffer+5, nRet-5); name[nRet-5] = '\0'; PutName(CA2T(name)); } if (_type == IDENTITY_EXPERT || _type == IDENTITY_LISTENER) { //if (MessageBox(NULL, _T("来自用户的通话将被接入!\n是否允许?"), _T("Frss"), MB_YESNO) == IDYES) { int ret1 = InitATMR(tarIp); if (ret1 != 0) { TRACE("udp error: %d\n", ret1); ret = STATE_CONNECT_UDPERROR; } else { ret = STATE_CONNECT_OK; } break; } //else //{ // ret = STATE_CONNECT_CLOSE; // break; //} } else { int ret1 = InitATMR(tarIp); if (ret1 != 0) { TRACE("udp error: %d\n", ret1); ret = STATE_CONNECT_UDPERROR; } else { ret = STATE_CONNECT_OK; } break; } } else { ret = STATE_CONNECT_WRONGDATA; break; } } else { ret = STATE_CONNECT_WRONGDATA; break; } } else { ret = STATE_CONNECT_WRONGDATA; break; } } } PutState(&ret); closesocket(s); WSACleanup(); return ret; }