int leader(){ int i=0; int found = 0; while(!found){ if(go_to_position(positions[i], 10, NORMAL_SPEED)){ //predefined posiion reached found = get_ball(); //if(found){ //decide if and when reset positions to prefdefined one robot.x = positions[i].x; robot.y = positions[i].y; i++; //} } else { //obstacle or ball found... must chose if it is to avoid or to grab //for now assume it is a ball int a = robot.t; found = get_ball(); robot.x+=sin(a*M_PI/180)*STOP_DIST; robot.y+=cos(a*M_PI/180)*STOP_DIST; } if(i==n_points) i = 0; } }
//this function tris to reach a position avoiding an obstacle and restarting every time an obstacle is found //may deadlock... even if care is taken to properly avoid obsatcles void go_to_position_interruptible(pos_t target_pos, int margin, int speed, int avoid_obstacle) { int result; while(1) { result = go_to_position(target_pos, margin, speed); if(result == REACHED || result == CUSTOM_STOP_MESSAGE) break; if(result == OBSTACLE){ if(avoid_obstacle){ obstacle_avoid(); }else{ break; } } } }
static void move_cursor_word_left(t_env *e, char *str) { int j; int blank; j = 0; blank = ft_iswhitespace(str[e->curs_pos]); while (e->curs_pos >= 0) { if (ft_iswhitespace(str[e->curs_pos]) != blank || e->curs_pos == 0) { e->curs_pos++; go_to_position(e, str, e->curs_pos); break ; } e->curs_pos--; j++; } }
static void move_cursor_word_right(t_env *e, char *str) { int j; int blank; j = 0; blank = ft_iswhitespace(str[e->curs_pos]); while (e->curs_pos <= e->curs_max) { if (ft_iswhitespace(str[e->curs_pos]) != blank || e->curs_pos == e->curs_max) { go_to_position(e, str, e->curs_pos); break ; } e->curs_pos++; j++; } }