corrige le fill_list pour virer les zeros de debut de tetraminos
This commit is contained in:
105
'
Normal file
105
'
Normal file
@@ -0,0 +1,105 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* add_to_list.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/14 15:20:53 by hulamy #+# #+# */
|
||||
/* Updated: 2019/04/24 13:36:26 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "fillit.h"
|
||||
#include <stdio.h>
|
||||
|
||||
/*
|
||||
** DELETE BEFORE EVAL - TEST FUNCTION
|
||||
** Function that prints a 16 bites short
|
||||
*/
|
||||
|
||||
//void print_bits(short line)
|
||||
//{
|
||||
// int mask;
|
||||
//
|
||||
// mask = 1 << 16;
|
||||
// while (mask >>= 1)
|
||||
// (line & mask) ? write(1, "1", 1) : write(1, "0", 1);
|
||||
// write(1, "\n", 1);
|
||||
//}
|
||||
|
||||
/*
|
||||
** 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)
|
||||
{
|
||||
unsigned short tmp;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (line[i])
|
||||
{
|
||||
list->tetribit <<= 1;
|
||||
if (line[i] == '\n')
|
||||
i++;
|
||||
if (line[i++] == '#')
|
||||
list->tetribit |= 1;
|
||||
}
|
||||
while (!(list->tetribit & (1 << 15)))
|
||||
list->tetribit <<= 1;
|
||||
tmp = list->tetribit;
|
||||
while (tmp)
|
||||
{
|
||||
list->tibirtet <<= 1;
|
||||
if (tmp & 1)
|
||||
list->tibirtet |= 1;
|
||||
tmp >>= 1;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
/*
|
||||
** Function that 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);
|
||||
}
|
||||
|
||||
/*
|
||||
** DELETE BEFORE EVAL - MAIN FOR TEST
|
||||
*/
|
||||
|
||||
//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 > 1)
|
||||
// {
|
||||
// add_to_list(*(++av), &list);
|
||||
// while (list && (i = -1))
|
||||
// {
|
||||
// printf("%d\n", list->tetribit);
|
||||
// print_bits(list->tetribit);
|
||||
// print_bits(list->tibirtet);
|
||||
// list = list->next;
|
||||
// }
|
||||
// }
|
||||
// return (0);
|
||||
//}
|
||||
|
||||
137
add_to_list.c
137
add_to_list.c
@@ -6,28 +6,27 @@
|
||||
/* By: hulamy <hulamy@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/14 15:20:53 by hulamy #+# #+# */
|
||||
/* Updated: 2019/04/24 12:15:47 by hulamy ### ########.fr */
|
||||
/* Updated: 2019/04/24 13:38:22 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "fillit.h"
|
||||
#include <stdio.h>
|
||||
//#include "libft/includes/libft.h"
|
||||
//#include <stdio.h>
|
||||
|
||||
/*
|
||||
** DELETE BEFORE EVAL - TEST FUNCTION
|
||||
** Function that prints a 16 bites short
|
||||
*/
|
||||
|
||||
void print_bits(short line)
|
||||
{
|
||||
int mask;
|
||||
|
||||
mask = 1 << 27;
|
||||
while (mask >>= 1)
|
||||
(line & mask) ? write(1, "1", 1) : write(1, "0", 1);
|
||||
write(1, "\n", 1);
|
||||
}
|
||||
//void print_bits(short line)
|
||||
//{
|
||||
// int mask;
|
||||
//
|
||||
// mask = 1 << 16;
|
||||
// while (mask >>= 1)
|
||||
// (line & mask) ? write(1, "1", 1) : write(1, "0", 1);
|
||||
// write(1, "\n", 1);
|
||||
//}
|
||||
|
||||
/*
|
||||
** Function that transforme a tetrminos char* into a short of 16 bites
|
||||
@@ -36,8 +35,8 @@ void print_bits(short line)
|
||||
|
||||
int fill_list(char line[], t_fillist *list)
|
||||
{
|
||||
// short tmp;
|
||||
int i;
|
||||
unsigned short tmp;
|
||||
int i;
|
||||
|
||||
i = 0;
|
||||
while (line[i])
|
||||
@@ -48,15 +47,16 @@ 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;
|
||||
// }
|
||||
print_bits(list->tetribit);
|
||||
while (!(list->tetribit & (1 << 15)))
|
||||
list->tetribit <<= 1;
|
||||
tmp = list->tetribit;
|
||||
while (tmp)
|
||||
{
|
||||
list->tibirtet <<= 1;
|
||||
if (tmp & 1)
|
||||
list->tibirtet |= 1;
|
||||
tmp >>= 1;
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
@@ -80,81 +80,26 @@ int add_to_list(char *line, t_fillist **list)
|
||||
return (1);
|
||||
}
|
||||
|
||||
/*
|
||||
** DELETE BEFORE EVAL - TEST FUNCTION
|
||||
** Print octet
|
||||
*/
|
||||
|
||||
void print_test(int octet)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
i = 1 << 31;
|
||||
while (i)
|
||||
{
|
||||
(octet & i) ? printf("1") : printf("0");
|
||||
i >>= 1;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** DELETE BEFORE EVAL - TEST FUNCTION
|
||||
** Test for big map
|
||||
*/
|
||||
|
||||
void test(unsigned int map[])
|
||||
{
|
||||
int i;
|
||||
int j;
|
||||
int k;
|
||||
int l;
|
||||
unsigned int mask;
|
||||
|
||||
mask = map[9];
|
||||
|
||||
i = -1;
|
||||
j = 9;
|
||||
while (j >= 0)
|
||||
{
|
||||
if (!(++i % 32) && j-- && (k = -1))
|
||||
{
|
||||
while (++k < 10)
|
||||
print_test(map[k]);
|
||||
printf("\n");
|
||||
}
|
||||
l = 0;
|
||||
while (l++ < 320 - 32 - i)
|
||||
printf(" ");
|
||||
print_test(mask);
|
||||
printf("\n");
|
||||
mask = (mask >> 1) | (((1 << (i % 32)) & map[j]) << (31 - (i % 32)));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** DELETE BEFORE EVAL - MAIN FOR TEST
|
||||
*/
|
||||
|
||||
/*
|
||||
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
|
||||
unsigned int map[10] = {1568713153, 817645681, 654186132, 538171355, 1718453135, 551286515, 1631843343, 3413834313, 1155555555, 999999999};
|
||||
int i;
|
||||
//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 > 1)
|
||||
// {
|
||||
// add_to_list(*(++av), &list);
|
||||
// while (list && (i = -1))
|
||||
// {
|
||||
// printf("%d\n", list->tetribit);
|
||||
// print_bits(list->tetribit);
|
||||
// print_bits(list->tibirtet);
|
||||
// list = list->next;
|
||||
// }
|
||||
// }
|
||||
// return (0);
|
||||
//}
|
||||
|
||||
if (ac > 1)
|
||||
{
|
||||
add_to_list(*(++av), &list);
|
||||
while (list && (i = -1))
|
||||
{
|
||||
printf("%d\n", list->tetribit);
|
||||
print_bits(list->tetribit);
|
||||
print_bits(list->tibirtet);
|
||||
list = list->next;
|
||||
}
|
||||
}
|
||||
test(map);
|
||||
|
||||
return (0);
|
||||
}
|
||||
*/
|
||||
|
||||
7
fillit.h
7
fillit.h
@@ -6,7 +6,7 @@
|
||||
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/03/01 13:34:46 by vmanzoni #+# #+# */
|
||||
/* Updated: 2019/04/23 16:19:19 by vmanzoni ### ########.fr */
|
||||
/* Updated: 2019/04/24 13:02:34 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include <stdio.h> // for printf (DELETE BEFORE EVAL)
|
||||
|
||||
#include "libft/includes/libft.h"
|
||||
# define BUFF_SIZE 1024
|
||||
|
||||
/*
|
||||
** STRUCTURE
|
||||
@@ -26,8 +27,8 @@
|
||||
|
||||
typedef struct s_fillist
|
||||
{
|
||||
short tetribit;
|
||||
short tibirtet;
|
||||
unsigned short tetribit;
|
||||
unsigned short tibirtet;
|
||||
int position;
|
||||
struct s_fillist *next;
|
||||
} t_fillist;
|
||||
|
||||
@@ -6,12 +6,24 @@
|
||||
/* By: vmanzoni <vmanzoni@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2019/04/15 14:48:14 by vmanzoni #+# #+# */
|
||||
/* Updated: 2019/04/23 21:23:47 by vmanzoni ### ########.fr */
|
||||
/* Updated: 2019/04/24 12:52:26 by hulamy ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "fillit.h"
|
||||
|
||||
void print_short(short octet)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
i = 1 << 15;
|
||||
while (i)
|
||||
{
|
||||
(octet & i) ? printf("1") : printf("0");
|
||||
i >>= 1;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Function that parse a file and put each tetrimino in a linked list
|
||||
*/
|
||||
@@ -38,13 +50,16 @@ 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);
|
||||
print_short(list->tetribit);
|
||||
printf("\n");
|
||||
print_short(list->tibirtet);
|
||||
printf("\n");
|
||||
list = list->next;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -52,26 +67,26 @@ void parse_input(char *input)
|
||||
** Function that parse a file and put each tetrimino in a linked list
|
||||
*/
|
||||
|
||||
char **create_square(char *tetri)
|
||||
{
|
||||
char **square;
|
||||
int i;
|
||||
int k;
|
||||
|
||||
i = 0;
|
||||
if (!(square = (char**)malloc(sizeof(*square) * (4 + 1))))
|
||||
return (NULL);
|
||||
square[4] = NULL;
|
||||
while (*tetri && (k = -1))
|
||||
{
|
||||
if (!(square[i] = (char*)malloc(sizeof(**square) * (4 + 1))))
|
||||
return (NULL);
|
||||
square[i][4] = '\0';
|
||||
while (++k < 4)
|
||||
square[i][k] = *(tetri++);
|
||||
while (*tetri == '\n')
|
||||
tetri++;
|
||||
i++;
|
||||
}
|
||||
return (square);
|
||||
}
|
||||
// char **create_square(char *tetri)
|
||||
// {
|
||||
// char **square;
|
||||
// int i;
|
||||
// int k;
|
||||
//
|
||||
// i = 0;
|
||||
// if (!(square = (char**)malloc(sizeof(*square) * (4 + 1))))
|
||||
// return (NULL);
|
||||
// square[4] = NULL;
|
||||
// while (*tetri && (k = -1))
|
||||
// {
|
||||
// if (!(square[i] = (char*)malloc(sizeof(**square) * (4 + 1))))
|
||||
// return (NULL);
|
||||
// square[i][4] = '\0';
|
||||
// while (++k < 4)
|
||||
// square[i][k] = *(tetri++);
|
||||
// while (*tetri == '\n')
|
||||
// tetri++;
|
||||
// i++;
|
||||
// }
|
||||
// return (square);
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user