diff --git a/fillit.c b/fillit.c new file mode 100644 index 0000000..b75598a --- /dev/null +++ b/fillit.c @@ -0,0 +1,43 @@ +#include "fillit.h" + +unsigned int ft_sqrt_ceil(unsigned int num) +{ + int i; + + i = 1; + while (i * i < num) + i++; + return (i); +} + +void clear_map(t_map *map) +{ + int i; + + i = 0; + while (i < 16) + map->line[i++] = 0; +} + +t_tetraminos *convert_tetramino(char *s) +{ + t_tetraminos *res; + + res = (t_tetraminos*)malloc(sizeof(t_tetraminos)); + return (res); +} + +t_map *map_initialization(char **tetramino_table) +{ + t_map *map; + unsigned int i; + + map = (t_map*)malloc(sizeof(t_map)); + i = 0; + while (*tetramino_table) + map->figure[i++] = convert_tetramino(*tetramino_table++); + map->figure_amount = i; + map->size = ft_sqrt_ceil(i * 4); + clear_map(map); + return (map); +} diff --git a/fillit.h b/fillit.h new file mode 100644 index 0000000..7cacc14 --- /dev/null +++ b/fillit.h @@ -0,0 +1,17 @@ +typedef struct s_tetraminos +{ + uint16_t line[16]; + int offset_y; +} t_tetraminos; + +typedef struct s_map +{ + uint16_t line[16]; + unsigned int size; + t_tetraminos *figure[26]; + unsigned int figure_amount; +} t_map; + +t_tetraminos *convert_tetramino(char *s); +t_map *map_initialization(char **tetramino_table); +