int sh_cd(t_data *st) { char *env_pwd; char *path; int ret; ret = 0; env_pwd = ft_strjoin(ft_getenv(st->envtab, "PWD"), "/"); if (st->cmd[1] && (ft_strcmp(st->cmd[1], "-") == 0 || st->cmd[1][0] == '~')) ft_change_part2(st->cmd, env_pwd, st); else if (st->cmd[1]) { path = ft_strjoin(env_pwd, st->cmd[1]); ret = check_right(&path, st->cmd, st); set_var_env(st, ft_strjoin("OLDPWD=", getcwd(NULL, 1024))); path = (st->cmd[1][0] == '/' ? st->cmd[1] : path); chdir(path); } else { path = ft_getenv(st->envtab, "HOME"); set_var_env(st, ft_strjoin("OLDPWD=", getcwd(NULL, 1024))); chdir(path ? path : "/"); } free(env_pwd); set_var_env(st, ft_strjoin("PWD=", getcwd(NULL, 1024))); return (ret); }
t_bool check_grammar_exec(t_token *b, t_token *e) { t_token *tmp; int word; int pipe; int res; tmp = b; word = 0; pipe = 0; while (tmp && tmp != e) { if (!word && tmp->id == PIPE) return (puterror(NULL_CMD, NULL)); word = (tmp->id == WORD) ? (1) : (0); pipe = (tmp->id == PIPE) ? (1) : (0); tmp = tmp->next; } if (pipe) return (puterror(NULL_CMD, NULL)); res = there_are_red(b, e); if (res == 1 && check_left(b, e) != TRUE) return (FALSE); else if (res == 2 && check_right(b, e) != TRUE) return (FALSE); return (TRUE); }
void my_key(t_tetris *st, t_tetriminos *elem, int *x, int *y) { int key; int i; int j; i = *x; j = *y; if ((key = get_key(st)) == 1) { if (check_left(i, j, st, elem) == 0) *x = *x - 1; } else if (key == 2) { if (check_right(i, j, st, elem) == 0) *x = *x + 1; } else if (key == 3) check_left_rotate(i, j, st, elem); else if (key == 4) drop_tetri(y, x, st, elem); else if (key == 5) xexit(st, "See you again :)\n"); else if (key == 6) while (get_key(st) != 6); }
void CRoom_2x1::checkPtrs(int pixelCheck) { nullPtrs(); for (int i = 0; i < m_pRoom_collision->size(); ++i) { CRoom* pRoom = m_pRoom_collision->at(i); if (this->equals(pRoom)) { continue; } // general logic: // if not found (false) // then check to see if the room is found // & set to true if found, false if not // [OPTIMIZATION]: have a better checking columns algorithm for 1x2 or 2x1 or 1x2 to exit checking early check_up(pRoom, pixelCheck); check_down(pRoom, pixelCheck); check_left(pRoom, pixelCheck); check_right(pRoom, pixelCheck); } }
int check_dir(char **maze, t_list **closed, t_list **open, t_data *node) { check_up(maze, closed, open, node); check_right(maze, closed, open, node); check_down(maze, closed, open, node); check_left(maze, closed, open, node); return (0); }
int main() { init(); while(true) { check_right(); check_left(); check_move(); check_scroll(); // wait(0.005); } }
int check_win(t_gboard *p4, int player) { if (check_lines(p4, player) == 1 || check_columns(p4, player) == 1 || check_left(p4, player, 4) == 1 || check_right(p4, player, 4) == 1) { if (player != p4->ia_id) { ft_putendl("Congratulation human... you win."); ft_putendl(" .... This time !!!"); } return (1); } return (0); }
t_map *fusion_right(t_map *map) { t_map *head; head = map; while (head->next) head = head->next; while (head) { if (head->value >= 0) head = check_right(head); head = head->prev; } return (map); }
int check_order(char **tab) { int i; i = 0; while (tab[i]) { if (check_left(tab, i) == -1) return (-1); if (check_right(tab, i) == -1) return (-1); i++; } return (0); }
int am_i_circle(t_player *player) { int nb; nb = 0; if (check_left(player) && check_left_p(player)) nb++; if (check_right(player) && check_right_p(player)) nb++; if (check_up(player) && check_up_p(player)) nb++; if (check_down(player) && check_down_p(player)) nb++; if (nb >= 2) return (1); return (0); }
static void add_tree(t_op **tree, t_op *save) { t_op *tmp; tmp = NULL; if (!save) return ; if (!*tree) *tree = save; else { tmp = *tree; while (!save->top) { if (save->nbr < tmp->nbr) check_right(&tmp, &save); else check_left(&tmp, &save); } } }
int verify_playable(char** map, int x, int y, int player) { if (map[y][x] != 0) return -1; if (check_top(map, x, y, player) == 0) return 0; if (check_bottom(map, x, y, player) == 0) return 0; if (check_left(map, x, y, player) == 0) return 0; if (check_right(map, x, y, player) == 0) return 0; if (check_top_left(map, x, y, player) == 0) return 0; if (check_top_right(map, x, y, player) == 0) return 0; if (check_bottom_left(map, x, y, player) == 0) return 0; if (check_bottom_right(map, x, y, player) == 0) return 0; return -1; }
t_map *check_right(t_map *map) { t_map *head; int rec; head = map; rec = 0; while (head && (head->y == map->y) && (head->prev && head->prev->y == map->y)) { head = head->prev; if (head && (head->value == map->value) && !head->lock) { head = add_val(head, map->position, (head->value + map->value)); head = add_val(head, head->position, -1); rec = 1; break; } else if (head && (((head->value != map->value) && (head->value != -1)) || (head->value == map->value && head->lock))) break; } return (rec ? check_right(map) : map); }
int check_axe(t_terrain* button, t_terrain* terrain) { if (check_left(button, terrain)) { move_left(button, terrain); return (1); } else if (check_right(button, terrain)) { move_right(button, terrain); return (1); } else if (check_top(button, terrain)) { move_top(button, terrain); return (1); } else if (check_bot(button, terrain)) { move_bot(button, terrain); return (1); } return (0); }
void ft_changedirectory(t_data *data, char **args) { char *env_pwd; char *path; env_pwd = ft_strjoin(get_var_env(data, "PWD="), "/"); if (args[1] && ft_strcmp(args[1], "-") == 0) ft_change_part2(env_pwd, data); else if (args[1]) { path = ft_strjoin(env_pwd, args[1]); check_right(&path, args, data); change_pwd(data, "OLD"); path = (args[1][0] == '/' ? args[1] : path); chdir(path); } else { path = get_var_env(data, "HOME="); change_pwd(data, "OLD"); chdir(path); } free(env_pwd); }
int check_jump_movement_ok(int j,int k,int m,int n) { int count=0; int ok=0; if( check_up(j,k)==2 && check_up(j,k-1)==0) { jump_loc[count][0]=j; jump_loc[count][1]=k-2; if(jump_loc[count][0]==m && jump_loc[count][1]==n) ok=1; count++; } if( check_down(j,k)==2 && check_down(j,k+1)==0) { jump_loc[count][0]=j; jump_loc[count][1]=k+2; if(jump_loc[count][0]==m && jump_loc[count][1]==n) ok=1; count++; } if( check_left(j,k)==2 && check_left(j-1,k)==0) { jump_loc[count][0]=j-2; jump_loc[count][1]=k; if(jump_loc[count][0]==m && jump_loc[count][1]==n) ok=1; count++; } if( check_right(j,k)==2 && check_right(j+1,k)==0) { jump_loc[count][0]=j+2; jump_loc[count][1]=k; if(jump_loc[count][0]==m && jump_loc[count][1]==n) ok=1; count++; } if((j+k)%2==0) { if( check_up_left(j,k)==2 && check_up_left(j-1,k-1)==0) { jump_loc[count][0]=j-2; jump_loc[count][1]=k-2; if(jump_loc[count][0]==m && jump_loc[count][1]==n) ok=1; count++; } if( check_up_right(j,k)==2 && check_up_right(j+1,k-1)==0) { jump_loc[count][0]=j+2; jump_loc[count][1]=k-2; if(jump_loc[count][0]==m && jump_loc[count][1]==n) ok=1; count++; } if( check_down_left(j,k)==2 && check_down_left(j+1,k+1)==0) { jump_loc[count][0]=j+2; jump_loc[count][1]=k+2; if(jump_loc[count][0]==m && jump_loc[count][1]==n) ok=1; count++; } if( check_down_right(j,k)==2 && check_down_right(j-1,k+1)==0) { jump_loc[count][0]=j-2; jump_loc[count][1]=k+2; if(jump_loc[count][0]==m && jump_loc[count][1]==n) ok=1; count++; } } return ok; }
int check_movement_ok(int j,int k,int m,int n) { int count=0; int ok=0; if( check_up(j,k)==0) { move_loc[count][0]=j; move_loc[count][1]=k-1; if(move_loc[count][0]==m && move_loc[count][1]==n) ok=1; count++; } if( check_down(j,k)==0) { move_loc[count][0]=j; move_loc[count][1]=k+1; if(move_loc[count][0]==m && move_loc[count][1]==n) ok=1; count++; } if( check_left(j,k)==0) { move_loc[count][0]=j-1; move_loc[count][1]=k; if(move_loc[count][0]==m && move_loc[count][1]==n) ok=1; count++; } if( check_right(j,k)==0) { move_loc[count][0]=j+1; move_loc[count][1]=k; if(move_loc[count][0]==m && move_loc[count][1]==n) ok=1; count++; } if((j+k)%2==0) { if( check_up_left(j,k)==0) { move_loc[count][0]=j-1; move_loc[count][1]=k-1; if(move_loc[count][0]==m && move_loc[count][1]==n) ok=1; count++; } if( check_up_right(j,k)==0) { move_loc[count][0]=j+1; move_loc[count][1]=k-1; if(move_loc[count][0]==m && move_loc[count][1]==n) ok=1; count++; } if( check_down_left(j,k)==0) { move_loc[count][0]=j+1; move_loc[count][1]=k+1; if(move_loc[count][0]==m && move_loc[count][1]==n) ok=1; count++; } if( check_down_right(j,k)==0) { move_loc[count][0]=j-1; move_loc[count][1]=k+1; if(move_loc[count][0]==m && move_loc[count][1]==n) ok=1; count++; } } return ok; }
int check_possible_jump_movement(int j,int k) { int count=0; if( check_up(j,k)==2 && check_up(j,k-1)==0) { jump_loc[count][0]=j; jump_loc[count][1]=k-2; // draw_target(jump_loc[count][0],jump_loc[count][1]); count++; } if( check_down(j,k)==2 && check_down(j,k+1)==0) { jump_loc[count][0]=j; jump_loc[count][1]=k+2; // draw_target(jump_loc[count][0],jump_loc[count][1]); count++; } if( check_left(j,k)==2 && check_left(j-1,k)==0) { jump_loc[count][0]=j-2; jump_loc[count][1]=k; // draw_target(jump_loc[count][0],jump_loc[count][1]); count++; } if( check_right(j,k)==2 && check_right(j+1,k)==0) { jump_loc[count][0]=j+2; jump_loc[count][1]=k; // draw_target(jump_loc[count][0],jump_loc[count][1]); count++; } if((j+k)%2==0) { if( check_up_left(j,k)==2 && check_up_left(j-1,k-1)==0) { jump_loc[count][0]=j-2; jump_loc[count][1]=k-2; //draw_target(jump_loc[count][0],jump_loc[count][1]); count++; } if( check_up_right(j,k)==2 && check_up_right(j+1,k-1)==0) { jump_loc[count][0]=j+2; jump_loc[count][1]=k-2; // draw_target(jump_loc[count][0],jump_loc[count][1]); count++; } if( check_down_left(j,k)==2 && check_down_left(j+1,k+1)==0) { jump_loc[count][0]=j+2; jump_loc[count][1]=k+2; // draw_target(jump_loc[count][0],jump_loc[count][1]); count++; } if( check_down_right(j,k)==2 && check_down_right(j-1,k+1)==0) { jump_loc[count][0]=j-2; jump_loc[count][1]=k+2; // draw_target(jump_loc[count][0],jump_loc[count][1]); count++; } } return count; }
static int test_traverse(struct stringmap *map, struct test_entry *strings, size_t size, FILE *out) { size_t sp = 0; size_t stack_alloc = 16; struct stringmap_node **stack = NULL; struct stringmap_node *n; void *leaf; #define check(lri) do { \ leaf = n->lr[lri]; \ if (!size--) \ err("Fewer items in tree than counted"); \ if (tecmp(leaf, strings++)) \ err("%s leaf has incorrect string", lri ? "Left" : "Right"); \ } while(0) #define check_left() check(0) #define check_right() check(1) if (map->count != size) err("map->count != size"); if (map->count == 0) return 1; if (map->count == 1) { leaf = (struct test_entry*)map->root; if (!tecmp(leaf, &strings[0])) return 1; else err("Only leaf in tree has incorrect value"); } stack = malloc(sizeof(*stack) * stack_alloc); n = map->root; for (;;) { //descend left while (!n->left_is_leaf) { stack[sp++] = n; n = n->lr[0]; if (sp >= stack_alloc) { stack_alloc += stack_alloc; stack = realloc(stack, sizeof(*stack) * stack_alloc); } } check_left(); ascend_right: while (n->right_is_leaf) { check_right(); if (!sp) goto done; //we finished up the last entry n = stack[--sp]; } //descend right n = n->lr[1]; while (n->left_is_leaf) { check_left(); if (n->right_is_leaf) { check_right(); if (!sp) goto done; n = stack[--sp]; goto ascend_right; //sorry } n = n->lr[1]; } } done: if (size != 0) err("More items in tree than counted"); free(stack); return 1; fail: if (stack) free(stack); return 0; #undef check #undef check_left #undef check_right }
int check_possible_movement(int j,int k) { int count=0; if( check_up(j,k)==0) { move_loc[count][0]=j; move_loc[count][1]=k-1; // draw_target(move_loc[count][0],move_loc[count][1]); count++; } if( check_down(j,k)==0) { move_loc[count][0]=j; move_loc[count][1]=k+1; // draw_target(move_loc[count][0],move_loc[count][1]); count++; } if( check_left(j,k)==0) { move_loc[count][0]=j-1; move_loc[count][1]=k; // draw_target(move_loc[count][0],move_loc[count][1]); count++; } if( check_right(j,k)==0) { move_loc[count][0]=j+1; move_loc[count][1]=k; //draw_target(move_loc[count][0],move_loc[count][1]); count++; } if((j+k)%2==0) { if( check_up_left(j,k)==0) { move_loc[count][0]=j-1; move_loc[count][1]=k-1; // draw_target(move_loc[count][0],move_loc[count][1]); count++; } if( check_up_right(j,k)==0) { move_loc[count][0]=j+1; move_loc[count][1]=k-1; // draw_target(move_loc[count][0],move_loc[count][1]); count++; } if( check_down_left(j,k)==0) { move_loc[count][0]=j+1; move_loc[count][1]=k+1; // draw_target(move_loc[count][0],move_loc[count][1]); count++; } if( check_down_right(j,k)==0) { move_loc[count][0]=j-1; move_loc[count][1]=k+1; // draw_target(move_loc[count][0],move_loc[count][1]); count++; } } return count; }