Ejemplo n.º 1
0
void gerenciadorArvoreB::restore(BTPage* reg,int i,int RRN){
	if( i == reg->getTotalChaves()){
		BTPage* aux = loadPTPage(reg->filha[i-1]);
		if(aux->getTotalChaves() > ((aux->D/2))){	
			move_right(reg,i-1,RRN);	
		}else{
			combine(reg,i,RRN);	
		}		
	}else{
		if(i==0){
			BTPage* aux = loadPTPage(reg->filha[1]);
			if(aux->getTotalChaves() > ((aux->D/2))){
				move_left(reg,1,RRN);
			}else{			
				combine(reg,1,RRN);
			}
		}else{
			BTPage* aux = loadPTPage(reg->filha[i-1]);
			if(aux->getTotalChaves() > ((aux->D/2))){
				move_right(reg,i-1,RRN);
			}else{
				aux = loadPTPage(reg->filha[i+1]);	
 				if(aux->getTotalChaves() > ((aux->D/2))){
					move_left(reg,i+1,RRN);
				}else{
					combine(reg,i,RRN);
				}
				
			}
		}
	}	
}
Ejemplo n.º 2
0
void screen_move_up(struct te_buffer *buf)
{
	if (buf == NULL)
		return;

	int	i = 0;
	int	old_x = buf->x;

	/* move until the first character of the line */
	while(prev_char(buf) != '\n') {
		if(move_left(buf) == ERR)
			break;
	} 
	move_left(buf);

	/* then, move to the beginning of the previous line */
	while(prev_char(buf) != '\n') {
		if(move_left(buf) == ERR)
			break;
	}

 	screen_prev_line(buf);
 	buf->x = 0; 

	/* mimic emacs' behaviour of moving the user to the exact offset we were on */
		
	while(buf->x < old_x && next_char(buf) != '\n' && curr_char(buf) != '\n') {
		if (screen_move_right(buf) == ERR)
			break;
	}

	move(buf->y, buf->x);
	return;
}
Ejemplo n.º 3
0
/*** get keypad input ****/
void get_keypad_input() {  
  char keypad_key;
  keypad_enable();
  while(training) {
    keypad_key=getkey();          // get value from keypad
    wait_keyup();
    lcd_init();
    set_lcd_addr(0x00);
    if(keypad_key==1) {           // 1 = forward
      move_forward();               
    }else if(keypad_key==4) {     // 4 = left
      move_left();
    }else if(keypad_key==7) {     // 7 = right
      move_right();
    }else if(keypad_key==0) {     // 0 = reverse
      move_reverse();
    }else if(keypad_key==6) {     // 7 = pause
      move_pause();
    }else if(keypad_key==9) {     // break out of training mode
      training=0;
      move_stop();
      display_movement(&stop_training);
      break;
    }else{
      display_movement(&error);
    }
    ms_delay(50);
  }
}
Ejemplo n.º 4
0
/*** Playback Robot ***/
void playback_robot(){
  while(playback) {
    int i=0;
    display_movement(&start_playback);
    /* pull from array */
    for(i=0; i<=array_length; i++) {
      int direction=array1[i];
      
      if(direction == 1) {
        move_forward();
      }else if(direction == 2) {
        move_left();
      }else if(direction == 3) {
        move_right();
      }else if(direction == 4) {
        move_reverse();
      }else if(direction == 5) {
        move_pause();
      }else if((direction == 0) || (direction == 9)) {
        playback=0;
        display_movement(&stop_playback);
        break;
      } else {
        playback=0;
        break;
      }
      if(SW5_down()){         //switch5 stop playback mode
        playback=0;
        display_movement(&stop_playback);
      }
    }
  }
}
Ejemplo n.º 5
0
void screen_delete_char(struct te_buffer *buf)
{
	if (buf == NULL)
		return;

	move_left(buf);
	bstring previous_line = current_line_as_bstring(buf->contents, max(buf->point - 1, 0));
	char c = curr_char(buf);
	delete_char(buf);
	bstring s = current_line_as_bstring(buf->contents, max(buf->point, 0));

	if (c == '\n') {
		statusprintf("s : %s", bstr2cstr(s, '\0'));
		clear_nfirst_lines(buffer_win, max(buf->y, 0));
		scroll_up(buffer_win);
 		paint_buffer_nlines(buf, buf->y + 1); 
		screen_prev_line(buf);
		buf->x = max(screen_line_length(previous_line, 0) - 1, 0); /* max because scr_l_len("a") == 1 and coords begin at 0 */

		move(buf->y, buf->x);
	} else {
		draw_line(s, buf->y);
		screen_move_left(buf);
		move_right(buf); /* yes it's ugly but I don't feel like recoding screen_move_right atm */
	}

	bdestroy(previous_line);
	bdestroy(s);
}
Ejemplo n.º 6
0
static void		read_stdin(t_env *env)
{
	char	buffer[20];
	int		rd;

	ft_memset(buffer, 0, 20);
	rd = read(0, buffer, 20);
	if (rd == 1 && buffer[0] == 27)
		error_quit(NULL);
	else if (rd == 1 && buffer[0] == 10)
		return_selected(env);
	else if ((rd == 1 && buffer[0] == 127)
			|| !ft_strcmp(buffer, env->key_code_delete))
		delete_current(env);
	else if (rd == 1 && buffer[0] == ' ')
	{
		if (env->curr)
			env->curr->item->selected = !env->curr->item->selected;
	}
	else if (!ft_strcmp(buffer, env->key_code_down))
		move_down(env);
	else if (!ft_strcmp(buffer, env->key_code_up))
		move_up(env);
	else if (!ft_strcmp(buffer, env->key_code_left))
		move_left(env);
	else if (!ft_strcmp(buffer, env->key_code_right))
		move_right(env);
}
Ejemplo n.º 7
0
void solve()
{
    Zero(ans);
    Zero(cnt);

    int r = b - 1;
    int c = 0;
    int dir = 0;

    for (int i = 0; i < b; ++i)
        for (int j = 0; j < w; ++j)
            if (maze[i][j] == '0') ++ans[0];

    while (true) {
        while (! can_move(r, c, dir))
            dir = move_left(dir);

        r += dd[dir][0];
        c += dd[dir][1];

        if (cnt[r][c] <= 4) --ans[cnt[r][c]];
        ++cnt[r][c];
        if (cnt[r][c] <= 4) ++ans[cnt[r][c]];

        if (r == b - 1 && c == 0) break;

        if (! wall_right(r, c, dir))
            dir = move_right(dir);
    }
}
Ejemplo n.º 8
0
int Frame::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QFrame::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: press_top_mid((*reinterpret_cast< QMouseEvent*(*)>(_a[1]))); break;
        case 1: move_top_mid((*reinterpret_cast< QMouseEvent*(*)>(_a[1]))); break;
        case 2: press_bottom_left((*reinterpret_cast< QMouseEvent*(*)>(_a[1]))); break;
        case 3: move_bottom_left((*reinterpret_cast< QMouseEvent*(*)>(_a[1]))); break;
        case 4: press_bottom_right((*reinterpret_cast< QMouseEvent*(*)>(_a[1]))); break;
        case 5: move_bottom_right((*reinterpret_cast< QMouseEvent*(*)>(_a[1]))); break;
        case 6: press_bottom_mid((*reinterpret_cast< QMouseEvent*(*)>(_a[1]))); break;
        case 7: move_bottom_mid((*reinterpret_cast< QMouseEvent*(*)>(_a[1]))); break;
        case 8: press_right((*reinterpret_cast< QMouseEvent*(*)>(_a[1]))); break;
        case 9: move_right((*reinterpret_cast< QMouseEvent*(*)>(_a[1]))); break;
        case 10: press_left((*reinterpret_cast< QMouseEvent*(*)>(_a[1]))); break;
        case 11: move_left((*reinterpret_cast< QMouseEvent*(*)>(_a[1]))); break;
        case 12: destroy_it(); break;
        case 13: maximize_it(); break;
        case 14: iconify_it(); break;
        case 15: dragEnterEvent((*reinterpret_cast< QDragEnterEvent*(*)>(_a[1]))); break;
        case 16: dragMoveEvent((*reinterpret_cast< QDragMoveEvent*(*)>(_a[1]))); break;
        case 17: dropEvent((*reinterpret_cast< QDropEvent*(*)>(_a[1]))); break;
        default: ;
        }
        _id -= 18;
    }
    return _id;
}
Ejemplo n.º 9
0
static void move_begin()
{
	while( offset > 0 )
	{
		move_left();
	}
}
Ejemplo n.º 10
0
t_history			*down_history(t_history *list,
					t_it *it)
{
	int		i;

	i = 0;
	if (it->line)
		i = ft_strlen(it->line);
	while (i--)
		move_left(it);
	tputs(tgetstr("ce", NULL), 0, my_putchar);
	tputs(tgetstr("cd", NULL), 0, my_putchar);
	ft_memdel((void**)&it->line);
	if (list->next)
	{
		list = list->next;
		it->line = ft_strdup(list->cmd);
		ft_putstr(list->cmd);
		i = ft_strlen(it->line);
		while (i--)
			it->i++;
		return (list);
	}
	else
		return (return_last_elem(it, list));
}
Ejemplo n.º 11
0
void perform_user_action(int board[SIZE][SIZE]) {
  char key_pressed = getchar();

  switch((int)key_pressed) {
    case 104:  // 'h'
      move_left(board);
      break;
    case 108:  // 'l'
      move_right(board);
      break;
    case 107:  // 'k'
      move_up(board);
      break;
    case 106:  // 'j'
      move_down(board);
      break;
    case 114: // 'r'
      init_board(board);
      break;
    case 113: // 'q'
      exit(0);
    default:
      perform_user_action(board);
  }
}
Ejemplo n.º 12
0
int	bol(t_elem *e)
{
  my_tputs(e->cap[VI]);
  while (move_left(e) != -1);
  my_tputs(e->cap[VE]);
  return (0);
}
Ejemplo n.º 13
0
void* fctThreadForme(void* param)
{
   //printf("--Thread forme\n");

   S_FORME *forme;
   forme = param;

   pthread_mutex_lock(&mutexAttShift);
   AttShift = 1;
   pthread_mutex_unlock(&mutexAttShift);
   while(haut == 0)// && rotation == 0 && droite == 0 && gauche == 0)
      {
         pthread_cond_wait(&condEvent, &mutexEvent);
         pthread_mutex_lock(&mutexAttShift);
         while(AttShift == 0)
            pthread_cond_wait(&condAttShift, &mutexAttShift);
         pthread_mutex_unlock(&mutexAttShift);

         if(haut == 19)
            {
               while(move_up(forme) == 0);
               haut--;
            }

         else if(haut > 0)
            {
               if(move_up(forme) == 0)
                  haut--;
               /*int i, j;
               for (i = 0; i < NB_LIGNE; i++)
                  {
                     for (j = 0; j < NB_COLONNE; j++)
                        printf("%4d ", tab[i][j]);
                     printf("\n");
                  }
                  printf("\n");printf("\n");printf("\n");*/
            }
                    
         if(gauche > 0)
            {
               move_left(forme);
               gauche--;
            }
       
         if(droite > 0)
            {
               move_right(forme);
               droite--;
            }
         
         if(rotation > 0)
            {
               move_rotation(forme);
               rotation--;
            }
      }
   pthread_exit(NULL);
   
}
Ejemplo n.º 14
0
void move_down(struct game_t *game)
{
	rotate_clockwise(game);
	move_left(game);
	rotate_clockwise(game);
	rotate_clockwise(game);
	rotate_clockwise(game);
}
Ejemplo n.º 15
0
int main()
{
	init_curses();

	const char *exit_msg = "";
	srandom(time(NULL));

	struct game_t game = {0};
	int last_turn = game.turns;

	get_highscore_filepath(&game);
	load_highscore(&game);

	place_tile(&game);
	place_tile(&game);

	while (1) {
		print_game(&game);

		if (lose_game(game)) {
			exit_msg = "lost";
			goto lose;
		}

		last_turn = game.turns;

		switch (getch()) {
    case 'h': case KEY_LEFT:  case 'a': move_left(&game); break;
    case 'j': case KEY_DOWN:  case 's': move_down(&game); break;
    case 'k': case KEY_UP:    case 'w': move_up(&game);   break;
    case 'l': case KEY_RIGHT: case 'd': move_right(&game);break;
		case 'q':
			exit_msg = "quit";
			goto end;
		}

		if (last_turn != game.turns)
			place_tile(&game);
	}

lose:
	move(7, 0);
	printw("You lose! Press q to quit.");
	while (getch() != 'q');
end:
	endwin();
	if(game.score > game.highscore)
	{
		game.highscore = game.score;
		save_highscore(&game);
	}
	printf("You %s after scoring %d points in %d turns, "
		"with largest tile %d. The local highscore is %d points.\n",
		exit_msg, game.score, game.turns,
		1 << max_tile((tile_t *)game.board), game.highscore);
	free(game.highscorefile);
	return 0;
}
Ejemplo n.º 16
0
void SantaMap::move(const char movement) {
    switch(movement) {
        case '<': move_left(); break;
        case '^': move_up(); break;
        case '>': move_right(); break;
        case 'v': move_down(); break;
    }
    increment_counter_if_new_visited_house();
}
Ejemplo n.º 17
0
Archivo: 2048.c Proyecto: hos3in/2048
int main(int argc, const char *argv[])
{
	char game[3][3]={0};
	char key;
	show_game(game,3);
	printf("\n");
	while(scanf(" %c",&key)){
		switch(key){
			case 'w':
				{
			//	printf("%s\033[k");
				system("clear");
				sort_up(game,3);
				move_up(game,3);
				randfunc(game,3);
			        show_game(game,3);
				}
				break;
			case 'a':
				{
		//		printf("%s\033[1J");
				system("clear");  
				sort_left(game,3);
				move_left(game,3);
			        randfunc(game,3);
				show_game(game,3);

				}
				break;

			case 'd':
				{
			//	printf("%s\033[1k");
					system("clear");
					sort_right(game,3);
					move_right(game,3);
					randfunc(game,3);
					show_game(game,3);
				}
				break;
			
			case 's':
				{
		//		printf("%s\033[1J");
				system("clear");  
				sort_down(game,3);
				move_down(game,3);
				randfunc(game,3);
			        show_game(game,3);
				}
				break;

		}
		
	}
	return 0;
}
Ejemplo n.º 18
0
int lose_game(struct game_t test_game)
{
	int start_turns = test_game.turns;
	move_left(&test_game);
	move_up(&test_game);
	move_down(&test_game);
	move_right(&test_game);
	return test_game.turns == start_turns;
}
Ejemplo n.º 19
0
void Paddle::move(){
    if(right_pressed){
        move_right();
    }
    else{ if (left_pressed){
        move_left();
    }
    }
    move_ball();
}
Ejemplo n.º 20
0
	void moving(ground& earth, square& another)
	{
		move_left();
		move_right();		
		gravity(earth);
		warp(another);
		collision_check(another);
		set_square_posit();
		move_shots();
	}
