tentative de pull

This commit is contained in:
Hugo LAMY
2019-04-16 13:55:37 +02:00
12 changed files with 144 additions and 83 deletions

6
.gitignore vendored
View File

@@ -1 +1,7 @@
objs/
*.o
a\.out\.dSYM/
a\.out

View File

@@ -6,7 +6,7 @@
# By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2019/03/01 13:24:35 by vmanzoni #+# #+# #
# Updated: 2019/04/14 22:01:39 by vmanzoni ### ########.fr #
# Updated: 2019/04/15 20:17:47 by vmanzoni ### ########.fr #
# #
# **************************************************************************** #

View File

@@ -6,13 +6,13 @@
- [x] Check if we have a file
- [x] Read file
- [ ] Check if there are errors in file
- [x] Check if there are errors in file
- At least 1 tetrimino or less than 26
- [ ] Check if every tetrimino is valid
- [x] Check if every tetrimino is valid
- 4 char * 4 lines
- 4 blocks in 1 tetrimino
- No solo block
- [ ] Transform file into tetriminos
- [x] Transform file into tetriminos
- [ ] Backtracking for smallest square
- [ ] Transform tetriminos to letters
- [ ] Print result

BIN
a.out

Binary file not shown.

View File

@@ -1,20 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleIdentifier</key>
<string>com.apple.xcode.dsym.a.out</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>dSYM</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>

View File

@@ -3,16 +3,21 @@
/* ::: :::::::: */
/* add_to_list.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
/* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/14 15:20:53 by hulamy #+# #+# */
/* Updated: 2019/04/15 17:07:34 by hulamy ### ########.fr */
/* Updated: 2019/04/15 20:49:33 by vmanzoni ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
#include <stdio.h>
/*
** Function that fills the char **tetraminos section of the structure
** with the most little rectangle that fit the tetraminos
*/
char **fill_tetraminos(char **square, int *tab)
{
char **result;
@@ -40,6 +45,13 @@ char **fill_tetraminos(char **square, int *tab)
return (result);
}
/*
** This function calculate the line and columns where the tetraminos
** start and end, by skipping the empty lines
**
** ! it has a little bug so far, i need to fix it
*/
void find_start_and_end(char **square, int **x)
{
int i;
@@ -66,6 +78,19 @@ void find_start_and_end(char **square, int **x)
i--;
}
/*
** this function first call find_start_and_end to find the coordinates
** of start en end of the most little rectangle that fit the tetraminos
**
** it allows it to fill the structure with the size information
** (for instance :
** "##" ".#" ".#"
** is a tatraminos of 2 by 3)
** then it fills also the area information (2 * 3 = 6)
**
** and finally it calls fill_tetraminos to fill the char **tetraminos
*/
int fill_list(char **square, t_fillist *list)
{
int *tab;
@@ -79,6 +104,14 @@ int fill_list(char **square, t_fillist *list)
return (1);
}
/*
** this function first checks if the structure has been created
** if not, it creates the first element, else it adds an element
** and modifies the initial pointer to link to the new first element
**
** then it calls fill_list to fill the data of the structure
*/
int add_to_list(char **square, t_fillist **list)
{
t_fillist *tmp;
@@ -94,12 +127,13 @@ int add_to_list(char **square, t_fillist **list)
return (1);
}
/*
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
int i;
if (ac > 4)
if (ac > 1)
{
add_to_list(++av, &list); // l'appel de la fonction se fait avec un carre valide de 4*4 et l'adresse du pointeur vers la liste
if (ac == 9)
@@ -115,3 +149,4 @@ int main(int ac, char **av)
return (0);
}
*/

View File

@@ -6,7 +6,7 @@
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/01 13:34:46 by vmanzoni #+# #+# */
/* Updated: 2019/04/15 15:51:03 by hulamy ### ########.fr */
/* Updated: 2019/04/15 20:53:57 by vmanzoni ### ########.fr */
/* */
/* ************************************************************************** */
@@ -23,21 +23,9 @@
# define BUFF_SIZE 1024
/*
** DELETE BEFORE EVALUATION
** STRUCTURE
*/
void print_test(char *test);
/*
** FUNCTIONS
*/
char *read_file(char *file);
void print_error(char *s);
int check_file_errors(char *file);
int check_tetri_errors(char *tetri);
int check_tetri_errors2(char *tetri);
typedef struct s_fillist
{
int id;
@@ -48,6 +36,17 @@ typedef struct s_fillist
struct s_fillist *next;
} t_fillist;
/*
** FUNCTIONS
*/
void print_test(char *test); //DELETE BEFORE EVALUATION
char *read_file(char *file);
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 add_to_list(char **square, t_fillist **list);
#endif

