-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.c
84 lines (75 loc) · 1.84 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* map.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kfonda <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/28 01:34:34 by kfonda #+# #+# */
/* Updated: 2018/11/28 01:34:36 by kfonda ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
int ft_getminmapsize(int tetricount)
{
int square;
square = 1;
while (square * square < tetricount * 4)
square++;
return (square);
}
char **ft_setmap(int size)
{
char **map;
int i;
i = -1;
if (!(map = malloc(sizeof(char*) * (size + 1))))
return (NULL);
while (++i < size)
{
if (!(map[i] = malloc(sizeof(char) * (size + 1))))
{
ft_free2d(map, size);
return (NULL);
}
map[i][size] = '\0';
}
map[size] = NULL;
return (map);
}
void ft_mapinitalise(char **map, int size)
{
int x;
int y;
x = -1;
y = -1;
while (++x < size)
{
while (++y < size)
map[x][y] = '.';
y = -1;
}
}
char **ft_increasemap(char **map, int size)
{
char **new;
int x;
int y;
new = ft_setmap(size + 1);
x = -1;
y = -1;
while (++x < size)
{
while (++y < size)
new[x][y] = map[x][y];
free(map[x]);
y = -1;
}
x = -1;
while (++y < size)
new[y][size] = '.';
while (++x <= size)
new[size][x] = '.';
free(map);
return (new);
}