This commit is contained in:
Greg 2024-12-26 00:57:09 +02:00
parent 337c227fd7
commit fb456880a7
16 changed files with 616 additions and 0 deletions

92
CMakeLists.txt Normal file
View file

@ -0,0 +1,92 @@
cmake_minimum_required(VERSION 3.5.2)
project(fillit)
set(CMAKE_CXX_STANDARD 11)
include_directories(inc)
include_directories(libft)
set(SOURCE_FILES
libft/ft_atoi.c
libft/ft_bzero.c
libft/ft_isalnum.c
libft/ft_isalpha.c
libft/ft_isascii.c
libft/ft_isdigit.c
libft/ft_isprint.c
libft/ft_itoa.c
libft/ft_lst_at.c
libft/ft_lstadd.c
libft/ft_lstadd_back.c
libft/ft_lstdel.c
libft/ft_lstdelone.c
libft/ft_lstfind.c
libft/ft_lstiter.c
libft/ft_lstmap.c
libft/ft_lstnew.c
libft/ft_lststrsplit.c
libft/ft_memalloc.c
libft/ft_memccpy.c
libft/ft_memchr.c
libft/ft_memcmp.c
libft/ft_memcpy.c
libft/ft_memdel.c
libft/ft_memmove.c
libft/ft_memset.c
libft/ft_putchar.c
libft/ft_putchar_fd.c
libft/ft_putendl.c
libft/ft_putendl_fd.c
libft/ft_putnbr.c
libft/ft_putnbr_fd.c
libft/ft_putstr.c
libft/ft_putstr_fd.c
libft/ft_realloc.c
libft/ft_strcat.c
libft/ft_strchr.c
libft/ft_strclr.c
libft/ft_strcmp.c
libft/ft_strcpy.c
libft/ft_strdel.c
libft/ft_strdup.c
libft/ft_strequ.c
libft/ft_striter.c
libft/ft_striteri.c
libft/ft_strjoin.c
libft/ft_strlcat.c
libft/ft_strlen.c
libft/ft_strmap.c
libft/ft_strmapi.c
libft/ft_strncat.c
libft/ft_strncmp.c
libft/ft_strncpy.c
libft/ft_strnequ.c
libft/ft_strnew.c
libft/ft_strnstr.c
libft/ft_strrchr.c
libft/ft_strsplit.c
libft/ft_strstr.c
libft/ft_strsub.c
libft/ft_strtrim.c
libft/ft_tolower.c
libft/ft_toupper.c
libft/ft_lstpop.c
libft/libft.h
src/check_raw_string.c
src/dancing_links.c
src/fillit.c
src/get_types.c
src/glue_figure.c
src/main.c
src/move_up_left.c
src/read_file.c
src/string_to_table.c
src/test!_check.c
src/test!_print_one_string.c
src/test!_print_table.c
src/to_letters.c
src/get_amount.c
tests/sample.fillit
tests/sample1.fillit)
add_executable(fillit ${SOURCE_FILES})

34
src/check_raw_string.c Normal file
View file

@ -0,0 +1,34 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* check_raw_string.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/15 18:32:54 by gtertysh #+# #+# */
/* Updated: 2016/12/15 18:32:58 by gtertysh ### ########.fr */
/* */
/* ************************************************************************** */
int check_raw_string(char *raw_string)
{
int n_count;
n_count = 0;
if (*raw_string == 0 || *raw_string == '\n')
return (1);
while(*raw_string)
{
if (*raw_string == '\n')
n_count++;
if ((n_count + 1) % 4 == 0)
if (*(raw_string + 1) != '\0')
if (*(raw_string + 1) != '\n' && !(*(raw_string + 2) == '.' || *(raw_string + 2) == '#'))
return (1);
raw_string++;
}
if (n_count < 3)
return (1);
return (0);
}

11
src/fillit.c Normal file
View file

@ -0,0 +1,11 @@
#include "fillit.h"
unsigned int ft_sqrt_ceil(unsigned int num)
{
unsigned int i;
i = 1;
while (i * i < num)
i++;
return (i);
}

