diff --git a/inc/fillit.h b/inc/fillit.h index 91297f0..984525d 100644 --- a/inc/fillit.h +++ b/inc/fillit.h @@ -72,7 +72,7 @@ char **glue_figure(char **table); void move_up_left(char **table); // print table returned by glue_figure() -void print_one_string(char **glued); +void print_one_string(t_ttrmn ttr); // compare 19 templates with each tetromino in *ttr table void test_check(char **ttr, t_ttrmn *tamplates); diff --git a/src/main.c b/src/main.c index 2db37a6..9b2a4fd 100644 --- a/src/main.c +++ b/src/main.c @@ -12,85 +12,31 @@ #include "fillit.h" -// bad global variable +/* +** bad global variable +*/ + t_ttrmn g_templates[19] = { - { - "#...#...#...#...", 1, 4, .c[0] = {0, 0}, .c[1] = {1, 0}, - .c[2] = {2, 0}, .c[3] = {3, 0} - }, - - { .t = "####............", - .x = 4, - .y = 1}, - - { .t = "#...#...##......", - .x = 2, - .y = 3}, - - { .t = "..#.###.........", - .x = 3, - .y = 2}, - - { .t = "##...#...#......", - .x = 2, - .y = 3}, - - { .t = "###.#...........", - .x = 3, - .y = 2}, - - { .t = ".#...#..##......", - .x = 2, - .y = 3}, - - { .t = "###...#.........", - .x = 3, - .y = 2}, - - { .t = "##..#...#.......", - .x = 2, - .y = 3}, - - { .t = "#...###.........", - .x = 3, - .y = 2}, - - { .t = "###..#..........", - .x = 3, - .y = 2}, - - { .t = "#...##..#.......", - .x = 2, - .y = 3}, - - { .t = ".#..###.........", - .x = 3, - .y = 2}, - - { .t = ".#..##...#......", - .x = 2, - .y = 3}, - - { .t = "##..##..........", - .x = 2, - .y = 2}, - - { .t = "##...##.........", - .x = 3, - .y = 2}, - - { .t = ".#..##..#.......", - .x = 2, - .y = 3}, - - { .t = ".##.##..........", - .x = 3, - .y = 2}, - - { .t = "#...##...#......", - .x = 2, - .y = 3} + {"#...#...#...#...", 1, 4, {{0, 0}, {1, 0}, {2, 0}, {3, 0}}}, + {"####............", 4, 1, {{0, 0}, {0, 1}, {0, 2}, {0, 3}}}, + {"#...#...##......", 2, 3, {{0, 0}, {1, 0}, {2, 0}, {2, 1}}}, + {"..#.###.........", 3, 2, {{0, 2}, {1, 0}, {1, 1}, {1, 2}}}, + {"##...#...#......", 2, 3, {{0, 0}, {0, 1}, {1, 1}, {2, 1}}}, + {"###.#...........", 3, 2, {{0, 0}, {0, 1}, {0, 2}, {1, 0}}}, + {".#...#..##......", 2, 3, {{0, 1}, {1, 1}, {2, 0}, {2, 1}}}, + {"###...#.........", 3, 2, {{0, 0}, {0, 1}, {0, 2}, {1, 2}}}, + {"##..#...#.......", 2, 3, {{0, 0}, {0, 1}, {1, 0}, {2, 0}}}, + {"#...###.........", 3, 2, {{0, 0}, {1, 0}, {1, 1}, {1, 2}}}, + {"###..#..........", 3, 2, {{0, 0}, {0, 1}, {0, 2}, {1, 2}}}, + {"#...##..#.......", 2, 3, {{0, 0}, {1, 0}, {1, 1}, {2, 0}}}, + {".#..###.........", 3, 2, {{0, 1}, {1, 0}, {1, 1}, {1, 2}}}, + {".#..##...#......", 2, 3, {{0, 1}, {1, 0}, {1, 1}, {2, 1}}}, + {"##..##..........", 2, 2, {{0, 0}, {0, 1}, {1, 0}, {1, 1}}}, + {"##...##.........", 3, 2, {{0, 0}, {0, 1}, {1, 1}, {1, 2}}}, + {".#..##..#.......", 2, 3, {{0, 1}, {1, 0}, {1, 1}, {2, 0}}}, + {".##.##..........", 3, 2, {{0, 1}, {0, 2}, {1, 0}, {1, 2}}}, + {"#...##...#......", 2, 3, {{0, 0}, {1, 0}, {1, 1}, {2, 1}}} }; int main(int argc, char **argv) @@ -99,7 +45,7 @@ int main(int argc, char **argv) char **table; char **ttr; int i; - int *types; + //int *types; i = 0; if (argc != 2) @@ -127,10 +73,12 @@ int main(int argc, char **argv) //printf("test check:\n\n"); //test_check(ttr, templates); - - types = to_strct_array(ttr, g_templates); - + while (i < 19) + { + print_one_string(g_templates[i]); + i++; + } //printf("%s\n %d, %d", strct_ttr[0]->t, strct_ttr[0]->x, strct_ttr[0]->y); //to_letters(ttr); //printf("to latters:\n\n"); diff --git a/src/test!_print_one_string.c b/src/test!_print_one_string.c index d7baab5..a146345 100644 --- a/src/test!_print_one_string.c +++ b/src/test!_print_one_string.c @@ -13,23 +13,19 @@ #include "fillit.h" // Test func. Print table but one string contain whole figure. -void print_one_string(char **glued) +void print_one_string(t_ttrmn ttr) { int i; - int j; i = 0; - while (glued[i]) + while (ttr.t[i]) { - j = 0; - while (glued[i][j]) - { - ft_putchar(glued[i][j]); - if ((j + 1) % 4 == 0) - ft_putchar('\n'); - j++; - } - ft_putstr("\n"); + ft_putchar(ttr.t[i]); + if ((i + 1) % 4 == 0) + ft_putchar('\n'); i++; } + printf("x = %d, y = %d\n", ttr.x, ttr.y); + printf("x1[%d] y1[%d]\nx2[%d] y2[%d]\nx3[%d] y3[%d]\nx4[%d] y4[%d]\n", ttr.c[0].x, ttr.c[0].y, ttr.c[1].x, ttr.c[1].y, ttr.c[2].x, ttr.c[2].y, ttr.c[3].x, ttr.c[3].y); + ft_putstr("\n"); } \ No newline at end of file diff --git a/src/to_strct_array.c b/src/to_strct_array.c index 11cebdb..68ef8d2 100644 --- a/src/to_strct_array.c +++ b/src/to_strct_array.c @@ -1,7 +1,7 @@ #include "fillit.h" -t_ttrmn **to_strct_array(char **ttr, t_ttrmn *templates) +int *to_strct_array(char **ttr, t_ttrmn *templates) { t_ttrmn **ret; int amount; @@ -29,5 +29,5 @@ t_ttrmn **to_strct_array(char **ttr, t_ttrmn *templates) ret[i]->y = templates[j].y; i++; } - return (ret); + return (0); } \ No newline at end of file