Beispiel #1
0
  // Get integer part, starting search from given lower bound.
  void binary_search(mpz_ptr lower) {
    while (!mpz_sgn(p->c0)) move_right();
    for (;;) {
      mpz_set(z0, lower);
      mpz_set(z, lower);
      int sign = sign_quad();
      mpz_set_ui(pow2, 1);
      for (;;) {
	mpz_add(z, z0, pow2);
	if (sign_quad() != sign) break;
	mpz_mul_2exp(pow2, pow2, 1);
      }
      mpz_set(z1, z);

      for (;;) {
	mpz_add(z, z0, z1);
	mpz_div_2exp(z, z, 1);
	if (!mpz_cmp(z, z0)) break;
	if (sign_quad() == sign) {
	  mpz_set(z0, z);
	} else {
	  mpz_set(z1, z);
	}
      }
      sign = sign_quad1();
      mpz_set(z, z1);
      if (sign_quad1() != sign) break;
      move_right();
    }
  }
Beispiel #2
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);
				}
				
			}
		}
	}	
}
Beispiel #3
0
	void Camera3D::move_relative_to_view(F32 speed, glm::vec2 coords){
		
		F32 total_speed = sqrt(coords.x * coords.x + coords.y * coords.y);
		move_forward(speed * -coords.y / total_speed);
		move_right(speed * coords.x / total_speed);

	}
Beispiel #4
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);
}
Beispiel #5
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);
    }
}
Beispiel #6
0
int screen_move_right(struct te_buffer *buf)
{
	if (buf == NULL)
		return ERR;

	if (move_right(buf) == ERR) /* last char of the document */
		return ERR;

	if (prev_char(buf) == '\n') {
		screen_next_line(buf);
	} else { 
		/* tab is the only character larger than 1 */
			if (prev_char(buf) == '\t') {
				buf->x += TAB_LEN;
			} else {
				buf->x++;
			}

			if(buf->x == COLS - 1) { 
				bstring s = current_line_as_bstring(buf->contents, buf->point);
				int off = screen_numchar_to_offset(s, COLS - 1);
				bstring s2 = bmidstr(s, off, blength(s) - off);
				draw_line(s2, buf->y);
				bdestroy(s);
				bdestroy(s2);
				wmove(buffer_win, buf->y, 0);
				refresh();
			}
	}

	move(buf->y, buf->x);
	return OK;
}
/*** 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);
  }
}
Beispiel #8
0
void screen_move_down(struct te_buffer *buf)
{
	if (buf == NULL)
		return;

	if (buf->point == blength(buf->contents))
	    return;

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

	do {
		/* move until the first char of the next line */
		if (move_right(buf) == ERR)
			break;

	} while (prev_char(buf) != '\n');

	screen_next_line(buf);

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

	move(buf->y, buf->x);
	return;
}
/*** 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);
      }
    }
  }
}
Beispiel #10
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);
}
Beispiel #11
0
static void move_end()
{
	while( offset < len )
	{
		move_right();
	}
}
Beispiel #12
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;
}
Beispiel #13
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);
  }
}
Beispiel #14
0
int	eol(t_elem *e)
{
  my_tputs(e->cap[VI]);
  while (move_right(e) != -1);
  my_tputs(e->cap[VE]);
  return (0);
}
Beispiel #15
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);
   
}
Beispiel #16
0
bool wall_right(int r, int c, int dir)
{
    int d2 = move_right(dir);
    int r2 = r + dd[d2][0];
    int c2 = c + dd[d2][1];

    return (!valid_pos(r2, c2)) || maze[r2][c2] == '1';
}
Beispiel #17
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;
}
Beispiel #18
0
GUI_status SpellView::move_down()
{
	sint8 index = get_selected_index();

	if(index != -1 && index < 15 && index != (num_spells_per_page-1))
	{
		if(cur_spells[index+1] != -1)
		{
			spell_container->quality = cur_spells[index+1];
			update_display = true;
		}
		else
			move_right();
	}
	else
		move_right();
	return GUI_YUM;
}
Beispiel #19
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();
}
Beispiel #20
0
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;
}
Beispiel #21
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;
}
void Paddle::move(){
    if(right_pressed){
        move_right();
    }
    else{ if (left_pressed){
        move_left();
    }
    }
    move_ball();
}
	void moving(ground& earth, square& another)
	{
		move_left();
		move_right();		
		gravity(earth);
		warp(another);
		collision_check(another);
		set_square_posit();
		move_shots();
	}
Beispiel #24
0
int move_cursor_eol(Text *text)
{
	size_t i = text->text_start;
	for (; text->size - text->text_start > 0; i = text->text_start) {
		if (text->buf[i] == '\n') break;
		move_right(text);
	}

	return 0;
}
Beispiel #25
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;
}
Beispiel #26
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);
    }
}
Beispiel #27
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();
}
Beispiel #28
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);
}
Beispiel #29
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();
}
Beispiel #30
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);
}