void Gen( int p, int s, int cL ) { int np, temp; if (p > n) PrintIt(); else { if (cL==0 && p <= ub+2 ) par[p] = L[p] = p-1; else if (par[p-cL] < s) { par[p] = par[s]; L[p] = L[s]; } else { par[p] = cL + par[p-cL]; L[p] = 1+L[par[p]]; } temp = rChi[par[p]]; if (chi[par[p]] <= mc) { ++chi[par[p]]; rChi[par[p]] = p; nextp[p] = chi[par[p]] < mc ? par[p] : nextp[par[p]]; Gen( p+1, s, cL ); /* <==== recursive call */ --chi[par[p]]; rChi[par[p]] = temp; } nextp[p] = nextp[par[p]]; np = nextp[p]; while (np >= 1) { par[p] = np; L[p] = 1 + L[np]; ++chi[np]; temp = rChi[np]; rChi[np] = p; if (chi[np] >= mc) nextp[p] = nextp[np]; Gen( p+1, temp, p-temp ); /* <==== recursive call */ --chi[np]; rChi[par[p]] = temp; np = nextp[np]; nextp[p] = np; } } }
void GenOdd(){ Gen(2); Gen(cmMod); Gen(0); Gen(0); // јдрес перехода вперед Gen(cmIfEQ); }
int main( int argc, char *argv[] ) { int i; /* first set all the parameters */ printf( "Enter n (0 for help): " ); scanf( "%d", &n ); if (n == 0) { printhelp(); return(0); } printf( "Enter format (0,1,2,3): " ); scanf( "%d", &out_format ); printf( "Enter MaxChild, lb , ub: " ); scanf( "%d%d%d", &mc, &lb, &ub ); if(out_format==1) outputP = 1; if(out_format==2) outputL = 1; if(out_format==3) {outputP = 1; outputL = 1;} num = 0; /* mc = n; */ if (ub < n-1 && lb < ub) omit = 1; for( i=1; i<=n; i++) chi[i]=0; /* now start the program */ if (lb > n || n > MaxSize-1) printf("Error: Invalid parameter!\n"); else for (i=1; i<=lb+1; i++) { par[i] = L[i] = nextp[i] = i-1; rChi[i] = i+1; chi[par[i]] = 1; } rChi[lb+1] = 0; if (lb < ub) Gen(lb+2, 0, 0); if (lb == ub) Gen(lb+2,lb+1,1); if (lb > ub) { printf("lower bound must be <= upper bound!\n"); return( 1 ); } printf("Total = %4d\n",num); return( 0 ); }
void GenAbs(){ Gen(cmDup); Gen(0); Gen(PC+3); Gen(cmIfGE); Gen(cmNeg); }
///////////////////////////////////////////////// // Bit-Set TBSet::TBSet(const TBSet& BSet): B4s(0), Bits(0), LastB4Mask(0), B4T(NULL) { Gen(BSet.Bits); for (int B4N=0; B4N<B4s; B4N++) { B4T[B4N]=BSet.B4T[B4N]; } }
int main(){ char s1,*s2; mas = (Trec*)calloc(maxn*maxw,sizeof(Trec)); m2 = root = mas; char f=0; printf("Input 'h' for help\n"); while(f==0){ printf("%s","Input operation: "); scanf("\n%s",s2); s1 = *s2; switch (s1){ case 'a': scanf("%s",s2); Insert(s2); printf("String %s inserted\n",s2); break; case 'g': ; int wrd,l1,l2; scanf("%d %d %d",&wrd,&l1,&l2); Gen(wrd,l1,l2); printf("%d words were generated\n",wrd); break; case 'd': scanf("%s",s2); int r = Delete(s2); if(!r)printf("String %s deleted\n",s2); else printf("String %s wasn't found\n",s2); break; case 's': ; char * ssh = "\0"; Show(ssh); break; case 'p': scanf("%s",s2); Show(s2); break; case 'f': ; time_t t1 = time(NULL); PrintToFile(); time_t t2 = time(NULL); printf("Time: %f\n",difftime(t2,t1)); break; case 'q': printf("%s\n","Quit"); f=1; break; case 'h': printf("\nBor structure\nby Nickolay Andronov(c)\n\n Operations:\n1)a string - Appends string\n2)d string - Deletes string\n3)s - Shows all strings\n4)q - Quit\n5)h - Help\n6)p string - Prints all strings started with prefix\n7)g(number of words, lowerlimit, upper limit) - Generates random strings \n\n"); break; default: printf("%s\n","Invalid operation"); break; } } free(mas); return 0; }
void PList(){ int parms = 0; int i; Get(); if(!strcmp(token, "(")){ Get(); if(strcmp(token, ")")){ Expression(); parms++; while(!strcmp(token, ",")){ Get(); Expression(); parms++; } while(parms > 0){ Gen(4, 0, stacksize + 4-1); parms--; } if(strcmp(token, ")")){ Error(22); } } } else Error(22); }
short GetHumanMove(int from,int t){ int revedBytes; static short x = 4, y = 5; long int i; int count = 0; short ch,selecting = 0; Gen(); /* for check legal move only */ while(1){ //nhan du lieu tu client revedBytes = recv(conn_sock,buff,1024,0); if(buff[0] == 3){ buff[revedBytes] = '\0'; from = (int)buff[1]; t = (int)buff[2]; if(color[from]==side){ newmove.from = from; newmove.dest = t; for (i=gen_begin[ply]; i<gen_end[ply]; i++) if (gen_dat[i].m.from==newmove.from && gen_dat[i].m.dest==newmove.dest) return 0; } buff[0] = 3; buff[1] = 0; buff[2] = '\0'; send(conn_sock,buff,1024,0);//tra ve loi } } }
cPOCPieceGenerator::cPOCPieceGenerator(int a_Seed) : m_Seed(a_Seed) { // Prepare a vector of available pieces: m_AvailPieces.push_back(new cPOCPiece(5, 3)); m_AvailPieces.push_back(new cPOCPiece(7, 5)); m_AvailPieces.push_back(new cPOCPiece(9, 5)); m_AvailPieces.push_back(new cPOCPiece(5, 7)); // Generate the structure: cBFSPieceGenerator Gen(*this, a_Seed); Gen.PlacePieces(0, 50, 0, 6, m_Pieces); // DebugPieces(m_Pieces); // Get the smallest cuboid encompassing the entire generated structure: cCuboid Bounds(0, 50, 0, 0, 50, 0); for (cPlacedPieces::const_iterator itr = m_Pieces.begin(), end = m_Pieces.end(); itr != end; ++itr) { Vector3i MinCoords = (*itr)->GetCoords(); Bounds.Engulf(MinCoords); Bounds.Engulf(MinCoords + (*itr)->GetPiece().GetSize()); } // for itr - m_Pieces[] m_Bounds = Bounds; }
cPieceGeneratorSelfTest(void) { // Prepare the internal state: InitializePieces(); // Generate: cBFSPieceGenerator Gen(*this, 0); cPlacedPieces OutPieces; Gen.PlacePieces(500, 50, 500, 3, OutPieces); // Print out the pieces: printf("OutPieces.size() = " SIZE_T_FMT "\n", OutPieces.size()); size_t idx = 0; for (cPlacedPieces::const_iterator itr = OutPieces.begin(), end = OutPieces.end(); itr != end; ++itr, ++idx) { const Vector3i & Coords = (*itr)->GetCoords(); cCuboid Hitbox = (*itr)->GetHitBox(); Hitbox.Sort(); printf(SIZE_T_FMT ": {%d, %d, %d}, rot %d, hitbox {%d, %d, %d} - {%d, %d, %d} (%d * %d * %d)\n", idx, Coords.x, Coords.y, Coords.z, (*itr)->GetNumCCWRotations(), Hitbox.p1.x, Hitbox.p1.y, Hitbox.p1.z, Hitbox.p2.x, Hitbox.p2.y, Hitbox.p2.z, Hitbox.DifX() + 1, Hitbox.DifY() + 1, Hitbox.DifZ() + 1 ); } // itr - OutPieces[] printf("Done.\n"); // Free the placed pieces properly: Gen.FreePieces(OutPieces); }
/* Search game tree by alpha-beta algorith */ short AlphaBeta(short alpha, short beta, short depth) { short i, value, best; if (!depth) return Eval(); Gen(); best = -INFINITY; for (i=gen_begin[ply]; i<gen_end[ply] && best<beta; i++) { if (best > alpha) alpha = best; if (MakeMove(gen_dat[i].m)) value = 1000-ply; else value = -AlphaBeta(-beta, -alpha, depth-1); UnMakeMove(); if (value > best) { best = value; if (!ply) newmove = gen_dat[i].m; } } return best; }
static thing_th *dup_cell(thing_th *thing) { switch(th_kind(thing)) { case number_k: return Number(sym(thing)); case string_k: return String(sym(thing)); case atom_k: return Atom(sym(thing)); case cons_k: return Cons(Car(thing), Cdr(thing)); case error_k: return Err(Cdr(thing)); case procedure_k: return Proc(Car(thing), Cdr(thing)); case macro_k: return Mac(Car(thing), Cdr(thing)); case gen_k: return Gen(Car(thing), Cdr(thing)); case routine_k: return Routine(call_rt(thing)); case method_k: return Method(call_rt(thing)); case grid_k: return duplicate_grid(thing); case null_k: return NULL; } }
Individual::Individual (size_t n, size_t m) { for (size_t i = 0; i < n; i++) { chromosome.push_back ( Gen (m) ); } for (size_t i = 0; i < (n*m) ; i++) { crossPoints.push_back( rand()%10<3?1:0 ); } }
void GenComp(tLex Lex){ // ? Gen(0); // јдрес перехода вперед switch (Lex) { case lexEQ : Gen(cmIfNE); break; case lexNE : Gen(cmIfEQ); break; case lexLE : Gen(cmIfGT); break; case lexLT : Gen(cmIfGE); break; case lexGE : Gen(cmIfLT); break; case lexGT : Gen(cmIfLE); break; } }
short GetHumanMove(void) { static short x = 4, y = 5; short ch, from, t, i, selecting = 0; Gen(); /* for check legal move only */ while (1) { MoveTo (x, y); ch = (short)getch(); switch (ch) { case 13: case 32: /* Enter or Spacebar */ t = x + y*SIZE_X; if (!selecting) { if (color[t]==side) { selecting = 1; from = t; DrawCell(t, SELECT); } } else { if (t != from) DrawCell(from, NORMAL); if (color[t]==side) { from = t; DrawCell(t, SELECT); } else { newmove.from = from; newmove.dest = t; for (i=gen_begin[ply]; i<gen_end[ply]; i++) if (gen_dat[i].m.from==newmove.from && gen_dat[i].m.dest==newmove.dest) return 0; DrawCell(from, SELECT); } } break; case 27: return 1; /* ESC */ case 0xE0: ch = (short)getch(); switch (ch) { case 75: if (x) x--; else x = SIZE_X-1; break; /* LEFT */ case 77: if (x<SIZE_X-1) x++; else x = 0; break; /* RIGHT */ case 72: if (y) y--; else y = SIZE_Y-1; break; /* UP */ case 80: if (y<SIZE_Y-1) y++; else y = 0; break; /* DOWN */ } break; } /* switch */ } /* while */ }
TBSet& TBSet::operator=(const TBSet& BSet) { if (this!=&BSet) { if (Bits!=BSet.Bits) { Gen(BSet.Bits); } for (int B4N=0; B4N<B4s; B4N++) { B4T[B4N]=BSet.B4T[B4N]; } } return *this; }
int main(int argc, char* argv[]) { RWTPtrSlist<A> list; std::generate_n(std::back_inserter(list.std()),50,Gen()); std::for_each(list.begin(), list.end(), Vals()); list.sort(); // the program compiles if this line is commented out. return 0; }
void CChineseChessView::OnLButtonUp(UINT nFlags, CPoint point) { // TODO: ÔÚ´ËÌí¼ÓÏûÏ¢´¦Àí³ÌÐò´úÂëºÍ/»òµ÷ÓÃĬÈÏÖµ if (isMouseDown){ isMouseDown=false; CRect rect; GetClientRect(&rect); CPoint logpoint=PhysicalToLogicPoint(point); if (logpoint.x>=0){ //human move Gen(); newmove.from = LogicPointToNum(selectedPoint); newmove.dest = LogicPointToNum(logpoint); for (int i=gen_begin[ply]; i<gen_end[ply]; i++){ if (gen_dat[i].m.from==newmove.from && gen_dat[i].m.dest==newmove.dest){ if(UpdateNewMove()){ UpdateDisplay(rect); int ret; ret=MessageBox("you are really a lucky dog,dare to try again?","Game Over",MB_YESNO); if (ret==IDYES){ NewGame(true); return; }else{ exit(0); } } side = xside; xside = 1-xside; //computer move short best; best = AlphaBeta(-INFINITY, INFINITY, MAX_PLY); if(UpdateNewMove()){ UpdateDisplay(rect); int ret; ret=MessageBox("afraid?dare to try again?","Game Over",MB_YESNO); if (ret==IDYES){ NewGame(true); return; }else{ exit(0); } } side = xside; xside = 1-xside; break; } } } UpdateDisplay(rect); } CView::OnLButtonUp(nFlags, point); }
//parse an expression void Expression(){ int sym = 0; int yee = 0; //+ or - is optional at the begining of an expression if(!strcmp(token, "+") || !strcmp(token, "-")){ if(!strcmp(token, "-")) yee = 1; sym = 1; Get(); Term(); if(yee) Gen(2,0,1); } //expression must have at least a single term //and can be followed by +/- and more terms while(sym == 0 || (!strcmp(token, "+") || !strcmp(token, "-"))){ sym = 1; if(!strcmp(token, "+")){ Get(); Term(); Gen(2,0,2); } else if(!strcmp(token, "-")){ Get(); Term(); Gen(2,0,3); } else { Term(); } } }
int _tmain(int argc, _TCHAR* argv[]) { KeySchedule(Key, strlen(Key)); byte i = 0, j = 0; for (int n = 0; n < strlen(pt); n++) { byte val = pt[i] ^ Gen(i, j); printf("%02x ", val); } return 0; }
Individual::Individual (std::vector < bool > ch, size_t g) { size_t n = ch.size()/g; std::vector < bool > t; for ( size_t i = 0, j = 0; i < ch.size(); i++ ) { t.push_back( ch.at(i) ); j++; if (j >= n) { j = 0; chromosome.push_back( Gen (t) ); t.clear(); } } }
//parse a condition void Condition(){ int sym; //odd condition if(!strcmp(token, "odd")){ Get(); Expression(); Gen(2,0,6); } //expression rel-op expression else{ //parse the expression Expression(); if(!strcmp(token, "=") || !strcmp(token, "<>") || !strcmp(token, "<") || !strcmp(token, "<=") || !strcmp(token, ">") || !strcmp(token, ">=")){ //decide which rel-op we have if(!strcmp(token, "=")) sym = 8; else if(!strcmp(token, "<>")) sym = 9; else if(!strcmp(token, "<")) sym = 10; else if(!strcmp(token, "<=")) sym = 11; else if(!strcmp(token, ">")) sym = 12; else if(!strcmp(token, ">=")) sym = 13; Get(); //parse the next expression Expression(); Gen(2,0,sym); } else Error(20); } }
static PyObject * _cffi_f_Gen(PyObject *self, PyObject *noarg) { struct Gen_return result; Py_BEGIN_ALLOW_THREADS _cffi_restore_errno(); { result = Gen(); } _cffi_save_errno(); Py_END_ALLOW_THREADS (void)self; /* unused */ (void)noarg; /* unused */ return _cffi_from_c_struct((char *)&result, _cffi_type(7)); }
//parse a term void Term(){ int sym; //a term must start with a factor, parse it Factor(); //we can have multiple factors multiplied or divided together while(!strcmp(token, "*") || !strcmp(token, "/")){ if(!strcmp(token, "*")) sym = 4; else sym = 5; Get(); Factor(); Gen(2,0,sym); } }
//++++++++++++++++++++++++++++++++++++++++++++++++ //煙の更新 //--in-------------------------------------------- // なし //--out------------------------------------------- // なし //++++++++++++++++++++++++++++++++++++++++++++++++ void LINE_PARTICLE::UpDate(void) { if(!m_Live) return; for(int i = 0; i < LINE_NUM; i++) { //更新処理 m_Time[i] --; //表示時間カウントダウン m_TexOffset[i] += TEX_SLIDE; //UVを移動 } if(m_Obj->m_Live == false || m_Obj->m_Effect == false) { Reset(); return; } Gen(); //タイマーがすべて0になったら初期化 for(int i = 0; i < LINE_NUM; i++) { if(m_Time[i] > 0) //一つでもタイマーが残っていれば関数を抜ける { return; } else m_Time[i] = 0; } //初期化 m_Obj->m_Effect = false; Reset(); }
void GenAddr(tObj *X){ // ? Gen(X->Val); // ¬ текущую ¤чейку адрес предыдущей + 2 X->Val = PC+1; // јдрес+2 = PC+1 - ? // }
//parse a statement void Statement(){ char* ident = malloc(sizeof(char*) * 12); int number; int tmp; int jaddr; int caddr; int jaddr2; symbol* curSym; //ident if(!strcmp(token, "2")){ //get the specific ident ident = input[tptr++]; Get(); //ident := expression if(!strcmp(token, ":=")) Get(); else Error(11); //get our ident from the table //make sure our ident is a variable curSym = Lookup(st, ident); if(curSym == NULL){ Error(11); } else if(curSym->type != 1){ Error(12); } else{ //if the variable has not yet been assigned, //assign its position on the stack if(curSym->position == -1){ curSym->position = offset++; } //parse the expression and store the rseult Expression(); Gen(4,(lex - curSym->level),curSym->position); } } //call a procedure else if(!strcmp(token, "call")){ Get(); if(!strcmp(token, "2")){ ident = input[tptr++]; curSym = Lookup(st, ident); if(curSym == NULL){ Error(11); } else if(curSym->type != 2){ Error(15); } else{ PList(); Gen(5, (lex - curSym->level), curSym->position); } } else Error(14); Get(); } //begin else if(!strcmp(token, "begin")){ Get(); Statement(); while(!strcmp(token, ";")){ Get(); Statement(); } if(!strcmp(token, "end")){ Get(); } else{ Error(10); } } //if - then else if(!strcmp(token, "if")){ Get(); Condition(); if(!strcmp(token, "then")){ Get(); //store the line where our jump address is written for future use jaddr = line; Gen(8,0,0); Statement(); if(!strcmp(token, ";")){ //update our jump addresses to the correct one codegen[jaddr].m = line; Get(); } if(!strcmp(token, "else")){ jaddr2 = line; Gen(7,0,0); Get(); codegen[jaddr].m = line; Statement(); //update our jump addresses to the correct one codegen[jaddr2].m = line; } else{ codegen[jaddr].m = line; token = ";"; tptr--; } } else Error(16); } //while else if(!strcmp(token, "while")){ Get(); //store the position of the start of the loop caddr = line; Condition(); if(!strcmp(token, "do")){ //store the line where our jump address is written for future use jaddr = line; Gen(8,0,0); Get(); Statement(); //write the jump to the top of the loop Gen(7,0,caddr); //update our jump address to the correct one codegen[jaddr].m = line; } else Error(18); } //read from console else if(!strcmp(token, "read")){ Gen(10,0,0); Get(); //ident to store input if(!strcmp(token, "2")){ //actual variable ident = input[tptr++]; Get(); //get the current symbol and make sure it is a variable curSym = Lookup(st, ident); if(curSym == NULL){ Error(11); } else if(curSym->type != 1){ Error(12); } //if the variable has not yet been assigned, //assign its position on the stack if(curSym->position == -1){ curSym->position = offset++; } Gen(4,(lex - curSym->level),curSym->position); } } //write to console else if(!strcmp(token, "write")){ Get(); if(!strcmp(token, "2")){ ident = input[tptr++]; Get(); //get the current symbol and make sure it is a variable curSym = Lookup(st, ident); if(curSym == NULL){ Error(11); } else if(curSym->type != 1){ Error(12); } if(curSym->position == -1){ Error(11); } Gen(3,(lex - curSym->level),curSym->position); Gen(9,0,0); } } }
//parse a factor void Factor(){ symbol* curSym; char* ident = malloc(sizeof(char*) * 12); int number; int tmp; //our factor is an ident if(!strcmp(token, "2")){ //get the specific identifier ident = input[tptr++]; //get the ident from our table curSym = Lookup(st, ident); //ident was not in table if(curSym == NULL){ Error(11); } //wrong type of ident else if(curSym->type == 2){ Error(21); } else{ //push our constant if(curSym->type == 0){ Gen(1,0,curSym->value); } else if(curSym->type == 1){ //undefined variable if(curSym->position == -1) Error(11); //load variable value else Gen(3,(lex - curSym->level),curSym->position); } } Get(); } //our factor is a number else if(!strcmp(token, "3")){ //get the specific number and push it number = atoi(input[tptr++]); Gen(1,0,number); Get(); } //our factor is in the form ( expresson ) else if(!strcmp(token, "(")){ Get(); Expression(); if(!strcmp(token, ")")) Get(); else Error(22); } //call a procedure else if(!strcmp(token, "call")){ Get(); if(!strcmp(token, "2")){ ident = input[tptr++]; curSym = Lookup(st, ident); if(curSym == NULL){ Error(11); } else if(curSym->type != 2){ Error(15); } else{ PList(); Gen(5, (lex - curSym->level), curSym->position); Gen(6,0,1); } } else Error(14); Get(); } else { Error(23); } }
//parse a block char* Block(int v){ lex++; int vars = v; char* ident = malloc(sizeof(char*) * 12); int number; int tmp; int jaddr; int bgn; int procvars; //store our constants if(!strcmp(token, "const")){ do{ Get(); if(!strcmp(token, "2")){ ident = input[tptr++]; } else{ Error(4); } Get(); if(!strcmp(token, "=")){ Get(); if(!strcmp(token, "3")) number = atoi(input[tptr++]); else Error(2); } else{ Error(3); } tmp = Add(st, ident, 0, number, -1, lex); if(tmp == 0); else printf("Error inserting %d into table. Code - %d\n",number, tmp); Get(); } while(!strcmp(token, ",")); if(!strcmp(token, ";")) Get(); else { Error(10); } } //store our variables if(!strcmp(token, "var")){ do{ Get(); if(!strcmp(token, "2")){ ident = input[tptr++]; } else{ Error(4); } tmp = Add(st, ident, 1, number, offset++, lex); if(tmp == 0); else printf("Error inserting %d into table. Code - %d\n",number, tmp); Get(); vars++; }while(!strcmp(token, ",")); if(!strcmp(token, ";")) Get(); else { Error(10); } } //allocate our stack space for our constants and variables bgn = line; Gen(7, 0, line); //parse all procedures while(!strcmp(token, "procedure")){ procvars = 0; offset = 4; Get(); if(!strcmp(token, "2")){ ident = input[tptr++]; Get(); } else{ Error(4); } procvars = PBlock(); if(!strcmp(token, ";")) Get(); else Error(6); Add(st, ident, 2, 0, line, lex); Add(st, "return", 1, 0, 0, lex+1); Block(procvars); if(!strcmp(token, ";")) Get(); else{ Error(10); } Gen(2,0,0); } codegen[bgn].m = line; Gen(6, 0, vars + 4); Statement(); Delete(st); lex--; return token; }
thing_th *funky_gen(thing_th *args) { if(!Car(args) || !Cdr(args)) return Err(Cons(String("Incomplete Gen construction"), NULL)); return Gen(Car(args), Cdr(args)); }