int ft_resolution(char **tab, char ***grid, int side, int i) { t_coords tyx; if (tab[i] == NULL) return (1); tyx.y = 0; tyx.x = 0; ft_coords(&(tyx.ty), tab[i], 0); ft_coords(&(tyx.tx), tab[i], 1); while (tyx.y < side) { if (ft_validposition(side, &tyx, grid)) { ft_place(grid, tyx, i, 'A'); if (ft_resolution(tab, grid, side, (i + 1))) return (1); else ft_place(grid, tyx, 0, '.'); } tyx.x++; ft_annex(&tyx, side); } return (0); }
int ft_resolve(t_coord *cd, t_etri *tetri) { t_int *pmap; pmap = (t_int *)malloc(sizeof(t_int)); pmap->k = 0; if (tetri == NULL) return (1); pmap->i = 0; while (pmap->i + LEN <= COTE) { pmap->j = 0; while (pmap->j + LAR <= COTE) { if (ft_check_tetri(cd, tetri, pmap) == 1) { if (ft_resolve(cd, NEXT) == 1) return (1); else ft_place(cd, tetri, '.', pmap); } pmap->j++; } pmap->i++; } free(pmap); return (0); }
int ft_treatment(char **ptr_map, char ptr_map_saved[16][16], char order_figure[27], int i) { int pos[3]; int end; end = 0; pos[0] = 0; pos[1] = 0; pos[2] = ft_len(ptr_map); if (ft_place(ptr_map, order_figure[i], ((char)i + 64), pos)) { if (i == order_figure[0]) { end = ft_save(ptr_map, ptr_map_saved, pos[2], order_figure[0]); } else { while (!end) { end = ft_treatment(ptr_map, ptr_map_saved, order_figure, (i + 1)); if (end < 26 && end >= 0) { if (!ft_deplace(ptr_map, order_figure[i], (i + 64), pos)) { ft_del(ptr_map, (i + 64), pos[2]); end = 1; } } } } } else return (0); return (end - 1); }
static int ft_try(t_tetros *tetro, char **map, int size) { if (tetro != NULL) { while (tetro->x * tetro->y < size * size) { if ((ft_can_place(tetro, map, size)) == 1) { map = ft_place(tetro, map); if ((ft_try(tetro->next, map, size)) == 1) return (1); map = ft_delete_tetro(tetro, map, size); } if (tetro->x < size) tetro->x++; else { tetro->y++; tetro->x = 0; } } tetro->y = 0; tetro->x = 0; return (0); } return (1); }
int ft_deplace(char **map, char figure, char letter, int tab[3]) { ft_del(map, letter, tab[2]); if (tab[1] < tab[2] - 1) tab[1] += 1; else if (tab[0] < tab[2] - 1) { tab[0]++; tab[1] = 0; } else return (0); return (ft_place(map, figure, letter, tab)); }
int ft_check_tetri(t_coord *cd, t_etri *tetri, t_int *pmap) { Y_P = 0; while (Y_P < LEN) { X_P = 0; while (X_P < LAR) { if (TETRI[Y_P][X_P] == '#' && MAP[NEWYM][NEWXM] != '.') return (0); X_P++; } Y_P++; } ft_place(cd, tetri, LET, pmap); return (1); }