resolu erreurs de tetra horizontal et vire les coordonnes en plus de tab

This commit is contained in:
Hugo LAMY
2019-04-15 17:08:06 +02:00
parent baa1a3de67
commit 92815d1928
3 changed files with 10 additions and 18 deletions

BIN
a.out

Binary file not shown.

View File

@@ -6,14 +6,14 @@
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */ /* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/14 15:20:53 by hulamy #+# #+# */ /* Created: 2019/04/14 15:20:53 by hulamy #+# #+# */
/* Updated: 2019/04/15 16:14:46 by hulamy ### ########.fr */ /* Updated: 2019/04/15 17:07:34 by hulamy ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
#include "fillit.h" #include "fillit.h"
#include <stdio.h> #include <stdio.h>
char **fill_tetraminos(char **square, int x1, int y1, int x2, int y2) char **fill_tetraminos(char **square, int *tab)
{ {
char **result; char **result;
int height; int height;
@@ -22,11 +22,11 @@ char **fill_tetraminos(char **square, int x1, int y1, int x2, int y2)
int j; int j;
i = 0; i = 0;
height = x2 - x1 + 1; height = tab[2] - tab[0] + 1;
length = y2 - y1 + 1; length = tab[3] - tab[1] + 1;
if (!(result = (char**)malloc(sizeof(*result) * (height + 1)))) if (!(result = (char**)malloc(sizeof(*result) * (height))))
return (NULL); return (NULL);
while (i < 4) while (i < height)
{ {
if (!(result[i] = (char*)malloc(sizeof(**result) * (length + 1)))) if (!(result[i] = (char*)malloc(sizeof(**result) * (length + 1))))
return (NULL); return (NULL);
@@ -36,7 +36,7 @@ char **fill_tetraminos(char **square, int x1, int y1, int x2, int y2)
i = -1; i = -1;
while (++i < height && (j = -1)) while (++i < height && (j = -1))
while (++j < length) while (++j < length)
result[i][j] = square[x1 + i][y1 + j]; result[i][j] = square[tab[0] + i][tab[1] + j];
return (result); return (result);
} }
@@ -69,21 +69,13 @@ void find_start_and_end(char **square, int **x)
int fill_list(char **square, t_fillist *list) int fill_list(char **square, t_fillist *list)
{ {
int *tab; int *tab;
int x1;
int x2;
int y1;
int y2;
tab = (int*)malloc(sizeof(int) * 4); tab = (int*)malloc(sizeof(int) * 4);
find_start_and_end(square, &tab); find_start_and_end(square, &tab);
x1 = tab[0]; list->size[0] = tab[3] - tab[1] + 1;
y1 = tab[1]; list->size[1] = tab[2] - tab[0] + 1;
x2 = tab[2];
y2 = tab[3];
list->size[0] = y2 - y1 + 1;
list->size[1] = x2 - x1 + 1;
list->area = list->size[0] * list->size[1]; list->area = list->size[0] * list->size[1];
list->tetraminos = fill_tetraminos(square, x1, y1, x2, y2); list->tetraminos = fill_tetraminos(square, tab);
return (1); return (1);
} }