This repository was archived by the owner on Feb 27, 2021. It is now read-only.
forked from giacomoguiulfo/42-fillit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.c
85 lines (75 loc) · 1.83 KB
/
map.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* map.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jkalia <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/03/08 09:44:19 by jkalia #+# #+# */
/* Updated: 2017/03/10 12:51:55 by jkalia ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
void print_map(char **map, size_t size)
{
size_t i;
i = 0;
while (i < size)
{
ft_putstr(map[i]);
ft_putchar('\n');
++i;
}
}
void delete_map(char **map)
{
size_t i;
i = 0;
while (map[i])
{
free(map[i]);
++i;
}
free(map);
}
char **new_map(size_t size)
{
int i;
int j;
int n_size;
char **map;
n_size = size + 3;
CHK((map = (char **)malloc(sizeof(char*) * (n_size + 1))) == 0, 0);
ft_bzero(map, n_size);
i = -1;
while (++i < (int)size)
{
CHK1((map[i] = ft_strnew(n_size)) == 0, delete_map(map), 0);
j = -1;
while (++j < (int)size)
map[i][j] = '.';
}
while (i < n_size)
{
CHK1((map[i] = ft_strnew(n_size)) == 0, delete_map(map), 0);
++i;
}
map[i] = 0;
return (map);
}
size_t initial_board_size(size_t nb_blocks)
{
size_t min_size;
size_t i;
i = 2;
min_size = nb_blocks * 4;
while (min_size > (i * i))
i++;
return (i);
}
char get_letter(char *str)
{
while (*str == '.')
str++;
return (*str);
}