static int ft_move_up(size_t *map, size_t size) { int i[4]; i[2] = size * size; i[0] = 0; i[3] = 0; while (i[0] < i[2]) { if (!ft_is_empty(map[i[0]])) { i[1] = i[0] % size; while (i[1] < i[0]) { if (ft_is_empty(map[i[1]])) { map[i[1]] = map[i[0]]; map[i[0]] = 0; i[3]++; break ; } i[1] += size; } } i[0]++; } return (i[3]); }
int ft_up(t_game *g) { int i[4]; i[2] = g->size * g->size; i[0] = 0; i[3] = 0; while (i[0] < i[2]) { if (!ft_is_empty(g->map[i[0]])) { i[1] = i[0] + g->size; while (i[1] < i[2]) { if (!ft_is_empty(g->map[i[1]])) { if (g->map[i[0]] == g->map[i[1]]) ft_add(g, i); break ; } i[1] += g->size; } } i[0]++; } return (ft_move_up(g->map, g->size) + i[3]); }
void ft_rand(t_game *g) { size_t i; i = 0; while (!ft_is_empty(g->map[i]) && i < (g->size * g->size)) i++; if (i < (g->size * g->size)) { i = rand() % (g->size * g->size); while (!ft_is_empty(g->map[i])) i = rand() % (g->size * g->size); g->map[i] = (rand() % g->size) ? 2 : 4; } }
char *ft_strtrim(char const *s) { char *copy; size_t i; size_t j; size_t k; if (ft_is_empty(s)) return (""); if (s == NULL) return (NULL); i = 0; j = 0; k = 0; while (s[i] == ' ' || s[i] == '\n' || s[i] == '\t') i++; j = ft_strlen(s) - 1; while (s[j] == ' ' || s[j] == '\n' || s[j] == '\t' || s[j] == '\0') j--; if (!(copy = (char *)malloc(sizeof(char) * (j - i + 2)))) return (NULL); while (i <= j) copy[k++] = s[i++]; copy[k] = '\0'; return (copy); }
int ft_strlen(char *str) { int i; int str_len; i = 0; str_len = 0; while (str[i]) { if (!(ft_is_empty(str[i + 1])) && ft_is_empty(str[i])) { str_len++; } i++; } return (str_len); }
void ft_size_tab(char *str, char **tab) { int i; int j; int k; i = 0; j = 0; k = 0; while (str[i]) { if (ft_is_empty(str[i]) && !(ft_is_empty(str[i + 1]))) { tab[k] = (char *)malloc(sizeof(char) * j + 1); j = -1; k++; } i++; j++; } }
void ft_filltab(char **tab, char *str, int i, int j) { int k; k = 0; while (str[i]) { if (k < ft_strlen(str) && ft_is_empty(str[i])) { while (ft_is_empty(str[i])) { tab[k][j] = str[i]; i++; j++; } tab[k][j] = '\0'; k++; j = 0; } else if (k >= ft_strlen(str)) tab[k] = 0; i++; } }