Ejemplo n.º 1
0
static int
remove_blanks(FILE* f)
{
  int count = 0 ;
  int c ;

  while (1) {
    c = fgetc(f) ;

    switch(c) {

    case '\t' : case '\n' :
    case '\r' : case ' '  :
      ++ count ;
      break ;

    case '#' :
      count += 1 + remove_line(f) ;
      break ;

    case EOF :
      goto quit_remove_blanks ;

    default:
      ungetc(c, f) ;
      goto quit_remove_blanks ;
    }
  }
 quit_remove_blanks:
  return count ;
}
Ejemplo n.º 2
0
Point3D const StatusStructure::process_event(Event* event, EventStructure& event_structure) {
    Point3D result(0.f, 0.f, -1.f);
    Event::EventType type(event->get_type());

    switch (type) {
        case Event::START: {
            StartEvent* start_event(reinterpret_cast<StartEvent*>(event));
            //std::cout << "Processing " << *start_event << std::endl;
            add_line(start_event, event_structure);
        } break;

        case Event::END: {
            EndEvent* end_event(reinterpret_cast<EndEvent*>(event));
            //std::cout << "Processing " << *end_event << std::endl;
            remove_line(end_event, event_structure);
        } break;

        case Event::INTERSECTION: {
            IntersectionEvent* intersection_event(reinterpret_cast<IntersectionEvent*>(event));
            //std::cout << "Processing " << *intersection_event << std::endl;
            swap(intersection_event, event_structure);
            result = intersection_event->get_position();
        } break;

        default: break;

    }
//    std::cout << std::endl;

    return result;
}
Ejemplo n.º 3
0
void
ItemScriptLine::invalid_remove() {
  auto menu = dynamic_cast<ScriptMenu*>(MenuManager::instance().current_menu());
  if (!menu) {
    return;
  }
  menu->remove_line();
}
Ejemplo n.º 4
0
void Field::check_lines()
{
    for(unsigned int line = 19; line--;){
        unsigned int column = 0;
        while(column < 10 && _colors[column][line].get_color()){
            column++;
        }
        if(column == 10){
            remove_line(line);
            // removing a line shifts all lines above one line down
            line++;
        }
    }
}
Ejemplo n.º 5
0
void tick(int * reached_bottom){
	static int filled_lines[4];
	static int counter = 0;
	
	if(*reached_bottom){
		//new piece reached the bottom or gravity activated and things need to be rechecked
		*reached_bottom = 0;
		
		if(counter == 0){//only if call is not coming from gravity stuff
			write_to_world(&current_tetromino, &world);
		}
		
		counter = 0;
		//check for lines right here & gravity
		for(int i = WORLD_HEIGHT-1; i >= world.top_line; i--){
			if(check_line(i)){
				fill_line(i);
				filled_lines[counter] = i;
				counter++;
			}
		}
		
		world.points += 100*counter*counter;
		
		if(counter == 0){
			fill_tetromino(&current_tetromino,rand()%7);
		
			if(check_collision(&current_tetromino, &world)){
				//GAME OVER
				init_game();
			}
		}else{
			current_tetromino.visible = 0;//dont display it while removing lines
		}
		
	}else if(counter != 0){
		//lines to remove, gravity to activate
		//remove from top to bottom
		for(int i = counter-1; i >= 0; i--){
			remove_line(filled_lines[i]);
		}
		set_tick_time();
		*reached_bottom = 1;
	}else{
		//just a normal turn, m8
		*reached_bottom = go_down(&current_tetromino, &world);//in the next tick: block is placed
	}
	
}
Ejemplo n.º 6
0
state_t env_step(env_t* p_env, action_t action, double* reward, int* terminal) {
  assert(p_env!=NULL);
  int n_rows = p_env->n_rows;
  int n_cols = p_env->n_cols;
  int block_dropped=0;
  int somme=0;
  int i,j;
  int win=0; //Si l'état terminal verifié plus tard est un état vainqueur ou perdant
  (*reward)=0;
  if(p_env->grid[0][action]==1)
  {
    (*reward)+=-10.0;
}
  else
    for (i = n_rows-1; i>=0; i--)
    {
      //printf("boucle for");
      if(p_env->grid[i][action]==0 && block_dropped==0)
      {
        p_env->grid[i][action]=1;
        for (j = 0; j < n_cols; j++)
        {
          somme+=p_env->grid[i][j];
        }
        if(somme==n_cols)
        {
          remove_line(i,p_env);
          (*reward)=100.0;
        }
        block_dropped =1;
      }
    }
    //printf("apres for");
    gridtostate(p_env);
    (*terminal) = is_terminal_state(p_env,p_env->cell,&win);

  if (*terminal) //calcul des points
  {
    //printf("%llu",p_env->cell);
    if(win)
      (*reward)+=1000.0;
    else
      (*reward)+=-1000.0;
  }
  (*reward)-=1.0;
  return env_observe_state(p_env);

}
Ejemplo n.º 7
0
void remove_asm_line (int idx)
{
  int i;
  int matched = 0;
  for (i=0; i<toks; i++) {
    if (!matched && tok_list[i].kind == TOK_STRING) {
      char *s = tok_list[i].str;      
      int numlines;
      int res = remove_line (s, idx, &numlines);
      if (res) {
	matched = 1;
      } else {
	idx -= numlines;
      }
    }
    printf ("%s", tok_list[i].str);
  }
  if (matched) {
    exit (0);
  } else {
    exit (1);
  }
}
Ejemplo n.º 8
0
int main( int argc, char ** argv ) {
    if ( argc != 2 ) {
        err( "usage shrinkMap <mapfile.map>" );
    }

    // read input into memory
    FILE * fp = fopen( argv[1], "rb" );
    if ( !fp ) {
        err( "could open input" );
    }
    char * in_data = (char *) malloc ( 1024 * 1024 );
    char * p = in_data;
    unsigned int n, data_sz = 0 ;
    do {
        n = fread( p, 1, 4096, fp );
        if ( n <= 0 ) break;
        data_sz += n;
        p += n;
    } while(1);
    fclose( fp );

    // create outfilename
    char oname[256];
    char tmp[256];
    strcpy( tmp, argv[1] );

    char * f = (char *) strstr( tmp, ".map" );
    if ( !f ) err( "f**k, I dont get it" );
    *f = '\0';
    sprintf( oname, "%s-shrunk.map", tmp );

    char buf[256];

    // open output
    fp = fopen( oname, "wb" );
    if ( !fp ) {
        sprintf( buf, "couldn't open %s for writing", oname );
        err( buf );
    }

    unsigned int i = 0;
    bool w = false;
    while ( i < data_sz ) {

        if ( !white( in_data[i] ) ) {
            // just remove comment
            if ( is_comment(&in_data[i]) ) 
            {
                remove_line( &in_data[i], &i, data_sz );
            } 
            else // print the line
            {
                unsigned int len = linelen( &in_data[i], i, data_sz );
                
                strncpy( buf, &in_data[i], len );
                buf[len] = '\0';

                fputs( buf, fp );
                i += len;
            }
            if ( i >= data_sz )
                break;
        }

        // skip all white chars
        w = false;
        while ( white( in_data[i] ) ) {
            i++;
            w = true;
            if ( i >= data_sz ) {
                w = false; break;
            }
        }

        if ( !white(in_data[i]) && !is_comment( &in_data[i] ) && w )
            fputc( ' ', fp );
    }
    
    fclose(fp);
    free( in_data );
    fprintf( stdout, "created %s\n", oname );
    return 0;
}