piscine-rush01/ex00/backtrack.c

71 lines
955 B
C

#include "helpers.h"
#include "backtrack.h"
#include <stdio.h>
int is_solved(int board[SIZE][SIZE])
{
int i;
int j;
i = 0;
while (i < SIZE)
{
j = 0;
while (j < SIZE)
{
if (!board[i][j])
return (0);
j++;
}
i++;
}
return (1);
}
int next_cell_pos(int board[SIZE][SIZE])
{
int pos;
pos = 0;
while (board[pos / SIZE][pos % SIZE])
pos++;
return (pos);
}
void *get_candidates(int board[SIZE][SIZE], int next_cell)
{
return (0);
}
int backtrack(int board[SIZE][SIZE], int clues[SIZE * 4])
{
int next_cell;
void *candidates;
if (is_solved(board))
return (1);
next_cell = next_cell_pos(board);
candidates = get_candidates(board, next_cell);
printf("%d\n", candidates[0];
return (0);
}
void print_board(int board[SIZE][SIZE])
{
int i;
int j;
i = -1;
while (++i < SIZE)
{
j = -1;
while (++j < SIZE)
{
ft_putchar(board[i][j] + '0');
ft_putchar(' ');
}
ft_putchar('\b');
ft_putchar('\n');
}
}