update clang

This commit is contained in:
Théophyl Hoguet committed 2021-12-09 18:23:38 +01:00
1 parent 0c38152752
commit 7d826b6082
7 files changed
+72 -133

No files matched your search

+28 -51
View File
@@ -122,9 +122,7 @@ bool game_is_blank(cgame g, uint i, uint j) {
} }
bool game_is_lightbulb(cgame g, uint i, uint j) { bool game_is_lightbulb(cgame g, uint i, uint j) {
return ((g->tab_cell[i][j] == S_LIGHTBULB) || return ((g->tab_cell[i][j] == S_LIGHTBULB) || (g->tab_cell[i][j] == (S_LIGHTBULB | F_LIGHTED)) || (g->tab_cell[i][j] == (S_LIGHTBULB | F_ERROR)) ||
(g->tab_cell[i][j] == (S_LIGHTBULB | F_LIGHTED)) ||
(g->tab_cell[i][j] == (S_LIGHTBULB | F_ERROR)) ||
(g->tab_cell[i][j] == (S_LIGHTBULB | F_LIGHTED | F_ERROR))); (g->tab_cell[i][j] == (S_LIGHTBULB | F_LIGHTED | F_ERROR)));
} }
@@ -141,9 +139,7 @@ int game_get_black_number(cgame g, uint i, uint j) {
} }
bool game_is_marked(cgame g, uint i, uint j) { bool game_is_marked(cgame g, uint i, uint j) {
return ((g->tab_cell[i][j] == S_MARK) || return ((g->tab_cell[i][j] == S_MARK) || (g->tab_cell[i][j] == (S_MARK | F_LIGHTED)) || (g->tab_cell[i][j] == (S_MARK | F_ERROR)) ||
(g->tab_cell[i][j] == (S_MARK | F_LIGHTED)) ||
(g->tab_cell[i][j] == (S_MARK | F_ERROR)) ||
(g->tab_cell[i][j] == (S_MARK | F_LIGHTED | F_ERROR))); (g->tab_cell[i][j] == (S_MARK | F_LIGHTED | F_ERROR)));
} }
@@ -165,9 +161,7 @@ bool game_has_error(cgame g, uint i, uint j) {
} }
bool game_check_move(cgame g, uint i, uint j, square s) { bool game_check_move(cgame g, uint i, uint j, square s) {
if (i >= DEFAULT_SIZE || j >= DEFAULT_SIZE || if (i >= DEFAULT_SIZE || j >= DEFAULT_SIZE || (s != S_BLANK && s != S_MARK && s != S_LIGHTBULB) || game_is_black(g, i, j))
(s != S_BLANK && s != S_MARK && s != S_LIGHTBULB) ||
game_is_black(g, i, j))
return false; return false;
return true; return true;
} }
@@ -177,58 +171,49 @@ void game_play_move(game g, uint i, uint j, square s) {
game_update_flags(g); game_update_flags(g);
} }
void game_update_flags(game g) { void delete_flags(g) {
// delete prev flags // delete prev flags
for (uint i = 0; i < DEFAULT_SIZE; i++) { for (uint i = 0; i < DEFAULT_SIZE; i++) {
for (uint j = 0; j < DEFAULT_SIZE; j++) { for (uint j = 0; j < DEFAULT_SIZE; j++) {
game_set_square(g, i, j, game_get_state(g, i, j)); game_set_square(g, i, j, game_get_state(g, i, j));
} }
} }
}
void game_update_flags(game g) {
delete_flags(g);
// update flags lighted and lightbulb error // update flags lighted and lightbulb error
for (uint i = 0; i < DEFAULT_SIZE; i++) { for (uint i = 0; i < DEFAULT_SIZE; i++) {
for (uint j = 0; j < DEFAULT_SIZE; j++) { for (uint j = 0; j < DEFAULT_SIZE; j++) {
if (game_get_state(g, i, j) == S_LIGHTBULB) { if (game_get_state(g, i, j) == S_LIGHTBULB) {
if (game_get_flags(g, i, j) > 16) if (game_get_flags(g, i, j) == F_ERROR)
game_set_square(g, i, j, game_set_square(g, i, j, (S_LIGHTBULB | F_LIGHTED | F_ERROR));
(S_LIGHTBULB | F_LIGHTED | F_ERROR));
else else
game_set_square(g, i, j, (S_LIGHTBULB | F_LIGHTED)); game_set_square(g, i, j, (S_LIGHTBULB | F_LIGHTED));
for (uint i2 = i + 1; for (uint i2 = i + 1; i2 < DEFAULT_SIZE && !game_is_black(g, i2, j); i2++) {
i2 < DEFAULT_SIZE && !game_is_black(g, i2, j); i2++) {
if (game_get_state(g, i2, j) == S_LIGHTBULB) if (game_get_state(g, i2, j) == S_LIGHTBULB)
// update initial lightbulb on F_ERROR // update initial lightbulb on F_ERROR
game_set_square(g, i, j, game_set_square(g, i, j, (S_LIGHTBULB | F_LIGHTED | F_ERROR));
(S_LIGHTBULB | F_LIGHTED | F_ERROR));
// update cases on FLIGHTED // update cases on FLIGHTED
game_set_square(g, i2, j, game_set_square(g, i2, j, (game_get_state(g, i2, j) | F_LIGHTED));
(game_get_state(g, i2, j) | F_LIGHTED));
} }
for (int i2 = i - 1; i2 >= 0 && !game_is_black(g, i2, j); for (int i2 = i - 1; i2 >= 0 && !game_is_black(g, i2, j); i2--) {
i2--) {
if (game_get_state(g, i2, j) == S_LIGHTBULB) if (game_get_state(g, i2, j) == S_LIGHTBULB)
// update initial lightbulb on F_ERROR // update initial lightbulb on F_ERROR
game_set_square(g, i, j, game_set_square(g, i, j, (S_LIGHTBULB | F_LIGHTED | F_ERROR));
(S_LIGHTBULB | F_LIGHTED | F_ERROR)); game_set_square(g, i2, j, (game_get_state(g, i2, j) | F_LIGHTED));
game_set_square(g, i2, j,
(game_get_state(g, i2, j) | F_LIGHTED));
} }
for (int j2 = j - 1; j2 >= 0 && !game_is_black(g, i, j2); for (int j2 = j - 1; j2 >= 0 && !game_is_black(g, i, j2); j2--) {
j2--) {
if (game_get_state(g, i, j2) == S_LIGHTBULB) if (game_get_state(g, i, j2) == S_LIGHTBULB)
// update initial lightbulb on F_ERROR // update initial lightbulb on F_ERROR
game_set_square(g, i, j, game_set_square(g, i, j, (S_LIGHTBULB | F_LIGHTED | F_ERROR));
(S_LIGHTBULB | F_LIGHTED | F_ERROR)); game_set_square(g, i, j2, (game_get_state(g, i, j2) | F_LIGHTED));
game_set_square(g, i, j2,
(game_get_state(g, i, j2) | F_LIGHTED));
} }
for (uint j2 = j + 1; for (uint j2 = j + 1; j2 < DEFAULT_SIZE && !game_is_black(g, i, j2); j2++) {
j2 < DEFAULT_SIZE && !game_is_black(g, i, j2); j2++) {
if (game_get_state(g, i, j2) == S_LIGHTBULB) if (game_get_state(g, i, j2) == S_LIGHTBULB)
// update initial lightbulb on F_ERROR // update initial lightbulb on F_ERROR
game_set_square(g, i, j, game_set_square(g, i, j, (S_LIGHTBULB | F_LIGHTED | F_ERROR));
(S_LIGHTBULB | F_LIGHTED | F_ERROR)); game_set_square(g, i, j2, (game_get_state(g, i, j2) | F_LIGHTED));
game_set_square(g, i, j2,
(game_get_state(g, i, j2) | F_LIGHTED));
} }
} }
} }
@@ -267,23 +252,18 @@ void game_update_flags(game g) {
notempty++; notempty++;
} }
for (int l = 0; l < size; l++) { for (int l = 0; l < size; l++) {
if (choice[l] == S_LIGHTBULB || if (choice[l] == S_LIGHTBULB || choice[l] == (S_LIGHTBULB | F_LIGHTED) || choice[l] == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) {
choice[l] == (S_LIGHTBULB | F_LIGHTED) ||
choice[l] == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) {
lb++; lb++;
} else if (choice[l] != S_BLANK) { } else if (choice[l] != S_BLANK) {
notempty++; notempty++;
} }
} }
if (lb > game_get_black_number(g, i, j)) { if (lb > game_get_black_number(g, i, j)) {
game_set_square(g, i, j, game_set_square(g, i, j, (game_get_state(g, i, j) | F_ERROR));
(game_get_state(g, i, j) | F_ERROR));
} }
// look if there is enough empty cell around the wall // look if there is enough empty cell around the wall
else if (notempty > else if (notempty > abs(game_get_black_number(g, i, j) - 4)) {
abs(game_get_black_number(g, i, j) - 4)) { game_set_square(g, i, j, (game_get_state(g, i, j) | F_ERROR));
game_set_square(g, i, j,
(game_get_state(g, i, j) | F_ERROR));
} }
} }
} }
@@ -294,9 +274,7 @@ void game_update_flags(game g) {
bool game_is_over(cgame g) { bool game_is_over(cgame g) {
for (uint i = 0; i < DEFAULT_SIZE; i++) { for (uint i = 0; i < DEFAULT_SIZE; i++) {
for (uint j = 0; j < DEFAULT_SIZE; j++) { for (uint j = 0; j < DEFAULT_SIZE; j++) {
if ((game_get_state(g, i, j) == S_BLANK && if ((game_get_state(g, i, j) == S_BLANK && game_get_flags(g, i, j) == S_BLANK) || game_get_flags(g, i, j) == F_ERROR ||
game_get_flags(g, i, j) == S_BLANK) ||
game_get_flags(g, i, j) == F_ERROR ||
game_get_flags(g, i, j) == (F_LIGHTED | F_ERROR)) game_get_flags(g, i, j) == (F_LIGHTED | F_ERROR))
return false; return false;
} }
@@ -307,8 +285,7 @@ bool game_is_over(cgame g) {
void game_restart(game g) { void game_restart(game g) {
for (uint i = 0; i < DEFAULT_SIZE; i++) { for (uint i = 0; i < DEFAULT_SIZE; i++) {
for (uint j = 0; j < DEFAULT_SIZE; j++) { for (uint j = 0; j < DEFAULT_SIZE; j++) {
if (game_get_state(g, i, j) == S_MARK || if (game_get_state(g, i, j) == S_MARK || game_get_state(g, i, j) == S_LIGHTBULB)
game_get_state(g, i, j) == S_LIGHTBULB)
game_set_square(g, i, j, S_BLANK); game_set_square(g, i, j, S_BLANK);
} }
} }
+17 -18
View File
@@ -33,20 +33,20 @@ typedef unsigned int uint;
* https://en.wikipedia.org/wiki/Bitwise_operations_in_C. * https://en.wikipedia.org/wiki/Bitwise_operations_in_C.
**/ **/
typedef enum { typedef enum {
/* states */ /* states */
S_BLANK = 0, /**< a blank square */ S_BLANK = 0, /**< a blank square */
S_LIGHTBULB = 1, /**< a light bulb */ S_LIGHTBULB = 1, /**< a light bulb */
S_MARK = 2, /**< a marked square (as not-a-light) */ S_MARK = 2, /**< a marked square (as not-a-light) */
S_BLACK = 8, /**< black wall base code */ S_BLACK = 8, /**< black wall base code */
S_BLACK0 = S_BLACK, /**< a numbered black wall (with 0 adjacent lights) */ S_BLACK0 = S_BLACK, /**< a numbered black wall (with 0 adjacent lights) */
S_BLACK1, /**< a numbered black wall (with 1 adjacent light) */ S_BLACK1, /**< a numbered black wall (with 1 adjacent light) */
S_BLACK2, /**< a numbered black wall (with 2 adjacent lights) */ S_BLACK2, /**< a numbered black wall (with 2 adjacent lights) */
S_BLACK3, /**< a numbered black wall (with 3 adjacent lights) */ S_BLACK3, /**< a numbered black wall (with 3 adjacent lights) */
S_BLACK4, /**< a numbered black wall (with 4 adjacent lights) */ S_BLACK4, /**< a numbered black wall (with 4 adjacent lights) */
S_BLACKU, /**< an unnumbered black wall (any number of adjacent lights) */ S_BLACKU, /**< an unnumbered black wall (any number of adjacent lights) */
/* flags */ /* flags */
F_LIGHTED = 16, /**< lighted flag */ F_LIGHTED = 16, /**< lighted flag */
F_ERROR = 32 /**< error flag */ F_ERROR = 32 /**< error flag */
} square; } square;
/** state mask used in square enum */ /** state mask used in square enum */
@@ -61,14 +61,14 @@ typedef enum {
/** /**
* @brief The structure pointer that stores the game state. * @brief The structure pointer that stores the game state.
**/ **/
typedef struct game_s *game; typedef struct game_s* game;
/** /**
* @brief The structure constant pointer that stores the game state. * @brief The structure constant pointer that stores the game state.
* @details That means that it is not possible to modify the game using this * @details That means that it is not possible to modify the game using this
* pointer. * pointer.
**/ **/
typedef const struct game_s *cgame; typedef const struct game_s* cgame;
/** /**
* @brief Creates a new game with default size and initializes it. * @brief Creates a new game with default size and initializes it.
@@ -78,7 +78,7 @@ typedef const struct game_s *cgame;
* @pre @p squares must be an initialized array of default size squared. * @pre @p squares must be an initialized array of default size squared.
* @return the created game * @return the created game
**/ **/
game game_new(square *squares); game game_new(square* squares);
/** /**
* @brief Creates a new empty game with defaut size. * @brief Creates a new empty game with defaut size.
@@ -251,7 +251,6 @@ bool game_is_lighted(cgame g, uint i, uint j);
**/ **/
bool game_has_error(cgame g, uint i, uint j); bool game_has_error(cgame g, uint i, uint j);
/** /**
* @brief Checks if a given move is legal. * @brief Checks if a given move is legal.
* @details This function checks that it is possible to play a move at a given * @details This function checks that it is possible to play a move at a given
+2 -5
View File
@@ -7,13 +7,10 @@ char charPrintCell(square sqState) {
return ' '; return ' ';
} }
if ((sqState == S_LIGHTBULB) || if ((sqState == S_LIGHTBULB) ||
(sqState == (S_LIGHTBULB | F_ERROR)) | (sqState == (S_LIGHTBULB | F_ERROR)) | (sqState == (S_LIGHTBULB | F_LIGHTED)) | (sqState == (S_LIGHTBULB | F_ERROR | F_LIGHTED))) {
(sqState == (S_LIGHTBULB | F_LIGHTED)) |
(sqState == (S_LIGHTBULB | F_ERROR | F_LIGHTED))) {
return '*'; return '*';
} }
if ((sqState == S_MARK) || if ((sqState == S_MARK) || (sqState == (S_MARK | F_ERROR)) | (sqState == (S_MARK | F_LIGHTED))) {
(sqState == (S_MARK | F_ERROR)) | (sqState == (S_MARK | F_LIGHTED))) {
return '-'; return '-';
} }
if (sqState == S_BLACK0 || sqState == (S_BLACK0 | F_ERROR)) { if (sqState == S_BLACK0 || sqState == (S_BLACK0 | F_ERROR)) {
+2 -4
View File
@@ -332,8 +332,7 @@ bool test_game_is_lighted(void) {
return true; return true;
} }
game_set_square(g, 0, 0, S_BLANK | F_LIGHTED | F_ERROR); game_set_square(g, 0, 0, S_BLANK | F_LIGHTED | F_ERROR);
if ((game_get_flags(g, 0, 0) == (F_LIGHTED | F_ERROR)) && if ((game_get_flags(g, 0, 0) == (F_LIGHTED | F_ERROR)) && game_is_lighted(g, 0, 0)) {
game_is_lighted(g, 0, 0)) {
game_delete(g); game_delete(g);
return true; return true;
} }
@@ -350,8 +349,7 @@ bool test_game_has_error(void) {
return true; return true;
} }
game_set_square(g, 0, 0, S_LIGHTBULB | F_LIGHTED | F_ERROR); game_set_square(g, 0, 0, S_LIGHTBULB | F_LIGHTED | F_ERROR);
if ((game_get_flags(g, 0, 0) == (F_LIGHTED | F_ERROR)) && if ((game_get_flags(g, 0, 0) == (F_LIGHTED | F_ERROR)) && game_has_error(g, 0, 0)) {
game_has_error(g, 0, 0)) {
game_delete(g); game_delete(g);
return true; return true;
} }
+21 -51
View File
@@ -58,9 +58,7 @@ bool test_game_restart(void) {
bool test_game_new(void) { bool test_game_new(void) {
square tab[DEFAULT_SIZE * DEFAULT_SIZE]; square tab[DEFAULT_SIZE * DEFAULT_SIZE];
game g; game g;
square list[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK, square list[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU, F_ERROR};
S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3,
S_BLACK4, S_BLACKU, F_ERROR};
for (uint i = 0; i < sizeof(list) / sizeof(list[0]); i++) { for (uint i = 0; i < sizeof(list) / sizeof(list[0]); i++) {
g = NULL; g = NULL;
for (uint j = 0; j < DEFAULT_SIZE * DEFAULT_SIZE; j++) { for (uint j = 0; j < DEFAULT_SIZE * DEFAULT_SIZE; j++) {
@@ -70,8 +68,7 @@ bool test_game_new(void) {
g = game_new(tab); g = game_new(tab);
for (uint i2 = 0; i2 < DEFAULT_SIZE; i2++) { for (uint i2 = 0; i2 < DEFAULT_SIZE; i2++) {
for (uint j = 0; j < DEFAULT_SIZE; j++) { for (uint j = 0; j < DEFAULT_SIZE; j++) {
printf("list :%d, get square :%d\n", list[i], printf("list :%d, get square :%d\n", list[i], game_get_square(g, i2, j));
game_get_square(g, i2, j));
assert(list[i] == game_get_square(g, i2, j)); assert(list[i] == game_get_square(g, i2, j));
} }
} }
@@ -87,8 +84,7 @@ bool test_game_new(void) {
bool test_game_print(void) { bool test_game_print(void) {
square tab[DEFAULT_SIZE * DEFAULT_SIZE]; square tab[DEFAULT_SIZE * DEFAULT_SIZE];
square list[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, square list[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU};
S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU};
game g; game g;
for (uint i = 0; i < sizeof(list) / sizeof(list[0]); i++) { for (uint i = 0; i < sizeof(list) / sizeof(list[0]); i++) {
for (uint j = 0; j < DEFAULT_SIZE * DEFAULT_SIZE; j++) { for (uint j = 0; j < DEFAULT_SIZE * DEFAULT_SIZE; j++) {
@@ -108,25 +104,14 @@ bool test_game_print(void) {
bool test_game_get_square(void) { bool test_game_get_square(void) {
game g; game g;
square tab[DEFAULT_SIZE * DEFAULT_SIZE]; square tab[DEFAULT_SIZE * DEFAULT_SIZE];
square list[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK, square list[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU, F_ERROR};
S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3,
S_BLACK4, S_BLACKU, F_ERROR};
for (uint i = 0; i < sizeof(list) / sizeof(list[0]); i++) { for (uint i = 0; i < sizeof(list) / sizeof(list[0]); i++) {
for (uint j = 0; j < DEFAULT_SIZE * DEFAULT_SIZE; j++) { for (uint j = 0; j < DEFAULT_SIZE * DEFAULT_SIZE; j++) {
tab[j] = list[i]; tab[j] = list[i];
g = game_new(tab); g = game_new(tab);
printf( printf("[%d, %d] %d %d\n", j / (DEFAULT_SIZE), j - (j / (DEFAULT_SIZE)) - (j / (DEFAULT_SIZE) * (DEFAULT_SIZE - 1)),
"[%d, %d] %d %d\n", j / (DEFAULT_SIZE), game_get_square(g, j / (DEFAULT_SIZE), j - (j / (DEFAULT_SIZE)) - (j / (DEFAULT_SIZE) * (DEFAULT_SIZE - 1))), tab[j]);
j - (j / (DEFAULT_SIZE)) - assert(game_get_square(g, j / (DEFAULT_SIZE), j - (j / (DEFAULT_SIZE)) - (j / (DEFAULT_SIZE) * (DEFAULT_SIZE - 1))) == tab[j]);
(j / (DEFAULT_SIZE) * (DEFAULT_SIZE - 1)),
game_get_square(g, j / (DEFAULT_SIZE),
j - (j / (DEFAULT_SIZE)) -
(j / (DEFAULT_SIZE) * (DEFAULT_SIZE - 1))),
tab[j]);
assert(game_get_square(g, j / (DEFAULT_SIZE),
j - (j / (DEFAULT_SIZE)) -
(j / (DEFAULT_SIZE) *
(DEFAULT_SIZE - 1))) == tab[j]);
game_delete(g); game_delete(g);
} }
} }
@@ -192,8 +177,7 @@ int checklightbulb(game g, uint i, uint j, bool wall) {
// if true we can break the loop because every others cases wont be lighted // if true we can break the loop because every others cases wont be lighted
// by the bulb we are testing // by the bulb we are testing
if (game_is_lightbulb(g, i, j)) { if (game_is_lightbulb(g, i, j)) {
if (/*test if this lightbulb is well updated*/ flags == S_BLANK || if (/*test if this lightbulb is well updated*/ flags == S_BLANK || flags == F_ERROR) {
flags == F_ERROR) {
// printf("156\n"); // printf("156\n");
return 0; return 0;
} }
@@ -214,8 +198,7 @@ int checklightbulb(game g, uint i, uint j, bool wall) {
for (int i2 = i - 1; i2 >= 0; i2--) { for (int i2 = i - 1; i2 >= 0; i2--) {
flags = game_get_square(g, i2, j); flags = game_get_square(g, i2, j);
// printf("i2:%d i2state:%d i2flags:%d\n",i2,state,flags); // printf("i2:%d i2state:%d i2flags:%d\n",i2,state,flags);
if (flags == (S_LIGHTBULB | F_LIGHTED) || if (flags == (S_LIGHTBULB | F_LIGHTED) || flags == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) {
flags == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) {
return -1; return -1;
} }
if (flags != F_LIGHTED && flags != (F_LIGHTED | S_MARK)) { if (flags != F_LIGHTED && flags != (F_LIGHTED | S_MARK)) {
@@ -224,8 +207,7 @@ int checklightbulb(game g, uint i, uint j, bool wall) {
} }
for (int i2 = i + 1; i2 < DEFAULT_SIZE; i2++) { for (int i2 = i + 1; i2 < DEFAULT_SIZE; i2++) {
flags = game_get_square(g, i2, j); flags = game_get_square(g, i2, j);
if (flags == (S_LIGHTBULB | F_LIGHTED) || if (flags == (S_LIGHTBULB | F_LIGHTED) || flags == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) {
flags == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) {
return -1; return -1;
} }
if (flags != F_LIGHTED && flags != (F_LIGHTED | S_MARK)) { if (flags != F_LIGHTED && flags != (F_LIGHTED | S_MARK)) {
@@ -234,8 +216,7 @@ int checklightbulb(game g, uint i, uint j, bool wall) {
} }
for (int j2 = j - 1; j2 >= 0; j2--) { for (int j2 = j - 1; j2 >= 0; j2--) {
flags = game_get_square(g, i, j2); flags = game_get_square(g, i, j2);
if (flags == (S_LIGHTBULB | F_LIGHTED) || if (flags == (S_LIGHTBULB | F_LIGHTED) || flags == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) {
flags == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) {
return -1; return -1;
} }
if (flags != F_LIGHTED && flags != (F_LIGHTED | S_MARK)) { if (flags != F_LIGHTED && flags != (F_LIGHTED | S_MARK)) {
@@ -244,8 +225,7 @@ int checklightbulb(game g, uint i, uint j, bool wall) {
} }
for (int j2 = j + 1; j2 < DEFAULT_SIZE; j2++) { for (int j2 = j + 1; j2 < DEFAULT_SIZE; j2++) {
flags = game_get_square(g, i, j2); flags = game_get_square(g, i, j2);
if (flags == (S_LIGHTBULB | F_LIGHTED) || if (flags == (S_LIGHTBULB | F_LIGHTED) || flags == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) {
flags == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) {
return -1; return -1;
} }
if (flags != F_LIGHTED && flags != (F_LIGHTED | S_MARK)) { if (flags != F_LIGHTED && flags != (F_LIGHTED | S_MARK)) {
@@ -270,17 +250,14 @@ bool check_update(game g) {
for (uint j = 0; j < DEFAULT_SIZE; j++) { for (uint j = 0; j < DEFAULT_SIZE; j++) {
if (game_is_lightbulb(g, i, j)) { if (game_is_lightbulb(g, i, j)) {
square flags = game_get_flags(g, i, j); square flags = game_get_flags(g, i, j);
if (/*test if this lightbulb is well updated*/ flags == if (/*test if this lightbulb is well updated*/ flags == S_BLANK || flags == F_ERROR) {
S_BLANK ||
flags == F_ERROR) {
// printf("196\n"); // printf("196\n");
return false; return false;
} }
// loop checking every case before i // loop checking every case before i
wall = false; wall = false;
for (int k = i - 1; k >= 0; k--) { for (int k = i - 1; k >= 0; k--) {
if (/*test if current case is a wall*/ game_is_black(g, k, if (/*test if current case is a wall*/ game_is_black(g, k, j)) {
j)) {
wall = true; wall = true;
} else { } else {
int tmp = checklightbulb(g, k, j, wall); int tmp = checklightbulb(g, k, j, wall);
@@ -294,8 +271,7 @@ bool check_update(game g) {
} }
wall = false; wall = false;
for (int k = i + 1; k < DEFAULT_SIZE; k++) { for (int k = i + 1; k < DEFAULT_SIZE; k++) {
if (/*test if current case is a wall*/ game_is_black(g, k, if (/*test if current case is a wall*/ game_is_black(g, k, j)) {
j)) {
wall = true; wall = true;
} else { } else {
int tmp = checklightbulb(g, k, j, wall); int tmp = checklightbulb(g, k, j, wall);
@@ -309,8 +285,7 @@ bool check_update(game g) {
} }
wall = false; wall = false;
for (int k = j - 1; k >= 0; k--) { for (int k = j - 1; k >= 0; k--) {
if (/*test if current case is a wall*/ game_is_black(g, i, if (/*test if current case is a wall*/ game_is_black(g, i, k)) {
k)) {
wall = true; wall = true;
} else { } else {
int tmp = checklightbulb(g, i, k, wall); int tmp = checklightbulb(g, i, k, wall);
@@ -324,8 +299,7 @@ bool check_update(game g) {
} }
wall = false; wall = false;
for (int k = j + 1; k < DEFAULT_SIZE; k++) { for (int k = j + 1; k < DEFAULT_SIZE; k++) {
if (/*test if current case is a wall*/ game_is_black(g, i, if (/*test if current case is a wall*/ game_is_black(g, i, k)) {
k)) {
wall = true; wall = true;
} else { } else {
int tmp = checklightbulb(g, i, k, wall); int tmp = checklightbulb(g, i, k, wall);
@@ -337,8 +311,7 @@ bool check_update(game g) {
} }
} }
} }
} else if (/*test if current case is a wall*/ game_is_black(g, i, } else if (/*test if current case is a wall*/ game_is_black(g, i, j)) {
j)) {
if (game_get_black_number(g, i, j) != -1) { if (game_get_black_number(g, i, j) != -1) {
// lookup for lightbulb and emptycells // lookup for lightbulb and emptycells
size = 0; size = 0;
@@ -370,8 +343,7 @@ bool check_update(game g) {
notempty++; notempty++;
} }
for (int l = 0; l < size; l++) { for (int l = 0; l < size; l++) {
if (choice[l] == (S_LIGHTBULB | F_LIGHTED) || if (choice[l] == (S_LIGHTBULB | F_LIGHTED) || choice[l] == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) {
choice[l] == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) {
lb++; lb++;
} else if (choice[l] != S_BLANK) { } else if (choice[l] != S_BLANK) {
notempty++; notempty++;
@@ -381,8 +353,7 @@ bool check_update(game g) {
res = false; res = false;
} }
// look if there is enough empty cell around the wall // look if there is enough empty cell around the wall
else if (notempty > else if (notempty > abs(game_get_black_number(g, i, j) - 4)) {
abs(game_get_black_number(g, i, j) - 4)) {
res = false; res = false;
} }
if (game_get_flags(g, i, j) == F_ERROR) { if (game_get_flags(g, i, j) == F_ERROR) {
@@ -410,8 +381,7 @@ bool brutforce(game g, int a, bool* deldup) {
fprintf(stderr, "Not enought memory\n"); fprintf(stderr, "Not enought memory\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
square list[] = {S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, square list[] = {S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU, S_BLANK};
S_BLACK3, S_BLACK4, S_BLACKU, S_BLANK};
for (uint i = 0; i < DEFAULT_SIZE; i++) { for (uint i = 0; i < DEFAULT_SIZE; i++) {
for (uint j = 0; j < DEFAULT_SIZE; j++) { for (uint j = 0; j < DEFAULT_SIZE; j++) {
// printf("state: %d i:%d j:%d\n",game_get_state(g,i,j),i,j); // printf("state: %d i:%d j:%d\n",game_get_state(g,i,j),i,j);
+1 -2
View File
@@ -122,8 +122,7 @@ bool test_game_is_black() {
bool test_game_is_lightbulb() { bool test_game_is_lightbulb() {
game g = game_new_empty(); game g = game_new_empty();
game_set_square(g, 0, 0, S_LIGHTBULB); game_set_square(g, 0, 0, S_LIGHTBULB);
if ((game_get_square(g, 0, 0) == S_LIGHTBULB) && if ((game_get_square(g, 0, 0) == S_LIGHTBULB) && game_is_lightbulb(g, 0, 0)) {
game_is_lightbulb(g, 0, 0)) {
game_delete(g); game_delete(g);
return true; return true;
} }
+1 -2
View File
@@ -79,8 +79,7 @@ int main(void) {
return EXIT_SUCCESS; return EXIT_SUCCESS;
} else if (c == 'l' || c == 'm' || c == 'b') { } else if (c == 'l' || c == 'm' || c == 'b') {
if (scanf(" %u %u", &i, &j) == 2) { if (scanf(" %u %u", &i, &j) == 2) {
if (i < DEFAULT_SIZE && j < DEFAULT_SIZE && if (i < DEFAULT_SIZE && j < DEFAULT_SIZE && !game_is_black(g, i, j)) {
!game_is_black(g, i, j)) {
if (c == 'l') { if (c == 'l') {
game_set_square(g, i, j, S_LIGHTBULB); game_set_square(g, i, j, S_LIGHTBULB);
game_update_flags(g); game_update_flags(g);