add new format for ttrmn templates

This commit is contained in:
Gregory Tertyshny 2016-12-20 20:32:30 +02:00
parent 9f78ae5810
commit d71477fa7c
4 changed files with 40 additions and 96 deletions

View file

@ -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);

View file

@ -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)
@ -128,9 +74,11 @@ 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");

View file

@ -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(ttr.t[i]);
if ((i + 1) % 4 == 0)
ft_putchar('\n');
j++;
}
ft_putstr("\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");
}

View file

@ -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);
}