blob: df4bc85d065c84b1e1946ec36bd6224df1b54c41 (
plain)
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
|
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* algo.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: samzur <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/22 12:32:19 by samzur #+# #+# */
/* Updated: 2019/07/24 09:38:57 by samzur ### ########.fr */
/* */
/* ************************************************************************** */
#include "include.h"
int ft_min(int nb1, int nb2, int nb3)
{
int minimum;
minimum = nb1;
if (minimum > nb2)
minimum = nb2;
if (minimum > nb3)
minimum = nb3;
return (minimum);
}
t_cell solve(t_terrain *terrain)
{
t_cell result;
int x;
int y;
y = -1;
result.y = 0;
result.x = 0;
result.value = 0;
while (++y < terrain->rows)
{
x = -1;
while (++x < terrain->columns)
{
if (terrain->matrix[y][x] > OBSTACLE && x != 0 && y != 0)
terrain->matrix[y][x] = 1 + ft_min(terrain->matrix[y - 1][x],
terrain->matrix[y][x - 1], terrain->matrix[y - 1][x - 1]);
if (terrain->matrix[y][x] > result.value)
{
result.value = terrain->matrix[y][x];
result.y = y;
result.x = x;
}
}
}
return (result);
}
void solve_and_complete(t_terrain *terrain)
{
t_cell result;
int row;
int column;
result = solve(terrain);
column = result.x;
while (column >= (result.x - result.value + 1))
{
row = result.y;
while (row >= (result.y - result.value + 1))
{
terrain->matrix[row][column] = FILLED;
row--;
}
column--;
}
}
|