From b5f8e37699b20234f9a29cc748e1ffdbca80f240 Mon Sep 17 00:00:00 2001 From: Manzovince Date: Mon, 22 Apr 2019 15:14:20 +0200 Subject: [PATCH 01/13] Auto stash before merge of "master" and "origin/master" --- add_to_list.c | 11 +++++++++-- test_big_map.c | 9 ++------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/add_to_list.c b/add_to_list.c index 51c38dc..3630c81 100644 --- a/add_to_list.c +++ b/add_to_list.c @@ -6,7 +6,7 @@ /* By: hulamy +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/14 15:20:53 by hulamy #+# #+# */ -/* Updated: 2019/04/21 13:42:46 by hulamy ### ########.fr */ +/* Updated: 2019/04/22 15:12:47 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ @@ -80,6 +80,10 @@ int add_to_list(char *line, t_fillist **list) return (1); } +/* +** Print octet +*/ + void print_test(int octet) { unsigned int i; @@ -92,6 +96,10 @@ void print_test(int octet) } } +/* +** ??? +*/ + void test(unsigned int map[]) { int i; @@ -142,4 +150,3 @@ int main(int ac, char **av) return (0); } - diff --git a/test_big_map.c b/test_big_map.c index 05831ac..64a0982 100644 --- a/test_big_map.c +++ b/test_big_map.c @@ -83,13 +83,8 @@ int main() unsigned int map[10] = {1568713153, 817645681, 654186132, 538171355, 1718453135, 551286515, 1631843343, 3413834313, 1155555555, 999999999}; int i; - i = -1; - while (++i < 10) - { - print_bits(map[i]); - printf(" "); - } - printf("\n"); + //while (i < 10) + // printf("%d\n", map[i++]); test(map); return (0); } From 3f6f6f249a04cd0917a3a75c6fd2ca7c5a2f7db9 Mon Sep 17 00:00:00 2001 From: Manzovince Date: Mon, 22 Apr 2019 16:27:46 +0200 Subject: [PATCH 02/13] little mod (makefile + read_file) --- Makefile | 9 +++++---- read_file.c | 9 +++------ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 876fac0..eb91318 100644 --- a/Makefile +++ b/Makefile @@ -6,13 +6,13 @@ # By: vmanzoni +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2019/03/01 13:24:35 by vmanzoni #+# #+# # -# Updated: 2019/04/18 12:27:12 by vmanzoni ### ########.fr # +# Updated: 2019/04/22 15:32:49 by vmanzoni ### ########.fr # # # # **************************************************************************** # NAME = fillit -OBJ_DIR = objs./ +OBJ_DIR = ./objs HEADER = fillit.h SRCS = main.c \ @@ -20,7 +20,8 @@ SRCS = main.c \ handle_errors.c \ parse_input.c \ get_smallest_square.c \ - print_fillit.c + print_fillit.c \ + add_to_list.c OBJS = $(SRCS:.c=.o) LIB = libft/ @@ -33,7 +34,7 @@ RM = rm -rf all: $(NAME) $(NAME): - make -C libft/ + make -C $(LIB) $(CC) $(CFLAGS) -I$(HEADER) -c $(SRCS) $(CC) -o $(NAME) $(OBJS) -L $(LIB) -lft mkdir $(OBJ_DIR) diff --git a/read_file.c b/read_file.c index 0afb78c..72f1e58 100644 --- a/read_file.c +++ b/read_file.c @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/13 12:09:46 by vmanzoni #+# #+# */ -/* Updated: 2019/04/19 12:50:32 by hulamy ### ########.fr */ +/* Updated: 2019/04/22 15:16:18 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ @@ -29,12 +29,9 @@ char *read_file(char *file) || !(result = malloc(sizeof(char) * rv))) return (NULL); buf[rv] = '\0'; - i = 0; - while (buf[i]) - { + i = -1; + while (buf[++i]) result[i] = buf[i]; - i++; - } result[i] = '\0'; close(fd); return (result); From 704a47684d05c13bebe25fe0fa1f241650d2ef39 Mon Sep 17 00:00:00 2001 From: Manzovince Date: Mon, 22 Apr 2019 17:12:36 +0200 Subject: [PATCH 03/13] files cleaned (WORKING) --- .gitignore | 4 ++++ .parse_input.c.swo | Bin 12288 -> 0 bytes .parse_input.c.swp | Bin 12288 -> 0 bytes .test_big_map.c.swp | Bin 12288 -> 0 bytes .test_mask.c.swp | Bin 12288 -> 0 bytes add_to_list.c | 23 +++++++++++--------- fillit.h | 7 ++++-- main.c | 2 +- parse_input.c | 52 +++++++------------------------------------- 9 files changed, 31 insertions(+), 57 deletions(-) delete mode 100644 .parse_input.c.swo delete mode 100644 .parse_input.c.swp delete mode 100644 .test_big_map.c.swp delete mode 100644 .test_mask.c.swp diff --git a/.gitignore b/.gitignore index e525c97..862bf81 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,7 @@ objs/ a\.out\.dSYM/ a\.out + +*.swo + +*.swp diff --git a/.parse_input.c.swo b/.parse_input.c.swo deleted file mode 100644 index 90e58e08fc209bacee8a6c959b7789c93f1f66e1..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI2Piz!b9LFCTg;7wWBpSrz*EY1<-O|}9i_oQifLdZr1;m!bw78kh&a$t&ompny zw3G@&q9J-UBpygi^dJ}ihJz>v6A#8jjVCl7B_2I+^T5IHdo#1UMM4@RF(hxwhnacr z_kQzx-{0@Op<(9oM<-sUUHt`y;|aztU%E1TsBGW8 zX?n+im6xNtIy>m8C#UbikshKI&h{ig07QsJ|OkgQF zue;@(-0G87Kr5gX&D#xgy8Z2|LO1l zpFPgl>tGYO`WRz1um$|EiLsNQ2VC38*xTSO&;UNDgE6odjDk);;2H2VFu>oBGWH#~ z488?vlVBsbv4OGQ!8PzT_!xWyE`oQ!IdB%#00&j@5_l10 zz-F)k++2@Xz%}qQ_!L|O?}GE-3|IiKfMKu|{Pi$nKZ2{^5;zYyI0z1aF)#|QBY)q5 ztKdWM0eBO<1|~oOSU~0ZKCDw6vR2^#SK#z%X5f!e=b@lslBew>o_kX4L1QD}o~UFx zXT8o|dEac<7NV&yu@;>-m;S4{f?3Sv$?ouX~<1~~Qh5VE|V;$>d#tJi%e)Y`m zZpv^xdArq%&a4Tt)WG*tRCed0<9%e4TdCNN8;~7Q;CkgqnK&+;h&Y827ZkdIp!p~i zF0AcJg*#Q4BL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(h2qB0g!J-VVsED%^T`3)h zE4xEq1qjo=&m+c&VVk)k2DdD^=ptBkfDj9$^Ye6aDVjvEhTrXWMBI_ zN(1?fWd#ZI1?!}1nV&EiiG)|A?64$>lSb`HdGqKgIV_c=Q7q`XAM$Q9SDyE11B(g< z9pxf_FD?AZP;9$Q)-%r?J9)}mii#YKr&O&)XAVoi3R;sYqj~3wWy#)Rjd-Xmd<8jl z=HwhJFlk|AbCkhS6pYFoVvraRGNGm^*AH84AnY5wTWNE&rIqZ@=Wn;ebh+Azl znQ%Wbr&j$ijDv9m!M`zoku~Kp`>g1!QW=TMlgV_xLX%Ryl}XS zSLtwJ*u|$r*Q4#0GiSG4+j*EevtIj<=QwnEgXYJZD-+l2bv)s(x^OnS7%Lq22&0aTeZ7hm{YSX0S7#p5^6+MI*nJ4tM5b do0aF4F42+~#{ZYYZT{6`?r^v21T_tZ{{YvHOXC0l diff --git a/.test_big_map.c.swp b/.test_big_map.c.swp deleted file mode 100644 index e95f62a58530df7ed439eca78784d4bd191dc635..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI2O^6&t6vr##M@Ef`9>l2dvSG75JF_!W)6QPFsh=+T@0tGefF4GRG;k!twS-PQH+-oM^^ zwIQ?Fc=4%|biCGLxb9)h{rvLjPaZhPR!%b3&wO`yPJP(_63uuy;_X_iS?k67bbU3S zu-*%^I6ar14eJeOqbGe|ru9@L>Bgqq+8DY~&D&=Z^T{Y+6u5o`vb49YgX z=Z?^Q_r7rb^OzAv0i%FXz$jo8FbWt2i~>dhqreTTKpGujufh783J*4l`++_8;?>-Y z0!9I&fKk9GU=%P47zK<1MggOMQNSo*6u1EuaJ!7XehXs{-Uj3G|NoDU?m>+x%J_8rQ`(PeC1pdB*u|L3% z;7f1`NbnqZ8axgfpalN99X5mSz&GGMz`?~5M|Qloie9i4W$)9xJSHh1hQb@=gi3-7#2ZKuUMZEiQKItLCtE*&5nkTziF4Hkm)^D$ub+gTBY4TC&QL5MX%)uMiy0DZC z5)li6c6L(?1wmQrxXa(H;FxXN8%?OAgDi6nrSmb8Wu#xn`IJHud z#!`pgq+^k>qtx^(6{M!!Y#>_gCRLC!c#^M zB31H|5Ic|i%%0@|Iga@-Bk7X}RN7$qYj5YQuhFT2F0G}}_Ejo_QDvRl4OMS-QKDnV zXnSc%-7HnYmiTCMT=M#^a-fG~(4Oc$O5h<%O&;Y%UcgN3$T*>=Lb0k`L;xh2+(D`% zbKG7}BBG~Vhl5#w7FFb@4~1=7Ll{B$Z5XzUEgT&UD8IVis%pBtjt@GF(J3#uEnR(e zm2f7HZ3F=;>7YW?>Jb>Z=WIy^Y8e=cF8<_ks&#wPD%EkY6UuIW7EVv4i{3g8h{ZZv zTtoptt%&p5wB>m;`}6L+7S-x*EzBUJ3LMNDtAUo_o zSAqq6pNT70UmTxR5(gB@J=`c+p$8q1l(I~ZVgKMb4skwLrbota4V}`vk3*;(yk0^{WbOv DC*IAG diff --git a/.test_mask.c.swp b/.test_mask.c.swp deleted file mode 100644 index 6204ff16068b4fd788010eb44de9c61c630d9c7b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12288 zcmeI2Ply{;9LL`ZWgY8kRnY6Nu_lvgOlFeZWYgWO;z1A*|A1b)-DQ%@xGzp-!pxg3 zC0oUd;8p6WN5y*dq7)SMpm_5S9>g9+x*+yYXfJ}`_s!(b*i9BJMJT+$XWzfy{O0%j zzTbQ7vT2*IJ@*1N%F7I&V~l;&yu9gOS!C-M7~6?GyMInD9R6{t;p)JGk80Ts4>5f+ zby#tOI27l^*`Q*sY`fg^xTpvx65D+{dZXMq#DiK=3Md6`OMzIpPp&SpTGcY;^N;6_ z(<2YRdRwm4LrMXqfKosypcGIFCo_`aPrYH%INlE$wKi8l`|z zKq;UUPzopolmbctrGQdEDWDWk3Md8cLIvzDV;2`0D`*HF|NkHV{eSI2#{L99fgiwk z;4APY_yl|a-UAMJ1-t}a1UkrrW8kj`7~2O|!EfL*@IH7QG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019/04/22 15:12:47 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/22 15:58:39 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ #include "fillit.h" #include -#include "libft/includes/libft.h" +//#include "libft/includes/libft.h" /* ** this function prints a 16 bites short @@ -24,8 +24,8 @@ void print_bits(short line) mask = 1 << 27; while (mask >>= 1) - (line & mask) ? ft_putnbr(1) : ft_putnbr(0); - ft_putchar('\n'); + (line & mask) ? write(1, "1", 1) : write(1, "0", 1); + write(1, "\n", 1); } /* @@ -33,17 +33,19 @@ void print_bits(short line) ** then it fills it and its reverse into the list */ -int fill_list(char *line, t_fillist *list) +int fill_list(char line[], t_fillist *list) { short tmp; int test; + int i; - while (*line) + i = 0; + while (line[i]) { list->tetribit <<= 1; - if (*line == '\n') - line++; - if (*(line++) == '#') + if (line[i] == '\n') + i++; + if (line[i++] == '#') list->tetribit |= 1; } tmp = list->tetribit; @@ -128,7 +130,7 @@ void test(unsigned int map[]) mask = (mask >> 1) | (((1 << (i % 32)) & map[j]) << (31 - (i % 32))); } } - +/* int main(int ac, char **av) { static t_fillist *list = NULL; // avant d'appeller add_to_list il faut declarer un pointeur static vers la structure @@ -150,3 +152,4 @@ int main(int ac, char **av) return (0); } +*/ diff --git a/fillit.h b/fillit.h index 94895c2..7a60d6a 100644 --- a/fillit.h +++ b/fillit.h @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/03/01 13:34:46 by vmanzoni #+# #+# */ -/* Updated: 2019/04/19 14:52:10 by hulamy ### ########.fr */ +/* Updated: 2019/04/22 15:57:43 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,7 +20,9 @@ #include // for debug printf #include // to use bool type -# define BUFF_SIZE 1024 +#include "libft/includes/libft.h" + +//# define BUFF_SIZE 1024 /* ** STRUCTURE @@ -45,5 +47,6 @@ int check_file_errors(char *file); int check_tetri_errors(char *tetri); int check_tetri_errors2(char *tetri); int add_to_list(char *square, t_fillist **list); +int fill_list(char *line, t_fillist *list); #endif diff --git a/main.c b/main.c index d7dfc4b..47cdfd7 100644 --- a/main.c +++ b/main.c @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/02/12 13:20:48 by vmanzoni #+# #+# */ -/* Updated: 2019/04/16 16:41:28 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/22 15:50:16 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/parse_input.c b/parse_input.c index 9dbda39..4028264 100644 --- a/parse_input.c +++ b/parse_input.c @@ -6,28 +6,12 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/15 14:48:14 by vmanzoni #+# #+# */ -/* Updated: 2019/04/18 16:09:24 by vmanzoni ### ########.fr */ -/* Updated: 2019/04/19 12:53:40 by hulamy ### ########.fr */ +/* Updated: 2019/04/22 17:06:51 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ #include "fillit.h" -/* -** !!! DELETE PRINT_BITS BEFORE EVAL !!! -*/ - -void print_bits(short octet) -{ - int i; - - i = 1 << 16; - while (i >>= 1) - (octet & i) ? write(1, "1", 1) : write(1, "0", 1); - printf("\n"); -} - - /* ** Function that parse a file and put each tetrimino in a linked list */ @@ -56,25 +40,9 @@ char **create_square(char *tetri) return (square); } -short create_tetribit(char *tetri) -{ - short tetribit; - int i; - - i = 0; - tetribit = 0; - while (tetri[i]) - { - if (tetri[i] != '\n') // Pour comparer avec le tetri en char - printf("%c", tetri[i]); - if (tetri[i] == '#') - tetribit = tetribit | 1; - else - tetribit <<= 1; - i++; - } - return (tetribit); -} +/* +** Function that parse a file and put each tetrimino in a linked list +*/ void parse_input(char *input) { @@ -82,24 +50,18 @@ void parse_input(char *input) char tetri[20]; int i; int j; - short test; //DELETE BEFORE EVAL i = 0; - printf("input: %s\n", input); - printf("end\n"); while (input[i]) { j = 0; while (j < 19) tetri[j++] = input[i++]; tetri[19] = '\0'; + printf("%s\n", tetri); if (check_tetri_errors(tetri)) print_error("Error: Tetrimino not valid."); - test = create_tetribit(tetri); - printf("\n"); - print_bits(test); - //test = create_square(tetri); - //add_to_list(test, &list); + add_to_list(tetri, &list); while (input[i] == '\n') i++; } @@ -107,6 +69,7 @@ void parse_input(char *input) ** ce qui suit sert juste a afficher le contenu de tous les tetraminos de la liste chainee ** pour debug, a effacer au rendu */ + /* while (list && (i = -1)) { while (++i < list->size[1]) @@ -114,4 +77,5 @@ void parse_input(char *input) printf("\n"); list = list->next; } + */ } From 02159dc5871e739d38fc602924cf82f2a9110e34 Mon Sep 17 00:00:00 2001 From: Manzovince Date: Tue, 23 Apr 2019 15:19:30 +0200 Subject: [PATCH 04/13] get_smallest_square edited + initialize map added (WIP) --- get_smallest_square.c | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/get_smallest_square.c b/get_smallest_square.c index ad03c58..9ac5ca1 100644 --- a/get_smallest_square.c +++ b/get_smallest_square.c @@ -6,15 +6,37 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/12 22:29:45 by vmanzoni #+# #+# */ -/* Updated: 2019/04/14 21:37:19 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/23 14:34:32 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ #include "fillit.h" -/* -char *get_smallest_square() +unsigned int *initialize_map(int size) { + unsigned int *map[0]; + int i; + i = size; + while (size--) + map[i] = malloc(sizeof(unsigned int) * i); + return (map); +} + +int *get_smallest_square(t_fillist list, int size, unsigned int map[]) +{ + unsigned int mask; + int i; + int j; + + i = 0; + mask = map[size]; + while (list.tetribit != NULL) + { + mask = (mask >> 1) | (((1 << (i % 32)) & map[j]) << (31 - (i % 32))); + if (!(tetri & mask)) + return (1); + i++; + } + return (0); } -*/ From 6d093e66ccefe3914852b5787d4ef2aef7d98c73 Mon Sep 17 00:00:00 2001 From: Manzovince Date: Tue, 23 Apr 2019 15:19:53 +0200 Subject: [PATCH 05/13] handle_errors function name modified --- handle_errors.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/handle_errors.c b/handle_errors.c index 2f5a907..94d5932 100644 --- a/handle_errors.c +++ b/handle_errors.c @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/03/01 13:29:05 by vmanzoni #+# #+# */ -/* Updated: 2019/04/15 14:41:19 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/23 14:05:16 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ @@ -75,7 +75,7 @@ int check_tetri_errors(char *tetri) dot++; i++; } - if (htg != 4 || dot != 12 || check_tetri_errors2(tetri)) + if (htg != 4 || dot != 12 || check_tetri_errors_proxy(tetri)) return (1); return (0); } @@ -84,7 +84,7 @@ int check_tetri_errors(char *tetri) ** Function that check if tetrimino parts are linked */ -int check_tetri_errors2(char *tetri) +int check_tetri_errors_proxy(char *tetri) { int i; From b2d291603ca7d6102f5d03ea1e48e6ca5b35ff0d Mon Sep 17 00:00:00 2001 From: Manzovince Date: Tue, 23 Apr 2019 15:21:21 +0200 Subject: [PATCH 06/13] create_square comment modified --- parse_input.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/parse_input.c b/parse_input.c index 4028264..608e639 100644 --- a/parse_input.c +++ b/parse_input.c @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/15 14:48:14 by vmanzoni #+# #+# */ -/* Updated: 2019/04/22 17:06:51 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/23 15:18:00 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,6 +14,7 @@ /* ** Function that parse a file and put each tetrimino in a linked list +** DELETE BEFORE EVAL - NOT USED ANYMORE */ char **create_square(char *tetri) From d0de4dcb47ec08cd78e64d0f8e2c9c72ca0c32b1 Mon Sep 17 00:00:00 2001 From: Manzovince Date: Tue, 23 Apr 2019 15:25:23 +0200 Subject: [PATCH 07/13] comments modified --- parse_input.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/parse_input.c b/parse_input.c index 608e639..7209657 100644 --- a/parse_input.c +++ b/parse_input.c @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/15 14:48:14 by vmanzoni #+# #+# */ -/* Updated: 2019/04/23 15:18:00 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/23 15:24:46 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ @@ -66,10 +66,10 @@ void parse_input(char *input) while (input[i] == '\n') i++; } - /* - ** ce qui suit sert juste a afficher le contenu de tous les tetraminos de la liste chainee - ** pour debug, a effacer au rendu - */ +/* +** ce qui suit sert juste a afficher le contenu de tous les tetraminos de la liste chainee +** pour debug, a effacer au rendu +*/ /* while (list && (i = -1)) { From 952cc5bf222e9b1fe842c67b9661cbf4a42d82b3 Mon Sep 17 00:00:00 2001 From: Manzovince Date: Tue, 23 Apr 2019 15:25:23 +0200 Subject: [PATCH 08/13] create_square comments modified --- parse_input.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/parse_input.c b/parse_input.c index 608e639..7209657 100644 --- a/parse_input.c +++ b/parse_input.c @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/15 14:48:14 by vmanzoni #+# #+# */ -/* Updated: 2019/04/23 15:18:00 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/23 15:24:46 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ @@ -66,10 +66,10 @@ void parse_input(char *input) while (input[i] == '\n') i++; } - /* - ** ce qui suit sert juste a afficher le contenu de tous les tetraminos de la liste chainee - ** pour debug, a effacer au rendu - */ +/* +** ce qui suit sert juste a afficher le contenu de tous les tetraminos de la liste chainee +** pour debug, a effacer au rendu +*/ /* while (list && (i = -1)) { From acf5aed90e6db5f7f04e6aa029870fab031e1dba Mon Sep 17 00:00:00 2001 From: Manzovince Date: Tue, 23 Apr 2019 15:34:21 +0200 Subject: [PATCH 09/13] gitignore, makefile, .h edited --- .gitignore | 2 + Makefile | 9 +- fillit | Bin 13644 -> 0 bytes fillit.h | 10 +- test_fillit.c | 272 ++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 282 insertions(+), 11 deletions(-) delete mode 100755 fillit create mode 100644 test_fillit.c diff --git a/.gitignore b/.gitignore index 862bf81..a5cf236 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,5 @@ a\.out *.swo *.swp + +fillit diff --git a/Makefile b/Makefile index eb91318..6a9955a 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ # By: vmanzoni +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2019/03/01 13:24:35 by vmanzoni #+# #+# # -# Updated: 2019/04/22 15:32:49 by vmanzoni ### ########.fr # +# Updated: 2019/04/23 15:16:05 by vmanzoni ### ########.fr # # # # **************************************************************************** # @@ -19,9 +19,10 @@ SRCS = main.c \ read_file.c \ handle_errors.c \ parse_input.c \ - get_smallest_square.c \ - print_fillit.c \ - add_to_list.c + add_to_list.c \ +# get_smallest_square.c \ + print_fillit.c + OBJS = $(SRCS:.c=.o) LIB = libft/ diff --git a/fillit b/fillit deleted file mode 100755 index bd83e4664cda6bc6500306b7fc2675578ceea191..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 13644 zcmeHOeQX@X6`wm_l1pm34g{LEkQ{{2grtrW0)mjxb79j>!EhG{BW>qAy6stVC6mHI(HR05)v+d{CD5WA>qOywe1N}FrtB)f2}T=7vSL|lJw zW^TQAHdX)XAJvV#GxOe?dGkJI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oni #+# #+# */ -/* Updated: 2019/04/22 15:57:43 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/23 14:25:15 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,14 +16,10 @@ #include #include // for system call write #include // for system call open -#include // for memmove and strlen -#include // for debug printf -#include // to use bool type +#include // for printf (DELETE BEFORE EVAL) #include "libft/includes/libft.h" -//# define BUFF_SIZE 1024 - /* ** STRUCTURE */ @@ -45,7 +41,7 @@ void print_error(char *s); void parse_input(char *input); int check_file_errors(char *file); int check_tetri_errors(char *tetri); -int check_tetri_errors2(char *tetri); +int check_tetri_errors_proxy(char *tetri); int add_to_list(char *square, t_fillist **list); int fill_list(char *line, t_fillist *list); diff --git a/test_fillit.c b/test_fillit.c new file mode 100644 index 0000000..3704f2e --- /dev/null +++ b/test_fillit.c @@ -0,0 +1,272 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* test_fillit.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: vmanzoni +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/04/22 16:05:59 by vmanzoni #+# #+# */ +/* Updated: 2019/04/23 13:57:22 by vmanzoni ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include +#include // for system call write +#include // for system call open +#include // for memmove and strlen +#include // for debug printf +#include // to use bool type + +#include "libft/includes/libft.h" + +/* +** STRUCTURE +*/ + +typedef struct s_fillist +{ + int tetribit; + int position; + struct s_fillist *next; +} t_fillist; + +/* +** Function that display error message *s on fd and exit program +*/ + +void print_error(char *s) +{ + write(2, s, strlen(s)); + exit(1); +} + +/* +** Function that read file +*/ + +char *read_file(char *file) +{ + char buf[BUFF_SIZE]; + int fd; + int rv; + int i; + char *result; + + if (((fd = open(file, O_RDONLY)) < 0) \ + || ((rv = read(fd, &buf, BUFF_SIZE)) < 0) \ + || !(result = malloc(sizeof(char) * rv))) + return (NULL); + buf[rv] = '\0'; + i = -1; + while (buf[++i]) + result[i] = buf[i]; + result[i] = '\0'; + close(fd); + return (result); +} + +/* +** Function to see if there if an error if the file +** - less than 4 lines +** - more than 104 (26 tetri) + 25 (\n) = 129 lines +** - two \n in a row +*/ + +int check_file_errors(char *file) +{ + int i; + int line_nbr; + + i = 0; + line_nbr = 0; + while (file[i]) + { + if (file[i] != '.' && file[i] != '#' && file[i] != '\n') + return (1); + if (file[i] == '\n') + line_nbr++; + if (file[i] == '\n' && file[i+1] != '\0' && \ + file[i+2] != '.' && file[i+2] != '#') + return (1); + i++; + } + if (line_nbr < 4 || line_nbr > 129) + return (1); + return (0); +} + +/* +** Function that check if tetrimino parts are linked +*/ + +int check_tetri_errors2(char *tetri) +{ + int i; + + i = 0; + while (tetri[i]) + { + if (tetri[i] == '.' || tetri[i] == '\n') + i++; + else if (tetri[i] == '#' && (tetri[i + 1] == '#' || tetri[i - 1] == '#' + || tetri[i + 5] == '#' || tetri[i - 5] == '#')) + i++; + else + return (1); + } + return (0); +} + +/* +** Function that check if tetrimino square contains: +** - 4 '#' +** - 12 '.' +*/ + +int check_tetri_errors(char *tetri) +{ + int i; + int htg; + int dot; + + i = 0; + htg = 0; + dot = 0; + while (tetri[i]) + { + if (tetri[i] == '#') + htg++; + else if (tetri[i] == '.') + dot++; + i++; + } + if (htg != 4 || dot != 12 || check_tetri_errors2(tetri)) + return (1); + return (0); +} + +/* +** Function that take char * tetri and convert to short and put it in a list +*/ + +int fill_list(char *line, t_fillist *list) +{ + short tmp; + short tet; + int i; + + i = -1; + tet = 0; + while (line[++i]) + { + tet <<= 1; + if (line[i] == '\n') + i++; + if (line[i] == '#') + tet |= 1; + } + return (0); +} + +/* +** this function create the linked list and add a new structure linked each time needed +*/ + +int add_to_list(char *line, t_fillist **list) +{ + t_fillist *tmp; + + if (!(tmp = (t_fillist*)malloc(sizeof(*tmp)))) + return (0); + if (!(*list)) + tmp->next = NULL; + else + tmp->next = *list; + *list = tmp; + fill_list(line, *list); + return (1); +} + +/* +** Function that parse a file and put each tetrimino in a linked list +*/ + +int parse_input(char *input, t_fillist list) +{ + //static t_fillist *list = NULL; + static int size; + char tetri[20]; + int i; + int j; + + i = 0; + size = 0; + while (input[i]) + { + j = 0; + while (j < 19) + tetri[j++] = input[i++]; + tetri[19] = '\0'; + if (check_tetri_errors(tetri)) + print_error("Error: Tetrimino not valid."); + add_to_list(tetri, &list); + while (input[i] == '\n') + i++; + size++; + } + printf("%i\n", size); + return (size); +} + +/* ***************************************************************************** +** Function that brute force with backtracking for smallest square with tetris +***************************************************************************** */ + +int get_smallest_square(t_fillist list, int size, unsigned int map[]) +{ + unsigned int mask; + int i; + int j; + + i = 0; + j = 0; + mask = map[size]; + while (list.next != NULL) + { + mask = (mask >> 1) | (((1 << (i % 32)) & map[j]) << (31 - (i % 32))); + if (!(list.tetribit & mask)) + return (1); + i++; + } + return (0); +} + +/* ***************************************************************************** +** MAIN +***************************************************************************** */ + +int main(int argc, char **argv) +{ + char *input; + int map; + int size; + t_fillist list; + + if (argc == 2) + { + if (!(input = read_file(argv[1]))) + print_error("Error: Could not read file.\n"); + if (check_file_errors(input)) + print_error("Error: Invalid file.\n"); + size = parse_input(input, list); + get_smallest_square(list, size, map); + /* + Backtracking for smallest square + Transform tetriminos with letters + Print result + */ + } + else + print_error("Usage: Please submit a file.\n"); + return (0); +} From 21c10a57877812296634c4c33da94b30c5eac4e5 Mon Sep 17 00:00:00 2001 From: Manzovince Date: Tue, 23 Apr 2019 16:17:13 +0200 Subject: [PATCH 10/13] editing few files for readability --- add_to_list.c | 14 ++++----- parse_input.c | 78 ++++++++++++++++++++++++--------------------------- test_mask.c | 50 ++++++++++++++++----------------- 3 files changed, 69 insertions(+), 73 deletions(-) diff --git a/add_to_list.c b/add_to_list.c index 048db2a..9a0ad48 100644 --- a/add_to_list.c +++ b/add_to_list.c @@ -6,7 +6,7 @@ /* By: hulamy +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/14 15:20:53 by hulamy #+# #+# */ -/* Updated: 2019/04/22 15:58:39 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/23 16:15:10 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ @@ -36,7 +36,6 @@ void print_bits(short line) int fill_list(char line[], t_fillist *list) { short tmp; - int test; int i; i = 0; @@ -56,10 +55,6 @@ int fill_list(char line[], t_fillist *list) list->tibirtet <<= 1; tmp >>= 1; } - test = list->tibirtet; - print_bits(test); - while (test <<= 1) - print_bits(test); return (0); } @@ -99,7 +94,7 @@ void print_test(int octet) } /* -** ??? +** Test */ void test(unsigned int map[]) @@ -130,6 +125,11 @@ void test(unsigned int map[]) mask = (mask >> 1) | (((1 << (i % 32)) & map[j]) << (31 - (i % 32))); } } + +/* +** MAIN FOR TEST +*/ + /* int main(int ac, char **av) { diff --git a/parse_input.c b/parse_input.c index 7209657..8852298 100644 --- a/parse_input.c +++ b/parse_input.c @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/15 14:48:14 by vmanzoni #+# #+# */ -/* Updated: 2019/04/23 15:24:46 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/23 16:01:12 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,7 +14,43 @@ /* ** Function that parse a file and put each tetrimino in a linked list +*/ + +void parse_input(char *input) +{ + static t_fillist *list = NULL; + char tetri[20]; + int i; + int j; + + i = 0; + printf("%s", input); + while (input[i]) + { + j = 0; + while (j < 19) + tetri[j++] = input[i++]; + tetri[19] = '\0'; + if (check_tetri_errors(tetri)) + print_error("Error: Tetrimino not valid."); + add_to_list(tetri, &list); + while (input[i] && input[i] != '.' && input[i] != '#') + i++; + } + /*DEBUG PART - Print each tetribit*/ +/* + while (list != NULL) + { + printf("%i\n", list->tetribit); + printf("\n"); + list = list->next; + } +*/ +} + +/* ** DELETE BEFORE EVAL - NOT USED ANYMORE +** Function that parse a file and put each tetrimino in a linked list */ char **create_square(char *tetri) @@ -40,43 +76,3 @@ char **create_square(char *tetri) } return (square); } - -/* -** Function that parse a file and put each tetrimino in a linked list -*/ - -void parse_input(char *input) -{ - static t_fillist *list = NULL; - char tetri[20]; - int i; - int j; - - i = 0; - while (input[i]) - { - j = 0; - while (j < 19) - tetri[j++] = input[i++]; - tetri[19] = '\0'; - printf("%s\n", tetri); - if (check_tetri_errors(tetri)) - print_error("Error: Tetrimino not valid."); - add_to_list(tetri, &list); - while (input[i] == '\n') - i++; - } -/* -** ce qui suit sert juste a afficher le contenu de tous les tetraminos de la liste chainee -** pour debug, a effacer au rendu -*/ - /* - while (list && (i = -1)) - { - while (++i < list->size[1]) - printf("%s\n", list->tetraminos[i]); - printf("\n"); - list = list->next; - } - */ -} diff --git a/test_mask.c b/test_mask.c index c8d0d42..940fc6f 100644 --- a/test_mask.c +++ b/test_mask.c @@ -40,16 +40,16 @@ void compare(int initial, int compare) !(initial & compare) ? ft_putendl("&: fit") : ft_putendl("&: not fit"); /* -// j = 1 << 12; -// while (j >>= 1) -// (initial | compare) & j ? ft_putnbr(1) : ft_putnbr(0); -// ft_putchar('\n'); -// (initial | compare) ? ft_putendl("|: fit") : ft_putendl("|: not fit"); -// j = 1 << 12; -// while (j >>= 1) -// (initial ^ compare) & j ? ft_putnbr(1) : ft_putnbr(0); -// ft_putchar('\n'); -// (initial ^ compare) ? ft_putendl("^: fit") : ft_putendl("^: not fit"); + j = 1 << 12; + while (j >>= 1) + (initial | compare) & j ? ft_putnbr(1) : ft_putnbr(0); + ft_putchar('\n'); + (initial | compare) ? ft_putendl("|: fit") : ft_putendl("|: not fit"); + j = 1 << 12; + while (j >>= 1) + (initial ^ compare) & j ? ft_putnbr(1) : ft_putnbr(0); + ft_putchar('\n'); + (initial ^ compare) ? ft_putendl("^: fit") : ft_putendl("^: not fit"); */ } @@ -74,19 +74,19 @@ int main(int ac, char **av) } /* -**int main(int ac, char **av) -**{ -** int init; -** int mask; -** -** mask = (1 << 4); -** if (ac == 4) -** { -** ft_putendl(ft_convertbase(av[1], av[2], av[3])); -** ft_putnbrendl(init); -** init |= mask; -** ft_putnbrendl(init); -** } -** return (0); -**} +int main(int ac, char **av) +{ + int init; + int mask; + + mask = (1 << 4); + if (ac == 4) + { + ft_putendl(ft_convertbase(av[1], av[2], av[3])); + ft_putnbrendl(init); + init |= mask; + ft_putnbrendl(init); + } + return (0); +} */ From f4492e2735c3f02e65bab8ec872c68b76fd5377f Mon Sep 17 00:00:00 2001 From: Manzovince Date: Tue, 23 Apr 2019 21:15:12 +0200 Subject: [PATCH 11/13] Few edits + BUG found on add_to_list with some tetriminoes --- add_to_list.c | 12 ++++++++---- fillit.h | 2 +- get_smallest_square.c | 10 +++++++++- main.c | 2 +- parse_input.c | 3 ++- samples/2tetri | 9 +++++++++ samples/3tetri | 14 ++++++++++++++ samples/4tetri | 19 +++++++++++++++++++ samples/difficile_ou_pas | 2 +- samples/{one => test_bug} | 4 ++-- 10 files changed, 66 insertions(+), 11 deletions(-) create mode 100644 samples/2tetri create mode 100644 samples/3tetri create mode 100644 samples/4tetri rename samples/{one => test_bug} (50%) diff --git a/add_to_list.c b/add_to_list.c index 9a0ad48..fd7d130 100644 --- a/add_to_list.c +++ b/add_to_list.c @@ -6,7 +6,7 @@ /* By: hulamy +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/14 15:20:53 by hulamy #+# #+# */ -/* Updated: 2019/04/23 16:15:10 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/23 21:04:43 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,7 +15,8 @@ //#include "libft/includes/libft.h" /* -** this function prints a 16 bites short +** DELETE BEFORE EVAL - TEST FUNCTION +** Function that prints a 16 bites short */ void print_bits(short line) @@ -59,7 +60,8 @@ int fill_list(char line[], t_fillist *list) } /* -** this function create the linked list and add a new structure linked each time needed +** Function that create the linked list and add a new structure +** linked each time needed */ int add_to_list(char *line, t_fillist **list) @@ -78,6 +80,7 @@ int add_to_list(char *line, t_fillist **list) } /* +** DELETE BEFORE EVAL - TEST FUNCTION ** Print octet */ @@ -94,6 +97,7 @@ void print_test(int octet) } /* +** DELETE BEFORE EVAL - TEST FUNCTION ** Test */ @@ -127,7 +131,7 @@ void test(unsigned int map[]) } /* -** MAIN FOR TEST +** DELETE BEFORE EVAL - MAIN FOR TEST */ /* diff --git a/fillit.h b/fillit.h index c80544f..0fbd67c 100644 --- a/fillit.h +++ b/fillit.h @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/03/01 13:34:46 by vmanzoni #+# #+# */ -/* Updated: 2019/04/23 14:25:15 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/23 16:19:19 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/get_smallest_square.c b/get_smallest_square.c index 9ac5ca1..399d74e 100644 --- a/get_smallest_square.c +++ b/get_smallest_square.c @@ -6,12 +6,16 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/12 22:29:45 by vmanzoni #+# #+# */ -/* Updated: 2019/04/23 14:34:32 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/23 21:03:10 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ #include "fillit.h" +/* +** Function that initialize a int map equivalent to a square size*size +*/ + unsigned int *initialize_map(int size) { unsigned int *map[0]; @@ -23,6 +27,10 @@ unsigned int *initialize_map(int size) return (map); } +/* +** Function that bruteforce with backtracking for smallest square +*/ + int *get_smallest_square(t_fillist list, int size, unsigned int map[]) { unsigned int mask; diff --git a/main.c b/main.c index 47cdfd7..77afdd6 100644 --- a/main.c +++ b/main.c @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/02/12 13:20:48 by vmanzoni #+# #+# */ -/* Updated: 2019/04/22 15:50:16 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/23 16:19:17 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/parse_input.c b/parse_input.c index 8852298..f5f88cc 100644 --- a/parse_input.c +++ b/parse_input.c @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/15 14:48:14 by vmanzoni #+# #+# */ -/* Updated: 2019/04/23 16:01:12 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/23 21:09:40 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ @@ -34,6 +34,7 @@ void parse_input(char *input) if (check_tetri_errors(tetri)) print_error("Error: Tetrimino not valid."); add_to_list(tetri, &list); + printf("added to list !!\n"); while (input[i] && input[i] != '.' && input[i] != '#') i++; } diff --git a/samples/2tetri b/samples/2tetri new file mode 100644 index 0000000..26e4931 --- /dev/null +++ b/samples/2tetri @@ -0,0 +1,9 @@ +...# +...# +...# +...# + +.... +##.. +.##. +.... diff --git a/samples/3tetri b/samples/3tetri new file mode 100644 index 0000000..84fea70 --- /dev/null +++ b/samples/3tetri @@ -0,0 +1,14 @@ +...# +...# +...# +...# + +.... +##.. +.##. +.... + +.... +###. +.#.. +.... diff --git a/samples/4tetri b/samples/4tetri new file mode 100644 index 0000000..98a0c27 --- /dev/null +++ b/samples/4tetri @@ -0,0 +1,19 @@ +...# +...# +...# +...# + +...# +...# +...# +...# + +...# +...# +...# +...# + +...# +...# +...# +...# diff --git a/samples/difficile_ou_pas b/samples/difficile_ou_pas index aac9474..d0c08a8 100644 --- a/samples/difficile_ou_pas +++ b/samples/difficile_ou_pas @@ -111,4 +111,4 @@ .... .... #### -....iskjdslkfsljklfdjk +....i diff --git a/samples/one b/samples/test_bug similarity index 50% rename from samples/one rename to samples/test_bug index 5013175..0e8a3bd 100644 --- a/samples/one +++ b/samples/test_bug @@ -1,4 +1,4 @@ +#... +###. .... .... -.... -#### From 0aa3026f65010ac20d3b9e27c7483f3d22b5e400 Mon Sep 17 00:00:00 2001 From: Manzovince Date: Tue, 23 Apr 2019 21:15:12 +0200 Subject: [PATCH 12/13] Few edits + BUG found on tmp (add_to_list) with some tetriminoes --- add_to_list.c | 12 ++++++++---- fillit.h | 2 +- get_smallest_square.c | 10 +++++++++- main.c | 2 +- parse_input.c | 3 ++- samples/2tetri | 9 +++++++++ samples/3tetri | 14 ++++++++++++++ samples/4tetri | 19 +++++++++++++++++++ samples/difficile_ou_pas | 2 +- samples/{one => test_bug} | 4 ++-- 10 files changed, 66 insertions(+), 11 deletions(-) create mode 100644 samples/2tetri create mode 100644 samples/3tetri create mode 100644 samples/4tetri rename samples/{one => test_bug} (50%) diff --git a/add_to_list.c b/add_to_list.c index 9a0ad48..fd7d130 100644 --- a/add_to_list.c +++ b/add_to_list.c @@ -6,7 +6,7 @@ /* By: hulamy +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/14 15:20:53 by hulamy #+# #+# */ -/* Updated: 2019/04/23 16:15:10 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/23 21:04:43 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ @@ -15,7 +15,8 @@ //#include "libft/includes/libft.h" /* -** this function prints a 16 bites short +** DELETE BEFORE EVAL - TEST FUNCTION +** Function that prints a 16 bites short */ void print_bits(short line) @@ -59,7 +60,8 @@ int fill_list(char line[], t_fillist *list) } /* -** this function create the linked list and add a new structure linked each time needed +** Function that create the linked list and add a new structure +** linked each time needed */ int add_to_list(char *line, t_fillist **list) @@ -78,6 +80,7 @@ int add_to_list(char *line, t_fillist **list) } /* +** DELETE BEFORE EVAL - TEST FUNCTION ** Print octet */ @@ -94,6 +97,7 @@ void print_test(int octet) } /* +** DELETE BEFORE EVAL - TEST FUNCTION ** Test */ @@ -127,7 +131,7 @@ void test(unsigned int map[]) } /* -** MAIN FOR TEST +** DELETE BEFORE EVAL - MAIN FOR TEST */ /* diff --git a/fillit.h b/fillit.h index c80544f..0fbd67c 100644 --- a/fillit.h +++ b/fillit.h @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/03/01 13:34:46 by vmanzoni #+# #+# */ -/* Updated: 2019/04/23 14:25:15 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/23 16:19:19 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/get_smallest_square.c b/get_smallest_square.c index 9ac5ca1..399d74e 100644 --- a/get_smallest_square.c +++ b/get_smallest_square.c @@ -6,12 +6,16 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/12 22:29:45 by vmanzoni #+# #+# */ -/* Updated: 2019/04/23 14:34:32 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/23 21:03:10 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ #include "fillit.h" +/* +** Function that initialize a int map equivalent to a square size*size +*/ + unsigned int *initialize_map(int size) { unsigned int *map[0]; @@ -23,6 +27,10 @@ unsigned int *initialize_map(int size) return (map); } +/* +** Function that bruteforce with backtracking for smallest square +*/ + int *get_smallest_square(t_fillist list, int size, unsigned int map[]) { unsigned int mask; diff --git a/main.c b/main.c index 47cdfd7..77afdd6 100644 --- a/main.c +++ b/main.c @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/02/12 13:20:48 by vmanzoni #+# #+# */ -/* Updated: 2019/04/22 15:50:16 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/23 16:19:17 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/parse_input.c b/parse_input.c index 8852298..f5f88cc 100644 --- a/parse_input.c +++ b/parse_input.c @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/15 14:48:14 by vmanzoni #+# #+# */ -/* Updated: 2019/04/23 16:01:12 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/23 21:09:40 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ @@ -34,6 +34,7 @@ void parse_input(char *input) if (check_tetri_errors(tetri)) print_error("Error: Tetrimino not valid."); add_to_list(tetri, &list); + printf("added to list !!\n"); while (input[i] && input[i] != '.' && input[i] != '#') i++; } diff --git a/samples/2tetri b/samples/2tetri new file mode 100644 index 0000000..26e4931 --- /dev/null +++ b/samples/2tetri @@ -0,0 +1,9 @@ +...# +...# +...# +...# + +.... +##.. +.##. +.... diff --git a/samples/3tetri b/samples/3tetri new file mode 100644 index 0000000..84fea70 --- /dev/null +++ b/samples/3tetri @@ -0,0 +1,14 @@ +...# +...# +...# +...# + +.... +##.. +.##. +.... + +.... +###. +.#.. +.... diff --git a/samples/4tetri b/samples/4tetri new file mode 100644 index 0000000..98a0c27 --- /dev/null +++ b/samples/4tetri @@ -0,0 +1,19 @@ +...# +...# +...# +...# + +...# +...# +...# +...# + +...# +...# +...# +...# + +...# +...# +...# +...# diff --git a/samples/difficile_ou_pas b/samples/difficile_ou_pas index aac9474..d0c08a8 100644 --- a/samples/difficile_ou_pas +++ b/samples/difficile_ou_pas @@ -111,4 +111,4 @@ .... .... #### -....iskjdslkfsljklfdjk +....i diff --git a/samples/one b/samples/test_bug similarity index 50% rename from samples/one rename to samples/test_bug index 5013175..0e8a3bd 100644 --- a/samples/one +++ b/samples/test_bug @@ -1,4 +1,4 @@ +#... +###. .... .... -.... -#### From 39a59058baa4d7aacad260dc87a923a980dd913f Mon Sep 17 00:00:00 2001 From: Manzovince Date: Tue, 23 Apr 2019 21:44:11 +0200 Subject: [PATCH 13/13] Few edit + BUG on bit convertion for tetri starting at top left corner --- .gitignore | 2 ++ add_to_list.c | 25 +++++++++++++------------ get_smallest_square.c | 6 ++---- main.c | 2 +- parse_input.c | 18 ++++++++---------- samples/1tetri | 8 ++++---- 6 files changed, 30 insertions(+), 31 deletions(-) diff --git a/.gitignore b/.gitignore index a5cf236..9b97ae7 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,5 @@ a\.out *.swp fillit + +test_fillit\.c diff --git a/add_to_list.c b/add_to_list.c index fd7d130..0a18586 100644 --- a/add_to_list.c +++ b/add_to_list.c @@ -6,7 +6,7 @@ /* By: hulamy +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/14 15:20:53 by hulamy #+# #+# */ -/* Updated: 2019/04/23 21:04:43 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/23 21:36:37 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ @@ -30,13 +30,13 @@ void print_bits(short line) } /* -** this function transforme a tetrminos char* into a short of 16 bites +** Function that transforme a tetrminos char* into a short of 16 bites ** then it fills it and its reverse into the list */ int fill_list(char line[], t_fillist *list) { - short tmp; +// short tmp; int i; i = 0; @@ -48,14 +48,15 @@ int fill_list(char line[], t_fillist *list) if (line[i++] == '#') list->tetribit |= 1; } - tmp = list->tetribit; - while (tmp) - { - if (tmp & 1) - list->tibirtet |= 1; - list->tibirtet <<= 1; - tmp >>= 1; - } +// tmp = list->tetribit; +// while (tmp) +// { +// if (tmp & 1) +// list->tibirtet |= 1; +// list->tibirtet <<= 1; +// tmp >>= 1; +// } + print_bits(list->tetribit); return (0); } @@ -98,7 +99,7 @@ void print_test(int octet) /* ** DELETE BEFORE EVAL - TEST FUNCTION -** Test +** Test for big map */ void test(unsigned int map[]) diff --git a/get_smallest_square.c b/get_smallest_square.c index 399d74e..4a4c8d2 100644 --- a/get_smallest_square.c +++ b/get_smallest_square.c @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/12 22:29:45 by vmanzoni #+# #+# */ -/* Updated: 2019/04/23 21:03:10 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/23 21:42:35 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ @@ -19,11 +19,9 @@ unsigned int *initialize_map(int size) { unsigned int *map[0]; - int i; - i = size; while (size--) - map[i] = malloc(sizeof(unsigned int) * i); + map[size] = 0; return (map); } diff --git a/main.c b/main.c index 77afdd6..2448ba8 100644 --- a/main.c +++ b/main.c @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/02/12 13:20:48 by vmanzoni #+# #+# */ -/* Updated: 2019/04/23 16:19:17 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/23 21:39:42 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ diff --git a/parse_input.c b/parse_input.c index f5f88cc..49ce03e 100644 --- a/parse_input.c +++ b/parse_input.c @@ -6,7 +6,7 @@ /* By: vmanzoni +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/04/15 14:48:14 by vmanzoni #+# #+# */ -/* Updated: 2019/04/23 21:09:40 by vmanzoni ### ########.fr */ +/* Updated: 2019/04/23 21:23:47 by vmanzoni ### ########.fr */ /* */ /* ************************************************************************** */ @@ -38,15 +38,13 @@ void parse_input(char *input) while (input[i] && input[i] != '.' && input[i] != '#') i++; } - /*DEBUG PART - Print each tetribit*/ -/* - while (list != NULL) - { - printf("%i\n", list->tetribit); - printf("\n"); - list = list->next; - } -*/ +/*DEBUG PART - Print each tetribit*/ +// while (list != NULL) +// { +// printf("%i\n", list->tetribit); +// printf("\n"); +// list = list->next; +// } } /* diff --git a/samples/1tetri b/samples/1tetri index 3f1734a..caa819e 100644 --- a/samples/1tetri +++ b/samples/1tetri @@ -1,4 +1,4 @@ -...# -...# -...# -...# +#... +#... +#... +#...