void print_level(struct btree *root, int n) { if(root == NULL) {return;} if(n==1) printf(" %d ",root->data); else { print_level(root->left, n-1); print_level(root->right, n-1); } }
void debug_print_level(unsigned int new_lvl, page_descr* pd_prev, page_descr* buddy_next) { if(new_lvl > 1) { println("***"); print_level(new_lvl); print_level(new_lvl - 1); print("pd_prev: "); print_page_descr(pd_prev); print("buddy_next: "); print_page_descr(buddy_next); } }
// Function to print all nodes at a given level void print_level(struct node* tree, int level) { if (tree == NULL) return; if (level == 1) printf("\t%d ", tree->data); else if (level > 1) { print_level(tree->left, level-1); print_level(tree->right, level-1); } }
static void print_level(struct bnode* x, int level) { if (x == NULL) return; if (level == 1) printf("%d ", x->v); else if (level > 1) { print_level(x->left, level-1); print_level(x->right, level-1); } }
/* print pending trailers after all data has been read */ void print_level_end(struct record *last) { int i = last_level; while(levels[i] && i >= 1) { if(levels[i]->element_name) print_level(levels[i],last->o->element_trailer,last->o->indent,get_indent_depth(i) - 1); if(levels[i]->group_name) print_level(levels[i],last->o->group_trailer,last->o->indent,get_indent_depth(i - 1)); i--; } }
void print_level(NODEPTR p,int lvl) { if(p) { if(lvl==1) { printf("%d -->",p->info); append_ll(&list_lvl,p); } else { print_level(p->left,lvl-1); print_level(p->right,lvl-1); } } }
//This function prints the given level of the given tree, assuming //that the node has the given x cordinate. void print_level(asciinode *node, int x, int level) { int i, isleft; if (node == NULL) return; isleft = (node->parent_dir == -1); if (level == 0) { for (i=0; i<(x-print_next-((node->lablen-isleft)/2)); i++) { printf(" "); } print_next += i; printf("%s", node->label); print_next += node->lablen; } else if (node->edge_length >= level) { if (node->left != NULL) { for (i=0; i<(x-print_next-(level)); i++) { printf(" "); } print_next += i; printf("/"); print_next++; } if (node->right != NULL) { for (i=0; i<(x-print_next+(level)); i++) { printf(" "); } print_next += i; printf("\\"); print_next++; } } else { print_level(node->left, x-node->edge_length-1, level-node->edge_length-1); print_level(node->right, x+node->edge_length+1, level-node->edge_length-1); } }
void main() { NODEPTR *predc=0; add_node(4); add_node(2); add_node(5); add_node(1); add_node(3); add_node(9); add_node(10); add_node(11); add_node(12); printf("\n... list of leafs..\n"); int i,h=6;///decreasing order= post order is necessary otherwise it will change initial nodes & u ill hv trouble of repeatation for(i=h;i>=1;i--) { printf("Level [%d] ",i); print_level(ptree,i); printf("\n"); } printf("\n... list of level nodes..\n"); display(&list_lvl); //printf("**%d",ptree->left->info); //inorder(ptree); //convert2list(ptree,&predc,&list1); printf("\ndisplay Inoreder......]\n"); inorder(ptree);// ofcourse it will change the original tree bcoz ki u r not using exta space for creating new list }
void expr_tern_op::print(ostream &os, int level){ right->print(os, level + 1); middle->print(os, level + 1); print_level(os, level); os << "?:" << endl; left->print(os, level + 1); }
/* * This pretty-prints the given tree, left-justified. * The tree is drawn in such a way that both of the edges down from * a node are the same length. This length is the minimum such that * the two subtrees are separated by at least two blanks. */ void tree_draw(const T t) { Pnode *proot; int xmin, i; if (t == NULL) return; proot = build_ptree(t->root); compute_edge_lengths(proot); for (i = 0; i < proot->height && i < MAX_HEIGHT; i++) { lprofile[i] = INFINITY; } compute_lprofile(proot, 0, 0); xmin = 0; for (i = 0; i < proot->height && i < MAX_HEIGHT; i++) { xmin = min(xmin, lprofile[i]); } for (i = 0; i < proot->height; i++) { print_next = 0; print_level(proot, -xmin, i); printf("\n"); } if (proot->height >= MAX_HEIGHT) { printf("(This tree is taller than %d, and may be drawn incorrectly.)\n", MAX_HEIGHT); } free_ptree(proot); }
int save_data(char *filename,struct level2_data *data) { FILE *fff; char tempst[255]; long filepos,good_pos=-1; fff=fopen(filename,"r+"); do { filepos=ftell(fff); fgets(tempst,254,fff); if (!strncmp(tempst,"%DATA",5)) { good_pos=filepos; break; } } while(!feof(fff)); if (good_pos<0) return -1; fseek(fff,good_pos,SEEK_SET); print_level(fff,data); return 0; }
bool scenario::better_scenario_than(const scenario &s, double limit) const { // - n of recovered cells int deltanfree = n_free_families() - s.n_free_families(); // n of new overlaps int deltanoverls = n_overlaps() - s.n_overlaps(); double deltaprob_helix = helix_Prob() - s.helix_Prob(); double deltachi_helix = helix_chi2() - s.helix_chi2(); double deltaprob_tangent = tangent_Prob() - s.tangent_Prob(); double deltachi_tangent = tangent_chi2() - s.tangent_chi2(); if (print_level() >= mybhep::VVERBOSE) { std::clog << " delta n_free_families = (" << n_free_families() << " - " << s.n_free_families() << ")= " << deltanfree << " dela n_overlaps = (" << n_overlaps() << " - " << s.n_overlaps() << ")= " << deltanoverls << " delta prob_helix = (" << helix_Prob() << " - " << s.helix_Prob() << ") = " << deltaprob_helix << " delta prob_tangent = (" << tangent_Prob() << " - " << s.tangent_Prob() << ") = " << deltaprob_tangent << std::endl; } if (deltanoverls < -2 * deltanfree) return true; if (deltanoverls == -2 * deltanfree) { int delta_n_common_vertexes = n_of_common_vertexes(limit) - s.n_of_common_vertexes(limit); if (print_level() >= mybhep::VVERBOSE) std::clog << " delta n common vertex = " << delta_n_common_vertexes << std::endl; if (delta_n_common_vertexes > 0) return true; if (delta_n_common_vertexes < 0) return false; int delta_n_of_ends_on_wire = n_of_ends_on_wire() - s.n_of_ends_on_wire(); if (print_level() >= mybhep::VVERBOSE) std::clog << " delta n ends on wire = " << delta_n_of_ends_on_wire << std::endl; if (delta_n_of_ends_on_wire < 0) return true; if (delta_n_of_ends_on_wire > 0) return false; if (deltaprob_helix > 0.) return true; if (deltaprob_tangent > 0.) return true; if (deltaprob_helix == 0. && deltachi_helix < 0.) return true; if (deltaprob_tangent == 0. && deltachi_tangent < 0.) return true; } return false; }
void expr_function::print(ostream &os, int level){ for (int i = fargs.size() - 1; i >= 0; i--){ fargs[i]->print(os, level + 1); } print_level(os, level); os << "()" <<endl; fid->print(os, level + 1); }
void bpt_print_leaf_node(bpt_node* node, int level) { int i, j; print_level(level); printf("##BEGIN LEAF NODE\n"); for(i = 0; i < node->num_of_rec; i++){ print_level(level); /* TODO: may add a callback so user could define how the leaf * node data will be printed. Currently print the pointer. */ printf("key:%ld, record:%ld\n", node->key[i], node->recs.l_rec.r_arr[i]); } print_level(level); printf("##END LEAF NODE\n"); }
void bst_print_level_order(struct bnode* x, int level) { int i; int h = height(x); for (i = 1; i <= h; i++) print_level(x, i); }
void print_level_order(struct btree *root) { int height = max_height(root); int i; for(i=1;i<=height;i++) { print_level(root,i); printf("\n"); } }
//--------------------------------------------------------- //This function prints the given level of the given tree, assuming //that the node has the given x cordinate. void AsciiTree::print_level(AsciiNode* ascii_node, int x, int level) { if(ascii_node==NULL) return; int i, isleft; isleft=(ascii_node->parent_dir==-1); if(level==0) { for(i=0; i<(x-print_next-((ascii_node->lablen-isleft)/2)); ++i) std::cout<<" "; print_next+=i; std::cout<<ascii_node->label; print_next+=ascii_node->lablen; } else if(ascii_node->edge_length>=level) { if(ascii_node->left!=NULL) { for(i=0; i<(x-print_next-(level)); ++i) std::cout<<" "; print_next+=i; std::cout<<"/"; print_next++; } if(ascii_node->right!=NULL) { for(i=0; i<(x-print_next+(level)); ++i) std::cout<<" "; print_next+=i; std::cout<<"\\"; print_next++; } } else { print_level(ascii_node->left, x-ascii_node->edge_length-1, level-ascii_node->edge_length-1); print_level(ascii_node->right, x+ascii_node->edge_length+1, level-ascii_node->edge_length-1); } }
/* Function to print level order traversal a tree*/ void level_order_traversal(struct node* tree) { int counter, height; height = compute_height(tree); printf("\n The tree elements at various level are :\n"); for (counter = 1; counter <= height; counter++) { print_level(tree, counter); printf("\n"); } }
void bpt_print_node(bpt_node* root, int level) { if(bpt_is_leaf(root)) bpt_print_leaf_node(root, level); else{ print_level(level); printf("##BEGIN INDEX NODE##\n"); int i, j; /** print the first child **/ bpt_print_node(root->recs.c_arr[0], level + 1); for(i = 0; i < bpt_num_of_key(root); i++){ /** print the key and next child **/ print_level(level); printf("key:%ld\n", root->key[i]); bpt_print_node(root->recs.c_arr[i+1], level + 1); } print_level(level); printf("##END INDEX NODE##\n"); } }
/* * This function prints the given level of the given tree, assuming * that the node pn has the given x cordinate. */ void print_level(Pnode * pn, int x, int level) { int i, isleft; if (pn == NULL) return; isleft = (pn->parent_dir == -1); if (level == 0) { for (i = 0; i < (x - print_next - ((pn->lablen - isleft) / 2)); i++) { printf(" "); } print_next += i; printf("%s", pn->label); print_next += pn->lablen; } else if (pn->edge_length >= level) { if (pn->left != NULL) { for (i = 0; i < (x - print_next - (level)); i++) { printf(" "); } print_next += i; printf("/"); print_next++; } if (pn->right != NULL) { for (i = 0; i < (x - print_next + (level)); i++) { printf(" "); } print_next += i; printf("\\"); print_next++; } } else { print_level(pn->left, x - pn->edge_length - 1, level - pn->edge_length - 1); print_level(pn->right, x + pn->edge_length + 1, level - pn->edge_length - 1); } }
static int print_symbol(FILE *outfile, int line, struct output_symbol *s) { print_level(s->level, s->last); fprintf(outfile, "%s: ", s->sym->name); if (brief_listing) { if (s->sym->expand_line) { fprintf(outfile, "%d", s->sym->expand_line); return 1; } else if (s->sym->callee) s->sym->expand_line = line; } print_symbol_type(outfile, s->sym); return 0; }
static int print_symbol(FILE *outfile, int line, struct output_symbol *s) { int has_subtree = s->direct ? s->sym->callee != NULL : s->sym->caller != NULL; print_level(s->level, s->last); print_function_name(s->sym, has_subtree); if (brief_listing) { if (s->sym->expand_line) { fprintf(outfile, " [see %d]", s->sym->expand_line); return 1; } else if (s->sym->callee) s->sym->expand_line = line; } return 0; }
//--------------------------------------------------------- //prints ascii tree for given Node structure void AsciiTree::print_ascii_tree() { if(_node==NULL) return; AsciiNode* ascii_root=build_ascii_tree(_node); compute_edge_lengths(ascii_root); for(int i=0; i<ascii_root->height && i<MAX_HEIGHT; ++i) lprofile[i]=INFINITY; compute_lprofile(ascii_root, 0, 0); int xmin=0; for(int i=0; i<ascii_root->height && i<MAX_HEIGHT; ++i) xmin=std::min(xmin, lprofile[i]); for(int i=0; i<ascii_root->height; ++i) { print_next=0; print_level(ascii_root, -xmin, i); std::cout<<std::endl; } if(ascii_root->height>=MAX_HEIGHT) std::cout<<"(This tree is taller than "<<MAX_HEIGHT<<", and may be drawn incorrectly.)"<<std::endl; free_ascii_tree(ascii_root); }
void scenario::calculate_n_free_families(const std::vector<topology::cell> &cells, const std::vector<topology::calorimeter_hit> &calos) { std::vector<int> freecells(cells.size()); fill(freecells.begin(), freecells.end(), 1); std::vector<int> freecalos(calos.size()); fill(freecalos.begin(), freecalos.end(), 1); for (std::vector<sequence>::iterator iseq = sequences_.begin(); iseq != sequences_.end(); ++iseq) { for (std::vector<node>::iterator in = iseq->nodes_.begin(); in != iseq->nodes_.end(); ++in) { if (in->c().id() >= cells.size()) { if (print_level() >= mybhep::VVERBOSE) std::clog << " problem: cell " << in->c().id() << " has larger id than n of cells " << cells.size() << std::endl; continue; } else { freecells[in->c().id()] = 0; } } if (iseq->has_decay_helix_vertex() && iseq->decay_helix_vertex_type() == "calo") { if (iseq->calo_helix_id() >= calos.size()) { if (print_level() >= mybhep::VVERBOSE) std::clog << " problem: helix calo " << iseq->calo_helix_id() << " has larger id than n of calos " << calos.size() << std::endl; continue; } freecalos[iseq->calo_helix_id()] = 0; } if (iseq->has_helix_vertex() && iseq->helix_vertex_type() == "calo") { if (iseq->helix_vertex_id() >= calos.size()) { if (print_level() >= mybhep::VVERBOSE) std::clog << " problem: helix calo-vertex " << iseq->helix_vertex_id() << " has larger id than n of calos " << calos.size() << std::endl; continue; } freecalos[iseq->helix_vertex_id()] = 0; } if (iseq->has_decay_tangent_vertex() && iseq->decay_tangent_vertex_type() == "calo") { if (iseq->calo_tangent_id() >= calos.size()) { if (print_level() >= mybhep::VVERBOSE) std::clog << " problem: tangent calo " << iseq->calo_tangent_id() << " has larger id than n of calos " << calos.size() << std::endl; continue; } freecalos[iseq->calo_tangent_id()] = 0; } if (iseq->has_tangent_vertex() && iseq->tangent_vertex_type() == "calo") { if (iseq->tangent_vertex_id() >= calos.size()) { if (print_level() >= mybhep::VVERBOSE) std::clog << " problem: tangent calo-vertex " << iseq->tangent_vertex_id() << " has larger id than n of calos " << calos.size() << std::endl; continue; } freecalos[iseq->tangent_vertex_id()] = 0; } } size_t counter = 0; for (std::vector<int>::iterator i = freecells.begin(); i != freecells.end(); ++i) if (*i) counter++; for (std::vector<int>::iterator i = freecalos.begin(); i != freecalos.end(); ++i) if (*i) counter++; n_free_families_ = counter; return; }
struct level2_data *parse_data_file(char *filename) { FILE *fff; char tempst[255],sprite_file[255],throwaway[255]; char type[255]; int number,shoots,explodes,count,i,numsprites,tempint; struct level2_data *data; fff=fopen(filename,"r"); if (fff==NULL) { printf("Cannot open %s\n",filename); return NULL; } data=(struct level2_data *)malloc(sizeof(struct level2_data)); /* Pass 1 */ do { fgets(tempst,254,fff); switch (tempst[0]) { case '%': if (!strncmp(tempst,"%SPRITEFILE",11)) { sscanf(tempst,"%s %s",throwaway,sprite_file); } if (!strncmp(tempst,"%SPRITEXSIZE",11)) { sscanf(tempst,"%s %d",throwaway,&data->xsize); } if (!strncmp(tempst,"%SPRITEYSIZE",11)) { sscanf(tempst,"%s %d",throwaway,&data->ysize); } if (!strncmp(tempst,"%SPRITEROWS",11)) { sscanf(tempst,"%s %d",throwaway,&data->rows); } if (!strncmp(tempst,"%SPRITECOLS",11)) { sscanf(tempst,"%s %d",throwaway,&data->cols); } } } while (!feof(fff)); /* Pass 2 */ numsprites=(data->rows) * (data->cols); data->numsprites=numsprites; data->sprites=calloc( numsprites, sizeof(struct sprite_type*)); for (i=0; i< numsprites;i++) { data->sprites[i]=calloc(1,sizeof(struct sprite_type)); data->sprites[i]->initialized=0; } rewind(fff); do { fgets(tempst,254,fff); switch(tempst[0]) { case '%': if (!strncmp(tempst,"%SPRITE ",8)) { count=sscanf(tempst,"%s %d %s %d %d", throwaway,&number,type,&shoots,&explodes); if (count > 2) { data->sprites[number]->type=map_string_to_type(type); data->sprites[number]->initialized=1; } if (count > 3) { data->sprites[number]->shoots=shoots; } if (count > 4) { data->sprites[number]->explodes=explodes; } } if (!strncmp(tempst,"%DATALENGTH",10)) { sscanf(tempst,"%s %d",throwaway,&data->level_length); } if (!strncmp(tempst,"%DATAWIDTH",9)) { sscanf(tempst,"%s %d",throwaway,&data->level_width); } break; } } while (!feof(fff)); /* Pass 3 */ data->level_data=calloc(data->level_length, sizeof(char *)); data->level_data[0]=calloc(data->level_length * data->level_width,sizeof(char)); for(i=1;i<data->level_length;i++) { data->level_data[i]=data->level_data[0]+ (i*data->level_width*sizeof(char)); } rewind(fff); do { fgets(tempst,254,fff); } while (strncmp(tempst,"%DATABEGIN",10)); i=0; while(i<data->level_length*data->level_width) { /* Grrrrr */ // fscanf(fff,"%d",(int *)data->level_data[0]); fscanf(fff,"%d",&tempint); *(data->level_data[0]+i)=(char)tempint; i++; } #ifdef DEBUG print_level(data); printf("Sprite File: %s\n",sprite_file); printf("Sprite size: %ix%i\n",data->xsize,data->ysize); printf("Sprite array: %ix%i\n",data->rows,data->cols); printf("Level length: %i\n",data->level_length); #endif fclose(fff); return data; }
/** returns 'true' if the user wants to quit game */ bool lcpause() { //No music when the game is paused int musicState = musicTogglePause(); //Updates screen //Applies the background apply_surface(0, 0, background, screen); //Writes the score print_score (score); //Writes the amount of lines collapsed print_line (line); //Writes the actual level print_level (level); //Puts the matrix on screen paint_matrix(); //Updates the screen and check against errors if (SDL_Flip(screen) == -1) { return true; } //Makes a backup of game_matrix lcBlockColor matrix_backup[LC_MATRIX_HEIGHT][LC_MATRIX_WIDTH]; /** Make the screen full of grey blocks * so the player won't have time to think when paused * (cheating isn't allowed =P) * Ah, and with a simple stacking animation */ for (int i = LC_MATRIX_HEIGHT - 1; i >= 0; i--) { for (int j = 0; j < LC_MATRIX_WIDTH; j++) { matrix_backup[i][j] = game_matrix[i][j]; game_matrix[i][j] = GREY; }//for (each line) //So the animation //Puts the matrix on screen paint_matrix(); //Updates the screen and check against errors if (SDL_Flip(screen) == -1) { return true; } SDL_Delay(20); }//for (each column) //If the user wants to quit while paused bool quit = false; //Create a loop like the main Timer fps; bool pause = true; while (pause) { //Starts the timer to cap the frame rate fps.start(); //Captures the unpause and quit events while (SDL_PollEvent (&eventQ)) { //Captures the type of event switch (eventQ.type) { //If the user try to close the window case SDL_QUIT: //Sets the flag to quit the main loop quit = true; break; //If the user has pressed a key case SDL_KEYDOWN: //All this stuff only to check the Alt+F4 if( (eventQ.key.keysym.sym == SDLK_F4) //If the user was pressed F4 && (eventQ.key.keysym.mod & KMOD_LALT) //and the left Alt key was pressed && !(eventQ.key.keysym.mod & KMOD_CTRL) //and the Ctrl key wasn't pressed && !(eventQ.key.keysym.mod & KMOD_SHIFT)) //and the Shift key wasn't pressed { pause = false; quit = true; //Sets the flag to quit the main loop } if (eventQ.key.keysym.sym == SDLK_ESCAPE) //If the user was pressed Esc { pause = false; quit = true; //Sets the flag to quit the main loop } //If the user pressed the space bar if (eventQ.key.keysym.sym == SDLK_SPACE) { pause = false; } //If the user pressed the F1 key, shows help if (eventQ.key.keysym.sym == SDLK_F1) { showHelp(); //The screen was changed, so we have to do this again: //Applies the background apply_surface(0, 0, background, screen); //Writes the score print_score (score); //Writes the amount of lines collapsed print_line (line); //Writes the actual level print_level (level); //Puts the matrix on screen paint_matrix(); //Updates the screen and check against errors if (SDL_Flip(screen) == -1) { quit = true; } //Puts the matrix on screen paint_matrix(); //Updates the screen and check against errors if (SDL_Flip(screen) == -1) { return true; } } //If the 'F' key was pressed, enable/disable sound FX if (eventQ.key.keysym.sym == SDLK_f) { soundFX = !soundFX; } //If the 'M' key was pressed, enable/disable music if (eventQ.key.keysym.sym == SDLK_m) { music = !music; } break; }//switch events }//while events /** Caps the frame rate * We don't the game runs on a super speed (even if there is no animation) * because it will consume CPU/RAM resources without needing */ if (fps.getTicks() < 1000 / LC_GAME_FPS) SDL_Delay ( (1000 / LC_GAME_FPS) - fps.getTicks()); }//while (pause) //Turns back to the game for (int i = 0; i < LC_MATRIX_HEIGHT; i++) { for (int j = 0; j < LC_MATRIX_WIDTH; j++) { game_matrix[i][j] = matrix_backup[i][j]; }//for (each line) }//for (each column) //Now we turn on the music again... if it is paused if (musicState == LC_MUSIC_PAUSED && music) musicTogglePause(); return quit; }
int main( int argc, char* args[] ) { SDL_Init(SDL_INIT_EVERYTHING); Mix_OpenAudio( 22050, MIX_DEFAULT_FORMAT, 1, 4096 ); //screen=SDL_SetVideoMode((LIN_MAX+1)*40,(COL_MAX+1)*40,32,SDL_FULLSCREEN/*SDL_SWSURFACE*/); screen=SDL_SetVideoMode(0,0,32,SDL_FULLSCREEN); TTF_Init(); font=TTF_OpenFont("font2.ttf",40); music=Mix_LoadMUS("bck.wav"); clear=SDL_LoadBMP("wooden_background.bmp"); apply_surface(0,0,clear,screen); if(mute==0) Mix_PlayMusic(music, -1 ); load_level("a"); print_level(); //welcome_message(); clear=SDL_LoadBMP("clear.bmp"); print_background(); burn=SDL_LoadBMP("fire.bmp"); background=SDL_LoadBMP("name_background.bmp"); message=TTF_RenderText_Solid(font,"Player 2",color1); apply_surface((COL_MAX+COL_START+2)*40,0,background,screen); apply_surface((COL_MAX+COL_START+2)*40+5,0,message,screen); SDL_Flip(screen); message=TTF_RenderText_Solid(font,"Player 1",color1); apply_surface((0)*40,0,background,screen); apply_surface((0)*40+5,0,message,screen); SDL_Flip(screen); player=SDL_LoadBMP("warrior_on_grass.bmp"); player1=SDL_LoadBMP("warrior1_on_grass.bmp"); obs[player2.lin][player2.col]=2; obs[player1.lin][player1.col]=3; print_hp(player2.hp,1,COL_MAX+COL_START+2); print_hp(player1.hp,1,0); print_mana(player2.mana,2,COL_MAX+COL_START+2); print_mana(player2.mana,2,0); time_ex=0; if(mute<=1) sound=Mix_LoadWAV("hit.wav"); print_level(); int start_t=0; put_arena_wall(); player1_load_save("player1"); player2_load_save("player2"); while(keystates[SDLK_ESCAPE]==NULL && player1.hp>0 && player2.hp>0) {flag_player=0; t=time(NULL); if(t-t1>=2) { start_t++; if(start_t>=4) { clear_arena_wall(); } t1=t; if(player2.mana<=99) { player2.mana++; print_mana(player2.mana,2,COL_MAX+COL_START+2); } if(player1.mana<=99) { player1.mana++; print_mana(player1.mana,2,0); } //load_level("a"); print_level(); player2.permission=player1.permission=0; } if(t-t2>=1) { t2=t; player2.permission_basic=player1.permission_basic=0; } up=keystates[SDLK_UP]; down=keystates[SDLK_DOWN]; right=keystates[SDLK_RIGHT]; left=keystates[SDLK_LEFT]; atack_left=keystates[SDLK_RCTRL]; atack_right=keystates[SDLK_RCTRL]; power1=keystates[SDLK_u]; power2=keystates[SDLK_i]; power3=keystates[SDLK_o]; power4=keystates[SDLK_p]; atack1_left=keystates[SDLK_z]; atack1_right=keystates[SDLK_z]; if(power1==1 && player2.mana>=10 && player2.hp<=90) { player2.mana-=10; player2.hp+=10; print_mana(player2.mana,2,COL_MAX+COL_START+2); print_hp(player2.hp,1,COL_MAX+COL_START+2); } if(power2==1 && player2.mana>=30 && player2.permission==0) { player2.mana-=30; player2.permission=1; if(max(player1.lin,player2.lin)-min(player1.lin,player2.lin)<=2 && max(player1.col,player2.col)-min(player1.col,player2.col)<=2) { player1.hp-=40+player2.fire_dmg*3/10-player1.fire_res*3/10; print_hp(player1.hp,1,0); } if(player2.lin-2<=0) beg1=1; else beg1=player2.lin-2; if(player2.lin+2>=LIN_MAX) end1=LIN_MAX; else end1=player2.lin+2; if(player2.col-2<=0) beg2=1; else beg2=player2.col-2; if(player2.col+2>=COL_MAX) end2=COL_MAX; else end2=player2.col+2; for(int i=beg1;i<=end1;i++) for(int j=beg2;j<=end2;j++) { if(obs[i][j]==0) { //get_burn(i,j); //burn=SDL_LoadBMP("fire.bmp"); apply_surface((j+COL_START)*40,i*40,burn,screen); } } print_mana(player2.mana,2,COL_MAX+COL_START+2); } if(power3==1 && player2.hp>10) { player2.hp-=10; player2.mana+=10; print_mana(player2.mana,2,COL_MAX+COL_START+2); print_hp(player2.hp,1,COL_MAX+COL_START+2); } if(atack_left==1 && player2.permission_basic==0) { player=SDL_LoadBMP("warrior_on_grass_left.bmp"); if(obs[player2.lin][player2.col-1]==3) { player2.permission_basic=1; player1.hp-=10+player2.attack/10-player1.block/10; print_hp(player1.hp,1,0); Mix_PlayChannel(-1, sound, 0); } } if(atack_right==1 && player2.permission_basic==0) { player=SDL_LoadBMP("warrior_on_grass.bmp"); if(obs[player2.lin][player2.col+1]==3) { player2.permission_basic=1; player1.hp-=10+player2.attack/10-player1.block/10; print_hp(player1.hp,1,0); Mix_PlayChannel(-1, sound, 0); } } if(up==1 && player2.lin>1) { time_ex++; if(obs[player2.lin-1][player2.col]==0) { obs[player2.lin][player2.col]=0; put_back(player2.lin,player2.col); player2.lin--; obs[player2.lin][player2.col]=2; } } if(down==1 && player2.lin<COL_MAX) { time_ex++; if(obs[player2.lin+1][player2.col]==0) { obs[player2.lin][player2.col]=0; put_back(player2.lin,player2.col); player2.lin++; obs[player2.lin][player2.col]=2; } } if(left==1 && player2.col>1) { time_ex++; if(obs[player2.lin][player2.col-1]==0) { obs[player2.lin][player2.col]=0; put_back(player2.lin,player2.col); player2.col--; obs[player2.lin][player2.col]=2; player=SDL_LoadBMP("warrior_on_grass_left.bmp"); } } if(right==1 && player2.col<LIN_MAX) { time_ex++; if(obs[player2.lin][player2.col+1]==0) { obs[player2.lin][player2.col]=0; put_back(player2.lin,player2.col); player2.col++; obs[player2.lin][player2.col]=2; player=SDL_LoadBMP("warrior_on_grass.bmp"); } } apply_surface((player2.col+COL_START)*40,player2.lin*40,player,screen); up=keystates[SDLK_w]; down=keystates[SDLK_s]; right=keystates[SDLK_d]; left=keystates[SDLK_a]; power1=keystates[SDLK_1]; power2=keystates[SDLK_2]; power3=keystates[SDLK_3]; power4=keystates[SDLK_4]; if(power1==1 && player1.mana>=10 && player1.hp<=90) { player1.mana-=10; player1.hp+=10; print_mana(player1.mana,2,0); print_hp(player1.hp,1,0); } if(power2==1 && player1.mana>=30 && player1.permission==0) { player1.mana-=30; player1.permission=1; if(max(player2.lin,player1.lin)-min(player1.lin,player2.lin)<=2 && max(player1.col,player2.col)-min(player1.col,player2.col)<=2) { player2.hp-=40+player1.fire_dmg*3/10-player2.fire_res*3/10; print_hp(player2.hp,1,COL_MAX+COL_START+2); } if(player1.lin-2<=0) beg1=1; else beg1=player1.lin-2; if(player1.lin+2>=LIN_MAX) end1=LIN_MAX; else end1=player1.lin+2; if(player1.col-2<=0) beg2=1; else beg2=player1.col-2; if(player1.col+2>=COL_MAX) end2=COL_MAX; else end2=player1.col+2; for(int i=beg1;i<=end1;i++) for(int j=beg2;j<=end2;j++) { if(obs[i][j]==0) { //get_burn(i,j); //burn=SDL_LoadBMP("fire.bmp"); apply_surface((j+COL_START)*40,i*40,burn,screen); } } print_mana(player1.mana,2,0); } if(power3==1 && player1.hp>10) { player1.hp-=10; player1.mana+=10; print_mana(player1.mana,2,0); print_hp(player1.hp,1,0); } if(atack1_left==1 && player1.permission_basic==0 && flag_player==0) { if(obs[player1.lin][player1.col-1]==2) { player1.permission_basic=1; player1=SDL_LoadBMP("warrior1_on_grass_left.bmp"); player2.hp-=10+player1.attack/10-player2.block/10; //SDL_FreeSurface(player); print_hp(player2.hp,1,COL_MAX+COL_START+2); /*player2=SDL_LoadBMP("hit_warrior_on_grass.bmp"); apply_surface(player2.col*40,player2.lin*40,player,screen);*/ SDL_Flip(screen); Mix_PlayChannel(-1, sound, 0); } } if(atack1_right==1 && player1.permission_basic==0 && flag_player==0) { if(obs[player1.lin][player1.col+1]==2) { player1.permission_basic=1; player1=SDL_LoadBMP("warrior1_on_grass.bmp"); player2.hp-=10+player1.attack/10-player2.block/10; print_hp(player2.hp,1,COL_MAX+COL_START+2); //SDL_FreeSurface(player); player2=SDL_LoadBMP("hit_warrior_on_grass.bmp"); /*apply_surface(player2.col*40,player2.lin*40,player,screen); SDL_Flip(screen);*/ Mix_PlayChannel(-1, sound, 0); } } if(up==1 && player1.lin>1) { time_ex++; if(obs[player1.lin-1][player1.col]==0) { obs[player1.lin][player1.col]=0; put_back(player1.lin,player1.col); player1.lin--; obs[player1.lin][player1.col]=3; } } if(down==1 && player1.lin<COL_MAX) { time_ex++; if(obs[player1.lin+1][player1.col]==0) { obs[player1.lin][player1.col]=0; put_back(player1.lin,player1.col); player1.lin++; obs[player1.lin][player1.col]=3; } } if(left==1 && player1.col>1) { time_ex++; if(obs[player1.lin][player1.col-1]==0) { obs[player1.lin][player1.col]=0; put_back(player1.lin,player1.col); player1.col--; obs[player1.lin][player1.col]=3; player1=SDL_LoadBMP("warrior1_on_grass_left.bmp"); } } if(right==1 && player1.col<LIN_MAX) { time_ex++; if(obs[player1.lin][player1.col+1]==0) { obs[player1.lin][player1.col]=0; put_back(player1.lin,player1.col); player1.col++; obs[player1.lin][player1.col]=3; player1=SDL_LoadBMP("warrior1_on_grass.bmp"); } } SDL_Delay(50); apply_surface((player1.col+COL_START)*40,player1.lin*40,player1,screen); SDL_Flip(screen); SDL_PumpEvents(); } if(player2.hp>player1.hp) { player1=SDL_LoadBMP("dead_warrior1_on_grass.bmp"); apply_surface((player1.col+COL_START)*40,player1.lin*40,player1,screen); message=TTF_RenderText_Solid(font,"Player 2 wins!",textColor); player2.money+=player2.hp+player2.mana+player1.money/50; player1.money+=player2.money/75+20; player2.xp+=100; player1.xp+=20; } else if(player2.hp!=player1.hp) { player=SDL_LoadBMP("dead_warrior_on_grass.bmp"); apply_surface((player2.col+COL_START)*40,player2.lin*40,player,screen); message=TTF_RenderText_Solid(font,"Player 1 wins!",textColor); player1.money+=player1.hp+player1.mana+player2.money/50; player2.money+=player1.money/75+20; player1.xp+=100; player2.xp+=20; } else { player1=SDL_LoadBMP("dead_warrior1_on_grass.bmp"); apply_surface((player1.col+COL_START)*40,player1.lin*40,player1,screen); player=SDL_LoadBMP("dead_warrior_on_grass.bmp"); apply_surface((player2.col+COL_START)*40,player2.lin*40,player,screen); message=TTF_RenderText_Solid(font,"Round draw!",textColor); int cash=(player2.money+player1.money)/2/25; player1.money+=cash; player2.money+=cash; player2.xp+=50; player1.xp+=50; } player1.save_player1("player1"); player2.save_player("player2"); Mix_CloseAudio(); Mix_OpenAudio(22050,MIX_DEFAULT_FORMAT,2,4096); sound=Mix_LoadWAV("win.wav"); Mix_PlayChannel(-1,sound,0); apply_surface(((COL_MAX+COL_START)/2-1)*40,(LIN_MAX/2-1)*40,message,screen); SDL_Flip(screen); SDL_Delay(2000); TTF_CloseFont(font); SDL_Quit(); return 0; }
void scenario::calculate_n_overlaps(const std::vector<topology::cell> &cells, const std::vector<topology::calorimeter_hit> &calos) { std::vector<int> freecells(cells.size()); fill(freecells.begin(), freecells.end(), 1); std::vector<int> freecalos(calos.size()); fill(freecalos.begin(), freecalos.end(), 1); size_t counter = 0; for (std::vector<sequence>::iterator iseq = sequences_.begin(); iseq != sequences_.end(); ++iseq) { for (std::vector<node>::iterator in = iseq->nodes_.begin(); in != iseq->nodes_.end(); ++in) { if (in->c().id() >= cells.size()) { if (print_level() >= mybhep::VVERBOSE) std::clog << " problem: cell " << in->c().id() << " has larger id than n of cells " << cells.size() << std::endl; continue; } if (freecells[in->c().id()]) freecells[in->c().id()] = 0; else counter++; } if (iseq->has_decay_helix_vertex() && iseq->decay_helix_vertex_type() == "calo") { if (iseq->calo_helix_id() >= calos.size()) { if (print_level() >= mybhep::VVERBOSE) std::clog << " problem: helix calo " << iseq->calo_helix_id() << " has larger id than n of calos " << calos.size() << std::endl; continue; } if (freecalos[iseq->calo_helix_id()]) freecalos[iseq->calo_helix_id()] = 0; else counter++; } if (iseq->has_helix_vertex() && iseq->helix_vertex_type() == "calo") { if (iseq->helix_vertex_id() >= calos.size()) { if (print_level() >= mybhep::VVERBOSE) std::clog << " problem: helix calo-vertex " << iseq->helix_vertex_id() << " has larger id than n of calos " << calos.size() << std::endl; continue; } if (iseq->helix_vertex_id() != iseq->calo_helix_id()) { // avoid double counting if both // extrapolations point to the same // calo if (freecalos[iseq->helix_vertex_id()]) freecalos[iseq->helix_vertex_id()] = 0; else counter++; } } if (iseq->has_decay_tangent_vertex() && iseq->decay_tangent_vertex_type() == "calo") { if (iseq->calo_tangent_id() >= calos.size()) { if (print_level() >= mybhep::VVERBOSE) std::clog << " problem: tangent calo " << iseq->calo_tangent_id() << " has larger id than n of calos " << calos.size() << std::endl; continue; } if (iseq->calo_tangent_id() != iseq->calo_helix_id() && iseq->calo_tangent_id() != iseq->helix_vertex_id()) { // avoid double counting if both // extrapolations point to the same // calo if (freecalos[iseq->calo_tangent_id()]) freecalos[iseq->calo_tangent_id()] = 0; else counter++; } } if (iseq->has_tangent_vertex() && iseq->tangent_vertex_type() == "calo") { if (iseq->tangent_vertex_id() >= calos.size()) { if (print_level() >= mybhep::VVERBOSE) std::clog << " problem: tangent calo-vertex " << iseq->tangent_vertex_id() << " has larger id than n of calos " << calos.size() << std::endl; continue; } if (iseq->tangent_vertex_id() != iseq->calo_helix_id() && iseq->tangent_vertex_id() != iseq->calo_tangent_id() && iseq->tangent_vertex_id() != iseq->helix_vertex_id()) { // avoid double counting if both // extrapolations point to the // same calo if (freecalos[iseq->tangent_vertex_id()]) freecalos[iseq->tangent_vertex_id()] = 0; else counter++; } } } n_overlaps_ = counter; return; }
/* Print group and element level headers/trailers BEFORE an element is printed */ void print_level_before(struct record *prev_record, struct record *curr_record) { int pl = 0,i; if(!curr_record->level) { if(prev_record && prev_record->level && prev_record->level->element_name) print_level(prev_record->level,prev_record->o->element_trailer,prev_record->o->indent,get_indent_depth(prev_record->level->level) - 1); return; } if(curr_record->level->level > max_level) max_level = curr_record->level->level; last_level = curr_record->level->level; if(prev_record && prev_record->level) pl = prev_record->level->level; if(last_level == pl) // in the same level { if(prev_record->level->element_name) print_level(prev_record->level,prev_record->o->element_trailer,prev_record->o->indent,get_indent_depth(pl) - 1); if((prev_record->level->group_name && curr_record->level->group_name && strcmp(prev_record->level->group_name,curr_record->level->group_name) != 0) || (!prev_record->level->group_name || !curr_record->level->group_name)) { if(prev_record->level->group_name) print_level(prev_record->level,prev_record->o->group_trailer,prev_record->o->indent,get_indent_depth(pl - 1)); if(curr_record->level->group_name) print_level(curr_record->level,curr_record->o->group_header,curr_record->o->indent,get_indent_depth(last_level - 1)); } } else if(last_level > pl) // current record is deeper in as previous { if(curr_record->level->group_name) print_level(curr_record->level,curr_record->o->group_header,curr_record->o->indent,get_indent_depth(pl)); } else if(last_level < pl) // current record is higher as previous, print trailers for elements between current and previous { i = pl; while(i >= last_level) { if(levels[i] && levels[i]->element_name) print_level(levels[i],curr_record->o->element_trailer,curr_record->o->indent,get_indent_depth(i) - 1); if(i > last_level && levels[i] && levels[i]->group_name) print_level(levels[i],curr_record->o->group_trailer,curr_record->o->indent,get_indent_depth(i - 1)); i--; } i++; if(levels[i] && ((levels[i]->group_name && curr_record->level->group_name && strcmp(levels[i]->group_name,curr_record->level->group_name) != 0) || (!levels[i]->group_name || !curr_record->level->group_name))) { if(levels[i]->group_name) print_level(levels[i],curr_record->o->group_trailer,curr_record->o->indent,get_indent_depth(i - 1)); if(curr_record->level->group_name) print_level(curr_record->level,curr_record->o->group_header,curr_record->o->indent,get_indent_depth(last_level - 1)); } reset_levels(last_level + 1,max_level); } levels[last_level] = curr_record->level; if(curr_record->level->element_name) print_level(curr_record->level,curr_record->o->element_header,curr_record->o->indent,get_indent_depth(last_level) - 1); }
void struct_access::print(ostream &os, int level){ field->print(os, level + 1); print_level(os, level); os << tk.get_src() << endl; left->print(os, level + 1); }