-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfonctions.h
94 lines (72 loc) · 2.9 KB
/
fonctions.h
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
86
87
88
89
90
91
92
93
94
/* JEANNE-ROSE Méven
04/05/22
fonctions.h
Performs calculations on array and display in the console
*/
#ifndef _FONCTION_H
#define _FONCTION_H
#include <stdint.h>
#include <stdio.h>
#define MAX_NB_RECURS 100
#define NB_POSSIBLE_VALUES_UNINIT 0x7F
#define NO_POSSIBILITY_AND_NO_VALUE 42
#define REACH_MAX_NB_RECURS 27
#define DEBUG 0
#if DEBUG
#define DEBUG_LOG(x) {printf(x);}
#else
#define DEBUG_LOG(x)
#endif
/* Structure représentant une case contenant une valeur, nombre de possibilités, etc.*/
struct Cellule{
uint16_t valeurs_possibles : 9;
uint16_t nombre_possibilites : 7;
uint8_t valeur;
uint8_t padding;
};
extern uint8_t g_ti [9][9];
extern struct Cellule g_tableau[9][9];
extern uint8_t recurs;
/*Without GTK, mainly debugging purpose*/
void main_console(void);
/********DISPLAY*******/
/*Display Stuct Cellule array values in the console*/
void Affichage(struct Cellule const[9][9]);
/*Init struct Cellule array with an array
@return Number of cells to find
*/
uint8_t init_array(struct Cellule[9][9], uint8_t const tab[9][9]);
/*calculate and Fill "valeurs_possibles" field of the struct
@return minimum number of possibilities*/
uint8_t calcul_valeurs_possibles(struct Cellule[9][9], uint8_t *ligne, uint8_t *colonne);
/*Update number of possibilities thanks to number of bits set in "valeurs_possibles" field
@return number of possibilities
*/
uint8_t update_nb_possibilites(struct Cellule*);
/*Compute possible value of each element line by line
@return 0 or 42 if no possibility*/
uint16_t calcul_valeurs_possibles_selon_ligne(struct Cellule[9][9]);
/*Compute possible value of each element column by column
@return 0 or 42 if no possibility*/
uint16_t calcul_valeurs_possibles_selon_colonne(struct Cellule[9][9]);
/*Compute possible value of each element block by block
@return minimum number of possibility*/
uint16_t calcul_valeurs_possibles_selon_block(struct Cellule[9][9], uint8_t*, uint8_t*);
/*Compute possible value of cells inside block
@return min number of possibilities of the corresponding block*/
void update_block(uint8_t block_number,uint8_t *ligne, uint8_t *colonne, struct Cellule array[9][9], uint16_t*);
/*display bits field "valeurs possibles"*/
void affiche_valeurs_possibles(const struct Cellule);
/*Entry point with console mode
@return 0 success 42 wrong branch 27 max number of recursivity reach
*/
uint8_t resolution(struct Cellule[9][9]);
/*Set value for a cell when it has only one possibility or to try a branch (sets the 1st possibility) with console mode
@return The value set, 0 otherwise
*/
uint8_t set_value(struct Cellule*);
/*Create a new struct cellule array. Used for recursivity*/
void copy_cell_array(const struct Cellule origin[9][9], struct Cellule new[9][9]);
/*Reset "valeur_possible" and "nombre_possibilite" field*/
void clean_array(struct Cellule array[9][9]);
#endif