1
0
This repository has been archived on 2024-10-25. You can view files and clone it, but cannot push or open issues or pull requests.
2023-08-06 20:12:38 +02:00

139 lines
2.6 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* checks.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kjimenez <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/07/24 14:33:44 by kjimenez #+# #+# */
/* Updated: 2022/07/24 15:14:35 by kjimenez ### ########.fr */
/* */
/* ************************************************************************** */
int left_to_right(int **arr_answer, int row, int expected)
{
int i;
int j;
int count;
int if_increasing;
i = 0;
count = 1;
while (arr_answer[row][i] <= 3)
{
j = i;
if_increasing = i;
while (j > 0)
{
if (arr_answer[row][i] > arr_answer[row][j - 1])
if_increasing--;
j--;
}
if (j == if_increasing)
count++;
i++;
}
return (count == expected);
}
int up_to_down(int **arr_answer, int col, int expected)
{
int i;
int j;
int count;
int if_increasing;
i = 0;
count = 1;
while (i < 4 && arr_answer[i][col] <= 3)
{
j = i;
if_increasing = i;
while (j > 0)
{
if (arr_answer[i][col] > arr_answer[j - 1][col])
if_increasing--;
j--;
}
if (j == if_increasing)
count++;
i++;
}
return (count == expected);
}
int right_to_left(int **arr_answer, int row, int expected)
{
int i;
int j;
int count;
int if_increasing;
i = 3;
count = 1;
while (arr_answer[row][i] <= 3)
{
j = i;
if_increasing = i;
while (j < 3)
{
if (arr_answer[row][i] > arr_answer[row][j + 1])
if_increasing++;
j++;
}
if (j == if_increasing)
count++;
i--;
}
return (count == expected);
}
int down_to_up(int **arr_answer, int col, int expected)
{
int i;
int j;
int count;
int if_increasing;
i = 3;
count = 1;
while (i > 0 && arr_answer[i][col] <= 3)
{
j = i;
if_increasing = i;
while (j < 3)
{
if (arr_answer[i][col] > arr_answer[j + 1][col])
if_increasing++;
j++;
}
if (j == if_increasing)
count++;
i--;
}
return (count == expected);
}
int check_duplicates(int **board)
{
int i;
int j;
int k;
i = -1;
while (++i < 4)
{
j = -1;
while (++j < 4)
{
k = j;
while (++k < 4)
{
if (board[j][i] == board[k][i])
return (0);
}
}
}
return (1);
}