38
src/test!_check.c Normal file
View file

@ -0,0 +1,38 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* test!_check.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/14 17:26:13 by gtertysh #+# #+# */
/* Updated: 2016/12/20 19:02:34 by gtertysh ### ########.fr */
/* */
/* ************************************************************************** */
#include "../inc/fillit.h"
// Test func. Compare figures from file
// with templates
void test_check(char **ttr, t_ttrmn *templates)
{
int i;
int j;
i = 0;
while (ttr[i])
{
j = 0;
while(j < 19)
{
if ((ft_memcmp(ttr[i], templates[j].t, 17) == 0))
{
printf(" match!\n");
print_one_string(templates[j]);
break;
}
j++;
}
i++;
}
}

View file

@ -0,0 +1,31 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* test!_print_one_string.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/14 17:09:23 by gtertysh #+# #+# */
/* Updated: 2016/12/14 17:09:24 by gtertysh ### ########.fr */
/* */
/* ************************************************************************** */
#include "../inc/fillit.h"
// Test func. Print table but one string contain whole figure.
void print_one_string(t_ttrmn ttr)
{
int i;
i = 0;
while (ttr.t[i])
{
ft_putchar(ttr.t[i]);
if ((i + 1) % 4 == 0)
ft_putchar('\n');
i++;
}
printf("x = %d, y = %d\n", ttr.width, ttr.height);
printf("x1[%d] y1[%d]\nx2[%d] y2[%d]\nx3[%d] y3[%d]\nx4[%d] y4[%d]\n", ttr.c[0].x, ttr.c[0].y, ttr.c[1].x, ttr.c[1].y, ttr.c[2].x, ttr.c[2].y, ttr.c[3].x, ttr.c[3].y);
ft_putstr("\n");
}

30
src/test!_print_table.c Normal file
View file

@ -0,0 +1,30 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* test!_print_table.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/14 17:07:19 by gtertysh #+# #+# */
/* Updated: 2016/12/14 17:07:22 by gtertysh ### ########.fr */
/* */
/* ************************************************************************** */
#include "../inc/fillit.h"
// Test func. Print string table,
// each line - line of tetromino figure.
void print_table(char **table)
{
int i;
i = 0;
while (table[i])
{
ft_putstr(table[i]);
ft_putstr("\n");
if ((i + 1) % 4 == 0)
ft_putchar('\n');
i++;
}
}

37
src/to_letters.c Normal file
View file

@ -0,0 +1,37 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* to_letters.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gtertysh <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/12/14 17:21:37 by gtertysh #+# #+# */
/* Updated: 2016/12/14 17:21:39 by gtertysh ### ########.fr */
/* */
/* ************************************************************************** */
#include "../inc/fillit.h"
// convert "#" symbols to letters
// rewrite for new method with structures
void to_letters(char **ttr)
{
char ch;
int i;
int j;
i = 0;
ch = 'A';
while(ttr[i])
{
j = 0;
while(ttr[i][j])
{
if(ttr[i][j] == '#')
ttr[i][j] = ch;
j++;
}
i++;
ch++;
}
}

42
tests/color_letters.c Normal file
View file

@ -0,0 +1,42 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* color_letters.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kyork <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/10/04 16:44:50 by kyork #+# #+# */
/* Updated: 2016/10/05 15:41:53 by kyork ### ########.fr */
/* */
/* ************************************************************************** */
#define CSI "\033["
#include <stdio.h>
#include <unistd.h>
int g_colors[] = {1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14,
16 + 5, 16 + 12, 16 + 23, 16 + 30, 52 + 0, 52 + 5, 52 + 6, 52 + 12, 52 + 20,
88 + 1, 88 + 6, 88 + 12, 160 + 12, 196 + 30, 160 + 21};
int main(void)
{
char c;
ssize_t read_size;
while (1)
{
read_size = read(0, &c, 1);
if (read_size == 0)
break ;
if ('A' <= c && c <= 'Z')
{
printf("%s48;5;%dm%c", CSI, g_colors[c - 'A'], c);
}
else if (c == '.')
printf("%sm%c", CSI, c);
else if (c == '\n')
printf("%sm%c", CSI, c);
else
printf("%c", c);
}
}

