Cleaning modif + new file for parsing input
This commit is contained in:
@@ -3,16 +3,19 @@
|
|||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* add_to_list.c :+: :+: :+: */
|
/* add_to_list.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: hulamy <marvin@42.fr> +#+ +:+ +#+ */
|
/* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/04/14 15:20:53 by hulamy #+# #+# */
|
/* Created: 2019/04/14 15:20:53 by hulamy #+# #+# */
|
||||||
/* Updated: 2019/04/15 00:24:25 by hulamy ### ########.fr */
|
/* Updated: 2019/04/15 14:38:43 by vmanzoni ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "fillit.h"
|
#include "fillit.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Function that ...
|
||||||
|
*/
|
||||||
|
|
||||||
void find_start_and_end(char **square, int *x1, int *x2, int *y1, int *y2)
|
void find_start_and_end(char **square, int *x1, int *x2, int *y1, int *y2)
|
||||||
{
|
{
|
||||||
@@ -36,6 +39,10 @@ void find_start_and_end(char **square, int *x1, int *x2, int *y1, int *y2)
|
|||||||
i--;
|
i--;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Function that ...
|
||||||
|
*/
|
||||||
|
|
||||||
char **fill_tetraminos(char **square, int x1, int y1, int x2, int y2)
|
char **fill_tetraminos(char **square, int x1, int y1, int x2, int y2)
|
||||||
{
|
{
|
||||||
char **result;
|
char **result;
|
||||||
@@ -63,6 +70,10 @@ char **fill_tetraminos(char **square, int x1, int y1, int x2, int y2)
|
|||||||
return (result);
|
return (result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Function that ...
|
||||||
|
*/
|
||||||
|
|
||||||
int add_to_list(char **square)
|
int add_to_list(char **square)
|
||||||
{
|
{
|
||||||
t_fillist *list;
|
t_fillist *list;
|
||||||
|
|||||||
6
fillit.h
6
fillit.h
@@ -6,7 +6,7 @@
|
|||||||
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/03/01 13:34:46 by vmanzoni #+# #+# */
|
/* Created: 2019/03/01 13:34:46 by vmanzoni #+# #+# */
|
||||||
/* Updated: 2019/04/15 00:26:08 by hulamy ### ########.fr */
|
/* Updated: 2019/04/15 13:39:50 by vmanzoni ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -39,6 +39,10 @@ int check_tetri_errors(char *tetri);
|
|||||||
int check_tetri_errors2(char *tetri);
|
int check_tetri_errors2(char *tetri);
|
||||||
int add_to_list(char **square);
|
int add_to_list(char **square);
|
||||||
|
|
||||||
|
/*
|
||||||
|
** STRUCTURE
|
||||||
|
*/
|
||||||
|
|
||||||
typedef struct s_fillist
|
typedef struct s_fillist
|
||||||
{
|
{
|
||||||
int id;
|
int id;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/03/01 13:29:05 by vmanzoni #+# #+# */
|
/* 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);
|
return (1);
|
||||||
if (file[i] == '\n')
|
if (file[i] == '\n')
|
||||||
line_nbr++;
|
line_nbr++;
|
||||||
// if (file[i] == '\n' && file[i+2] != '.' && file[i+2] != '#')
|
if (file[i] == '\n' && file[i+1] != '\0' && \
|
||||||
// return (1);
|
file[i+2] != '.' && file[i+2] != '#')
|
||||||
|
return (1);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
if (line_nbr < 4 || line_nbr > 129)
|
if (line_nbr < 4 || line_nbr > 129)
|
||||||
@@ -51,6 +52,12 @@ int check_file_errors(char *file)
|
|||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Function that check if tetrimino square contains:
|
||||||
|
** - 4 '#'
|
||||||
|
** - 12 '.'
|
||||||
|
*/
|
||||||
|
|
||||||
int check_tetri_errors(char *tetri)
|
int check_tetri_errors(char *tetri)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@@ -73,6 +80,9 @@ int check_tetri_errors(char *tetri)
|
|||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Function that check if tetrimino parts are linked
|
||||||
|
*/
|
||||||
|
|
||||||
int check_tetri_errors2(char *tetri)
|
int check_tetri_errors2(char *tetri)
|
||||||
{
|
{
|
||||||
|
|||||||
5
main.c
5
main.c
@@ -6,7 +6,7 @@
|
|||||||
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/02/12 13:20:48 by vmanzoni #+# #+# */
|
/* Created: 2019/02/12 13:20:48 by vmanzoni #+# #+# */
|
||||||
/* Updated: 2019/04/15 00:12:25 by hulamy ### ########.fr */
|
/* Updated: 2019/04/15 14:41:44 by vmanzoni ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -22,10 +22,7 @@ int main(int argc, char **argv)
|
|||||||
print_error("Error: Could not read file.\n");
|
print_error("Error: Could not read file.\n");
|
||||||
if (check_file_errors(input))
|
if (check_file_errors(input))
|
||||||
print_error("Error: Invalid file.\n");
|
print_error("Error: Invalid file.\n");
|
||||||
if (check_tetri_errors(input))
|
|
||||||
print_error("Error: Tetrimino not valid.\n");
|
|
||||||
/*
|
/*
|
||||||
Check if every tetrimino is valid
|
|
||||||
Transform input to tetriminos
|
Transform input to tetriminos
|
||||||
Backtracking for smallest square
|
Backtracking for smallest square
|
||||||
Transform tetriminos with letters
|
Transform tetriminos with letters
|
||||||
|
|||||||
34
parse_input.c
Normal file
34
parse_input.c
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
/* ************************************************************************** */
|
||||||
|
/* */
|
||||||
|
/* ::: :::::::: */
|
||||||
|
/* parse_input.c :+: :+: :+: */
|
||||||
|
/* +:+ +:+ +:+ */
|
||||||
|
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
||||||
|
/* +#+#+#+#+#+ +#+ */
|
||||||
|
/* Created: 2019/04/15 14:48:14 by vmanzoni #+# #+# */
|
||||||
|
/* Updated: 2019/04/15 15:10:01 by vmanzoni ### ########.fr */
|
||||||
|
/* */
|
||||||
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "fillit.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
** Function that parse a file and return each tetrimino
|
||||||
|
*/
|
||||||
|
|
||||||
|
void parse_input(char *input)
|
||||||
|
{
|
||||||
|
char *tetri;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
i = 0;
|
||||||
|
while (input[i])
|
||||||
|
{
|
||||||
|
tetri[i] = input[i];
|
||||||
|
if (i != 0 && i%19 == 0)
|
||||||
|
{
|
||||||
|
|
||||||
|
i+2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
36
read_file.c
36
read_file.c
@@ -6,14 +6,14 @@
|
|||||||
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2019/04/13 12:09:46 by vmanzoni #+# #+# */
|
/* 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"
|
#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)
|
char *read_file(char *file)
|
||||||
@@ -39,35 +39,3 @@ char *read_file(char *file)
|
|||||||
close(fd);
|
close(fd);
|
||||||
return (result);
|
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++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user