View File

@@ -6,7 +6,7 @@
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/01 13:29:05 by vmanzoni #+# #+# */
/* Updated: 2019/04/15 00:13:18 by hulamy ### ########.fr */
/* Updated: 2019/04/15 14:41:19 by vmanzoni ### ########.fr */
/* */
/* ************************************************************************** */
@@ -42,8 +42,9 @@ int check_file_errors(char *file)
return (1);
if (file[i] == '\n')
line_nbr++;
// if (file[i] == '\n' && file[i+2] != '.' && file[i+2] != '#')
// return (1);
if (file[i] == '\n' && file[i+1] != '\0' && \
file[i+2] != '.' && file[i+2] != '#')
return (1);
i++;
}
if (line_nbr < 4 || line_nbr > 129)
@@ -51,6 +52,12 @@ int check_file_errors(char *file)
return (0);
}
/*
** Function that check if tetrimino square contains:
** - 4 '#'
** - 12 '.'
*/
int check_tetri_errors(char *tetri)
{
int i;
@@ -73,6 +80,9 @@ int check_tetri_errors(char *tetri)
return (0);
}
/*
** Function that check if tetrimino parts are linked
*/
int check_tetri_errors2(char *tetri)
{

8
main.c
View File

@@ -6,7 +6,7 @@
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/12 13:20:48 by vmanzoni #+# #+# */
/* Updated: 2019/04/15 00:12:25 by hulamy ### ########.fr */
/* Updated: 2019/04/15 20:54:24 by vmanzoni ### ########.fr */
/* */
/* ************************************************************************** */
@@ -22,16 +22,14 @@ int main(int argc, char **argv)
print_error("Error: Could not read file.\n");
if (check_file_errors(input))
print_error("Error: Invalid file.\n");
if (check_tetri_errors(input))
print_error("Error: Tetrimino not valid.\n");
parse_input(input);
/*
Check if every tetrimino is valid
Transform input to tetriminos
Backtracking for smallest square
Transform tetriminos with letters
Print result
*/
print_test(input);
//print_test(input);
}
else
print_error("Usage: Please submit a file.\n");

65
parse_input.c Normal file
View File

@@ -0,0 +1,65 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parse_input.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/15 14:48:14 by vmanzoni #+# #+# */
/* Updated: 2019/04/16 11:50:45 by vmanzoni ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
/*
** Function that parse a file and put each tetrimino in a linked list
*/
char **create_square(char *tetri)
{
char **square = NULL;
int i;
int k;
i = 0;
while (tetri[i])
{
k = 0;
*square = malloc((sizeof(char)*4) + 1);
while (k < 4)
{
*square[k] = tetri[i];
k++;
i++;
}
i++;
//printf("print:\n%s\n", *square);
while (tetri[i] == '\n')
i++;
}
return (square);
}
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("PRINT:\n%s\n", tetri);
if (check_tetri_errors(tetri))
print_error("Error: Tetrimino not valid.");
add_to_list(create_square(tetri), &list);
while (input[i] == '\n')
i++;
}
}

View File

@@ -6,14 +6,14 @@
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/13 12:09:46 by vmanzoni #+# #+# */
/* Updated: 2019/04/14 23:01:31 by vmanzoni ### ########.fr */
/* Updated: 2019/04/15 14:48:36 by vmanzoni ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
/*
** Function that read and return a ptr to file
** Function that read and return a ptr to file content
*/
char *read_file(char *file)
@@ -39,35 +39,3 @@ char *read_file(char *file)
close(fd);
return (result);
}
/*
** Function that parse a file and return each tetrimino
*/
int parse_input(char *input)
{
char tetri;
int c;
int i;
int j;
c = 0;
while (input[c])
{
i = 0;
while (i < 4)
{
j = 0;
while (j < 4)
{
tetri[j] = input[c++];
j++;
}
if (check_tetri_errors(tetri))
print_error("Error: Tetrimino not valid.\n");
c++;
i++;
}
c++;
}
}