46
tests/rand_test.py Executable file
View file

@ -0,0 +1,46 @@
#!/usr/bin/env python
from __future__ import print_function
tet_shapes = [
'####\n....\n....\n....\n',
'#...\n#...\n#...\n#...\n',
'#...\n###.\n....\n....\n',
'##..\n#...\n#...\n....\n',
'###.\n..#.\n....\n....\n',
'.#..\n.#..\n##..\n....\n',
'..#.\n###.\n....\n....\n',
'#...\n#...\n##..\n....\n',
'###.\n#...\n....\n....\n',
'##..\n.#..\n.#..\n....\n',
'##..\n##..\n....\n....\n',
'.##.\n##..\n....\n....\n',
'#...\n##..\n.#..\n....\n',
'.#..\n###.\n....\n....\n',
'#...\n##..\n#...\n....\n',
'###.\n.#..\n....\n....\n',
'.#..\n##..\n.#..\n....\n',
'##..\n.##.\n....\n....\n',
'.#..\n##..\n#...\n....\n',
]
import argparse
import random
import os
parser = argparse.ArgumentParser(description="Generate random fillit problems")
parser.add_argument('count', metavar="count", type=int, default=10, nargs='?',
help="number of tetrominoes to output")
parser.add_argument('--seed', type=int, default=None,
help="mt_rand seed (to reproduce problems)")
args = parser.parse_args()
seed = args.seed
if seed is None:
seed = random.SystemRandom().randint(0, 2**19937-1)
random.seed(seed)
tets = [tet_shapes[random.randrange(len(tet_shapes))] for x in range(args.count)]
[print(x, end=("" if i == len(tets) - 1 else "\n")) for i, x in enumerate(tets)]

21
tests/sample.fillit Normal file
View file

@ -0,0 +1,21 @@
....
##..
.#..
.#..
....
####
....
....
#...
###.
....
....
....
##..
.##.
....

19
tests/sample1.fillit Normal file
View file

@ -0,0 +1,19 @@
....
##..
.#..
.#..
..#.
###.
....
....
....
##..
##..
....
####
....
....
....

34
tests/sample2.fillit Normal file
View file

@ -0,0 +1,34 @@
####
....
....
....
####
....
....
....
####
....
....
....
####
....
....
....
####
....
....
....
####
....
....
....
####
....
....
....

19
tests/sample3.fillit Normal file
View file

@ -0,0 +1,19 @@
....
##..
.#..
.#..
....
####
....
....
#...
###.
....
....
....
##..
.##.
....

39
tests/sample4.fillit Normal file
View file

@ -0,0 +1,39 @@
...#
...#
...#
...#
....
....
....
####
.###
...#
....
....
....
..##
.##.
....
....
.##.
.##.
....
....
....
##..
.##.
##..
.#..
.#..
....
....
###.
.#..
....

4
tests/sample5.fillit Normal file
View file

@ -0,0 +1,4 @@
....
..##
.##.
....

119
tests/sample6.fillit Normal file
View file

@ -0,0 +1,119 @@
...#
...#
...#
...#
....
....
....
####
.###
...#
....
....
....
..##
.##.
....
....
.##.
.##.
....
....
....
##..
.##.
##..
.#..
.#..
....
....
###.
.#..
....
...#
...#
...#
...#
....
....
....
####
.###
...#
....
....
....
..##
.##.
....
....
.##.
.##.
....
....
....
##..
.##.
##..
.#..
.#..
....
....
###.
.#..
....
...#
...#
...#
...#
....
....
....
####
.###
...#
....
....
....
..##
.##.
....
....
.##.
.##.
....
....
....
##..
.##.
##..
.#..
.#..
....
....
###.
.#..
....