static t_room *can_move(t_room *pos, t_room *prev, t_pipe *pipes) { t_room *res; if (pos->property == END) return (NULL); if ((res = end_near(pipes, pos))) return (res); while (pipes) { if (pos == pipes->room1 && (res = test_room(pipes->room2, pos, prev))) return (res); if (pos == pipes->room2 && (res = test_room(pipes->room1, pos, prev))) return (res); pipes = pipes->next; } return (NULL); }
static int matrice_visit0(t_lem_env *env, int *i, int *j, int *k) { if (env->r.start == 0 || env->r.end == 0) return (ft_error(env, 1)); if (env->r.state == 1) { env->room = ft_strsplit(env->str, '\n'); room_swap(env); if (test_room(env) == 0) return (ft_error(env, 1)); matrice_init(env); matrice_zero(env); visit_init(env); } *i = 0; *j = -1; *k = -1; return (1); }
char *get_rooms(t_env *e, t_list **map) { char *buf; if ((e->ends = (t_list **)ft_memalloc(sizeof(t_list *) * 2)) == NULL) error("L'allocation de Start et End a echouee", e->param); while (get_next_line(0, &buf) == 1) { if (buf[0] != '#' && test_room(buf, e->room)) break ; if (buf[0] != '#') ft_lstadd(&e->room, create_room(buf, e)); if (ft_strequ(buf, "##start") || ft_strequ(buf, "##end")) get_comm_rooms(e, &buf, map); if (*map) ft_lstaddl(map, ft_lstnew(buf, ft_strlen(buf) + 1)); free(buf); } if (!e->ends[0] || !e->ends[1]) error("##start et/ou ##end non declare", e->param); return (buf); }
static int get_comm_rooms(t_env *e, char **buf, t_list **map) { int comm; if (*map) ft_lstaddl(map, ft_lstnew(*buf, ft_strlen(*buf) + 1)); comm = ft_strequ(*buf, "##end"); if (e->ends[comm]) error(ft_strjoin("Double declaration de ", *buf), e->param); free(*buf); while (get_next_line(0, buf) == 1) { if (ft_strequ(*buf, "##start") || ft_strequ(*buf, "##end")) error(ft_strjoin(*buf, " : commande invalide"), e->param); if ((*buf)[0] != '#') break ; free(*buf); } if (test_room(*buf, e->room)) error(ft_strjoin(*buf, " non valide"), e->param); ft_lstadd(&e->room, create_room(*buf, e)); e->ends[comm] = e->room; return (0); }