Ejemplo n.º 21
0
int move_cursor_bol(Text *text)
{
	ssize_t i = text->gap_start-1;
	for (; i >= 0; i = text->gap_start-1) {
		if (text->buf[i] == '\n') break;
		move_left(text);
	}

	return 0;
}
Ejemplo n.º 22
0
int main()
{
	int i, j;
	srand(time(NULL));
	
	init();
	
	print_map();

	while (1) {
		char ch = getchar();
		if (ch < 'i' || ch > 'l') continue;
		if (!tgt.isOnMap) {
			generate_tgt();
			update_bullets();
			if (ch == 'j')
				move_left();
			if (ch == 'i')
				shoot();
			if (ch == 'l')
				move_right();
			collision();
		} else {
			update_tgt();
			update_bullets();
			if (ch == 'j')
				move_left();
			if (ch == 'i')
				shoot();
			if (ch == 'l')
				move_right();
			collision();
		}
		print_map();
		if (Life == 0) break;
	}

	printf("Game Over\n");
	printf("Your Score: %d\n", Score);

	return 0;
}
Ejemplo n.º 23
0
int		move_boss(t_struct *st)
{
  if (check_scale_boss(st) == 1)
    return (0);
  if (st->boss.x - st->heros.x > 0)
    move_left(st);
  else
    if (st->boss.x - st->heros.x < 0)
      move_right(st);
  return (0);
}
Ejemplo n.º 24
0
static void		ft_move_saved(t_it *it)
{
	int target;

	if (it->i > it->saved_i)
	{
		target = it->saved_i;
		while (it->i != target)
			move_left(it);
	}
}
Ejemplo n.º 25
0
void smart_object::repel(complex_object target)//object moves away from object B
{
    if(near_front(target))
        move_back();
    if(near_back(target))
        move_forward();
    if(near_left(target))
        move_right();
    if(near_right(target))
        move_left();
}
Ejemplo n.º 26
0
static void			handle_history(int i, t_it *it)
{
	while (i--)
		move_left(it);
	tputs(tgetstr("ce", NULL), 0, my_putchar);
	tputs(tgetstr("cd", NULL), 0, my_putchar);
	ft_putstr(it->line);
	i = ft_strlen(it->line);
	while (i--)
		it->i++;
}
Ejemplo n.º 27
0
//缓冲区移位
//offset大于0时左移
//offset小于0时右移
void move_bits(uint8 * p_input, uint8 bit_start, uint8 bit_end,  signed char offset)
{
    if(0 < offset)	//左移
    {
        move_left(p_input, bit_start, bit_end, offset);
    }
    else if(0 > offset)	//右移
    {
        move_right(p_input, bit_start, bit_end, -offset);
    }
}
Ejemplo n.º 28
0
void smart_object::attract(complex_object target)//object moves toward object B
{
    if(near_front(target))
        move_forward();
    if(near_back(target))
        move_back();
    if(near_left(target))
        move_left();
    if(near_right(target))
        move_right();
}
Ejemplo n.º 29
0
int main(int argc, char *argv[])
{
	int ret = 0,cnt =0;
	int fd,fds,i,diff =0;
	unsigned int dist,prevdist = 0,prev_direction;
        struct sigaction act;
	fd = open(display, O_RDWR);
	if (fd < 0)
		pabort("can't open device");
	printf("\n initialising....:");
	ioctl(fd, SPI_LED_INITIALISE, 0);
	transfer(fd);
	fds = open(sensor, O_RDWR);
	if (fds < 0)
		pabort("can't open sensor");

        memset (&act, '\0', sizeof(act));
        act.sa_sigaction = &terminatehdl;
        act.sa_flags = SA_SIGINFO;
        if (sigaction(SIGINT, &act,NULL) < 0) {
                perror ("sigaction");
                return 1;
        }

	while((!terminate)&&(cnt < 120)){	
	  dist = read(fds,NULL,0);
	  write(fds,NULL,0);
	  printf("\ndistance is %lu \n",dist);
	  diff  = dist - prevdist;
	  if(diff<0)
	  {
	    diff = prevdist - dist;
	  }
	  if(dist < 40)
	  {
	      move_left(fd);
          }
	  else 
	  {
	      move_right(fd);
          }
	  prevdist = dist;
	  cnt++;
	}
	write(fd,NULL,0);
	/* time to displat some patterns */
	transfer_moves(fd);
	anime(fd);	
	write(fd,NULL,0);
	usleep(100000);
	close(fd);
	close(fds);
	return 0;
}
Ejemplo n.º 30
0
void			process(t_env *e)
{
	if (e->input->a == 1)
		move_left(e);
	else if (e->input->d == 1)
		move_right(e);
	if (e->input->w == 1)
		move_forward(e);
	else if (e->input->s == 1)
		move_backward(e);
}