This commit is contained in:
Théophyl Hoguet committed 2021-12-09 20:42:04 +01:00
1 parent af17b34a9a
commit aac7da4685
8 files changed
+110 -207

No files matched your search

+1 -1
View File
@@ -45,7 +45,7 @@ BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 80
ColumnLimit: 160
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
+65 -124
View File
@@ -112,20 +112,15 @@ square game_get_flags(cgame g, uint i, uint j) {
}
bool game_is_blank(cgame g, uint i, uint j) {
return (g->tab_cell[i][j] == S_BLANK);
return game_get_state(g, i, j) == S_BLANK;
}
bool game_is_lightbulb(cgame g, uint i, uint j) {
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 | F_ERROR)));
return game_get_state(g, i, j) == S_LIGHTBULB;
}
bool game_is_black(cgame g, uint i, uint j) {
if (game_get_state(g, i, j) >= 8 && game_get_state(g, i, j) <= 13)
return true;
return false;
return game_get_state(g, i, j) >= S_BLACK0 && game_get_state(g, i, j) <= S_BLACKU;
}
int game_get_black_number(cgame g, uint i, uint j) {
@@ -135,33 +130,19 @@ int game_get_black_number(cgame g, uint i, uint j) {
}
bool game_is_marked(cgame g, uint i, uint j) {
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 | F_ERROR)));
return game_get_state(g, i, j) == S_MARK;
}
bool game_is_lighted(cgame g, uint i, uint j) {
if (g->tab_cell[i][j] >= F_ERROR) {
g->tab_cell[i][j] -= F_ERROR;
}
if (g->tab_cell[i][j] >= F_LIGHTED) {
return true;
}
return false;
return game_get_flags(g, i, j) >= F_LIGHTED;
}
bool game_has_error(cgame g, uint i, uint j) {
if (g->tab_cell[i][j] >= F_ERROR) {
return true;
}
return false;
return g->tab_cell[i][j] >= F_ERROR;
}
bool game_check_move(cgame g, uint i, uint j, square s) {
if (i >= DEFAULT_SIZE || j >= DEFAULT_SIZE ||
(s != S_BLANK && s != S_MARK && s != S_LIGHTBULB) ||
game_is_black(g, i, j))
if (i >= DEFAULT_SIZE || j >= DEFAULT_SIZE || (s != S_BLANK && s != S_MARK && s != S_LIGHTBULB) || game_is_black(g, i, j))
return false;
return true;
}
@@ -171,115 +152,78 @@ void game_play_move(game g, uint i, uint j, square s) {
game_update_flags(g);
}
void game_update_flags(game g) {
void delete_flags(game g) {
// delete prev flags
for (uint i = 0; i < DEFAULT_SIZE; i++) {
for (uint j = 0; j < DEFAULT_SIZE; j++) {
game_set_square(g, i, j, game_get_state(g, i, j));
}
}
}
void addF_LIGHTED(game g, uint i, uint j) {
square flags = game_get_flags(g, i, j);
if (flags == S_BLANK)
game_set_square(g, i, j, game_get_state(g, i, j) | F_LIGHTED);
else if (flags == F_ERROR) {
game_set_square(g, i, j, game_get_state(g, i, j) | F_LIGHTED | F_ERROR);
}
}
void game_update_flags(game g) {
delete_flags(g);
// update flags lighted and lightbulb error
for (uint i = 0; i < DEFAULT_SIZE; i++) {
for (uint j = 0; j < DEFAULT_SIZE; j++) {
for (int i = 0; i < DEFAULT_SIZE; i++) {
for (int j = 0; j < DEFAULT_SIZE; j++) {
if (game_get_state(g, i, j) == S_LIGHTBULB) {
if (game_get_flags(g, i, j) > 16)
game_set_square(g, i, j,
(S_LIGHTBULB | F_LIGHTED | F_ERROR));
else
game_set_square(g, i, j, (S_LIGHTBULB | F_LIGHTED));
for (uint i2 = i + 1;
i2 < DEFAULT_SIZE && !game_is_black(g, i2, j); i2++) {
if (game_get_state(g, i2, j) == S_LIGHTBULB)
// update initial lightbulb on F_ERROR
game_set_square(g, i, j,
(S_LIGHTBULB | F_LIGHTED | F_ERROR));
// update cases on FLIGHTED
game_set_square(g, i2, j,
(game_get_state(g, i2, j) | F_LIGHTED));
}
for (int i2 = i - 1; i2 >= 0 && !game_is_black(g, i2, j);
i2--) {
if (game_get_state(g, i2, j) == S_LIGHTBULB)
// update initial lightbulb on F_ERROR
game_set_square(g, i, j,
(S_LIGHTBULB | F_LIGHTED | F_ERROR));
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);
j2--) {
if (game_get_state(g, i, j2) == S_LIGHTBULB)
// update initial lightbulb on F_ERROR
game_set_square(g, i, j,
(S_LIGHTBULB | F_LIGHTED | F_ERROR));
game_set_square(g, i, j2,
(game_get_state(g, i, j2) | F_LIGHTED));
}
for (uint j2 = j + 1;
j2 < DEFAULT_SIZE && !game_is_black(g, i, j2); j2++) {
if (game_get_state(g, i, j2) == S_LIGHTBULB)
// update initial lightbulb on F_ERROR
game_set_square(g, i, j,
(S_LIGHTBULB | F_LIGHTED | F_ERROR));
game_set_square(g, i, j2,
(game_get_state(g, i, j2) | F_LIGHTED));
// add FLIGHTED to the current lightbulb
addF_LIGHTED(g, i, j);
// add FLIGHTED on the 4 directions, when a wall is hit stop this direction, when another lightbulb is hit put the initial lighbulb on error
int tab[] = {-1, 0, 1, 0, 0, -1, 0, 1};
for (int x = 1; x < DEFAULT_SIZE; x++) {
for (uint y = 0; y < 7; y = y + 2) {
if (tab[y] != tab[y + 1] && j + x * tab[y + 1] >= 0 && j + x * tab[y + 1] < DEFAULT_SIZE && i + x * tab[y] >= 0 &&
i + x * tab[y] < DEFAULT_SIZE) {
if (game_is_black(g, i + x * tab[y], j + x * tab[y + 1])) {
tab[y] = 0;
tab[y + 1] = 0;
} else {
// if we found another lightbulb on the line
if (game_get_state(g, i + x * tab[y], j + x * tab[y + 1]) == S_LIGHTBULB)
// update initial lightbulb on F_ERROR
game_set_square(g, i, j, (S_LIGHTBULB | F_LIGHTED | F_ERROR));
addF_LIGHTED(g, i + x * tab[y], j + x * tab[y + 1]);
}
}
}
}
}
}
}
// update flags wall
for (uint i = 0; i < DEFAULT_SIZE; i++) {
for (uint j = 0; j < DEFAULT_SIZE; j++) {
if (game_is_black(g, i, j)) {
if (game_get_black_number(g, i, j) >= 0) {
square choice[4];
int size = 0;
int lb = 0;
int notempty = 0;
if (i > 0) {
choice[size] = game_get_square(g, i - 1, j);
size++;
} else {
notempty++;
}
if (i < DEFAULT_SIZE - 1) {
choice[size] = game_get_square(g, i + 1, j);
size++;
} else {
notempty++;
}
if (j > 0) {
choice[size] = game_get_square(g, i, j - 1);
size++;
} else {
notempty++;
}
if (j < DEFAULT_SIZE - 1) {
choice[size] = game_get_square(g, i, j + 1);
size++;
} else {
notempty++;
}
for (int l = 0; l < size; l++) {
if (choice[l] == S_LIGHTBULB ||
choice[l] == (S_LIGHTBULB | F_LIGHTED) ||
choice[l] == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) {
// update flags wall (need to wait all FLIGHTED being updated)
for (int i = 0; i < DEFAULT_SIZE; i++) {
for (int j = 0; j < DEFAULT_SIZE; j++) {
if (game_is_black(g, i, j) && game_get_black_number(g, i, j) >= 0) {
int lb = 0;
int notempty = 0;
int tab[] = {-1, 0, 1, 0, 0, -1, 0, 1};
for (uint y = 0; y < 7; y = y + 2) {
if (j + tab[y + 1] >= 0 && j + tab[y + 1] < DEFAULT_SIZE && i + tab[y] >= 0 && i + tab[y] < DEFAULT_SIZE) {
if (game_is_lightbulb(g, i + tab[y], j + tab[y + 1]))
lb++;
} else if (choice[l] != S_BLANK) {
else if (!game_is_blank(g, i + tab[y], j + tab[y + 1]) || game_is_lighted(g, i + tab[y], j + tab[y + 1]))
notempty++;
}
}
if (lb > game_get_black_number(g, i, j)) {
game_set_square(g, i, j,
(game_get_state(g, i, j) | F_ERROR));
}
// look if there is enough empty cell around the wall
else if (notempty >
abs(game_get_black_number(g, i, j) - 4)) {
game_set_square(g, i, j,
(game_get_state(g, i, j) | F_ERROR));
} else {
notempty++;
}
}
if (lb > game_get_black_number(g, i, j)) {
game_set_square(g, i, j, (game_get_state(g, i, j) | F_ERROR));
}
// look if there is enough empty cell around the wall
else if (notempty > abs(game_get_black_number(g, i, j) - 4)) {
game_set_square(g, i, j, (game_get_state(g, i, j) | F_ERROR));
}
}
}
}
@@ -288,9 +232,7 @@ void game_update_flags(game g) {
bool game_is_over(cgame g) {
for (uint i = 0; i < DEFAULT_SIZE; i++) {
for (uint j = 0; j < DEFAULT_SIZE; j++) {
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 ||
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) == (F_LIGHTED | F_ERROR))
return false;
}
@@ -301,8 +243,7 @@ bool game_is_over(cgame g) {
void game_restart(game g) {
for (uint i = 0; i < DEFAULT_SIZE; i++) {
for (uint j = 0; j < DEFAULT_SIZE; j++) {
if (game_get_state(g, i, j) == S_MARK ||
game_get_state(g, i, j) == S_LIGHTBULB)
if (game_get_state(g, i, j) == S_MARK || game_get_state(g, i, j) == S_LIGHTBULB)
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.
**/
typedef enum {
/* states */
S_BLANK = 0, /**< a blank square */
S_LIGHTBULB = 1, /**< a light bulb */
S_MARK = 2, /**< a marked square (as not-a-light) */
S_BLACK = 8, /**< black wall base code */
S_BLACK0 = S_BLACK, /**< a numbered black wall (with 0 adjacent lights) */
S_BLACK1, /**< a numbered black wall (with 1 adjacent light) */
S_BLACK2, /**< a numbered black wall (with 2 adjacent lights) */
S_BLACK3, /**< a numbered black wall (with 3 adjacent lights) */
S_BLACK4, /**< a numbered black wall (with 4 adjacent lights) */
S_BLACKU, /**< an unnumbered black wall (any number of adjacent lights) */
/* flags */
F_LIGHTED = 16, /**< lighted flag */
F_ERROR = 32 /**< error flag */
/* states */
S_BLANK = 0, /**< a blank square */
S_LIGHTBULB = 1, /**< a light bulb */
S_MARK = 2, /**< a marked square (as not-a-light) */
S_BLACK = 8, /**< black wall base code */
S_BLACK0 = S_BLACK, /**< a numbered black wall (with 0 adjacent lights) */
S_BLACK1, /**< a numbered black wall (with 1 adjacent light) */
S_BLACK2, /**< a numbered black wall (with 2 adjacent lights) */
S_BLACK3, /**< a numbered black wall (with 3 adjacent lights) */
S_BLACK4, /**< a numbered black wall (with 4 adjacent lights) */
S_BLACKU, /**< an unnumbered black wall (any number of adjacent lights) */
/* flags */
F_LIGHTED = 16, /**< lighted flag */
F_ERROR = 32 /**< error flag */
} square;
/** state mask used in square enum */
@@ -61,14 +61,14 @@ typedef enum {
/**
* @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.
* @details That means that it is not possible to modify the game using this
* pointer.
**/
typedef const struct game_s *cgame;
typedef const struct game_s* cgame;
/**
* @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.
* @return the created game
**/
game game_new(square *squares);
game game_new(square* squares);
/**
* @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);
/**
* @brief Checks if a given move is legal.
* @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 ' ';
}
if ((sqState == S_LIGHTBULB) ||
(sqState == (S_LIGHTBULB | F_ERROR)) |
(sqState == (S_LIGHTBULB | F_LIGHTED)) |
(sqState == (S_LIGHTBULB | F_ERROR | F_LIGHTED))) {
(sqState == (S_LIGHTBULB | F_ERROR)) | (sqState == (S_LIGHTBULB | F_LIGHTED)) | (sqState == (S_LIGHTBULB | F_ERROR | F_LIGHTED))) {
return '*';
}
if ((sqState == S_MARK) ||
(sqState == (S_MARK | F_ERROR)) | (sqState == (S_MARK | F_LIGHTED))) {
if ((sqState == S_MARK) || (sqState == (S_MARK | F_ERROR)) | (sqState == (S_MARK | F_LIGHTED))) {
return '-';
}
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;
}
game_set_square(g, 0, 0, S_BLANK | F_LIGHTED | F_ERROR);
if ((game_get_flags(g, 0, 0) == (F_LIGHTED | F_ERROR)) &&
game_is_lighted(g, 0, 0)) {
if ((game_get_flags(g, 0, 0) == (F_LIGHTED | F_ERROR)) && game_is_lighted(g, 0, 0)) {
game_delete(g);
return true;
}
@@ -350,8 +349,7 @@ bool test_game_has_error(void) {
return true;
}
game_set_square(g, 0, 0, S_LIGHTBULB | F_LIGHTED | F_ERROR);
if ((game_get_flags(g, 0, 0) == (F_LIGHTED | F_ERROR)) &&
game_has_error(g, 0, 0)) {
if ((game_get_flags(g, 0, 0) == (F_LIGHTED | F_ERROR)) && game_has_error(g, 0, 0)) {
game_delete(g);
return true;
}
+21 -51
View File
@@ -58,9 +58,7 @@ bool test_game_restart(void) {
bool test_game_new(void) {
square tab[DEFAULT_SIZE * DEFAULT_SIZE];
game g;
square list[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK,
S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3,
S_BLACK4, S_BLACKU, F_ERROR};
square list[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK, 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++) {
g = NULL;
for (uint j = 0; j < DEFAULT_SIZE * DEFAULT_SIZE; j++) {
@@ -70,8 +68,7 @@ bool test_game_new(void) {
g = game_new(tab);
for (uint i2 = 0; i2 < DEFAULT_SIZE; i2++) {
for (uint j = 0; j < DEFAULT_SIZE; j++) {
printf("list :%d, get square :%d\n", list[i],
game_get_square(g, i2, j));
printf("list :%d, get square :%d\n", 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) {
square tab[DEFAULT_SIZE * DEFAULT_SIZE];
square list[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1,
S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU};
square list[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU};
game g;
for (uint i = 0; i < sizeof(list) / sizeof(list[0]); i++) {
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) {
game g;
square tab[DEFAULT_SIZE * DEFAULT_SIZE];
square list[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK,
S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3,
S_BLACK4, S_BLACKU, F_ERROR};
square list[] = {S_BLANK, S_LIGHTBULB, S_MARK, S_BLACK, 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 j = 0; j < DEFAULT_SIZE * DEFAULT_SIZE; j++) {
tab[j] = list[i];
g = game_new(tab);
printf(
"[%d, %d] %d %d\n", j / (DEFAULT_SIZE),
j - (j / (DEFAULT_SIZE)) -
(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]);
printf("[%d, %d] %d %d\n", j / (DEFAULT_SIZE), j - (j / (DEFAULT_SIZE)) - (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);
}
}
@@ -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
// by the bulb we are testing
if (game_is_lightbulb(g, i, j)) {
if (/*test if this lightbulb is well updated*/ flags == S_BLANK ||
flags == F_ERROR) {
if (/*test if this lightbulb is well updated*/ flags == S_BLANK || flags == F_ERROR) {
// printf("156\n");
return 0;
}
@@ -214,8 +198,7 @@ int checklightbulb(game g, uint i, uint j, bool wall) {
for (int i2 = i - 1; i2 >= 0; i2--) {
flags = game_get_square(g, i2, j);
// printf("i2:%d i2state:%d i2flags:%d\n",i2,state,flags);
if (flags == (S_LIGHTBULB | F_LIGHTED) ||
flags == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) {
if (flags == (S_LIGHTBULB | F_LIGHTED) || flags == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) {
return -1;
}
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++) {
flags = game_get_square(g, i2, j);
if (flags == (S_LIGHTBULB | F_LIGHTED) ||
flags == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) {
if (flags == (S_LIGHTBULB | F_LIGHTED) || flags == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) {
return -1;
}
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--) {
flags = game_get_square(g, i, j2);
if (flags == (S_LIGHTBULB | F_LIGHTED) ||
flags == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) {
if (flags == (S_LIGHTBULB | F_LIGHTED) || flags == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) {
return -1;
}
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++) {
flags = game_get_square(g, i, j2);
if (flags == (S_LIGHTBULB | F_LIGHTED) ||
flags == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) {
if (flags == (S_LIGHTBULB | F_LIGHTED) || flags == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) {
return -1;
}
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++) {
if (game_is_lightbulb(g, i, j)) {
square flags = game_get_flags(g, i, j);
if (/*test if this lightbulb is well updated*/ flags ==
S_BLANK ||
flags == F_ERROR) {
if (/*test if this lightbulb is well updated*/ flags == S_BLANK || flags == F_ERROR) {
// printf("196\n");
return false;
}
// loop checking every case before i
wall = false;
for (int k = i - 1; k >= 0; k--) {
if (/*test if current case is a wall*/ game_is_black(g, k,
j)) {
if (/*test if current case is a wall*/ game_is_black(g, k, j)) {
wall = true;
} else {
int tmp = checklightbulb(g, k, j, wall);
@@ -294,8 +271,7 @@ bool check_update(game g) {
}
wall = false;
for (int k = i + 1; k < DEFAULT_SIZE; k++) {
if (/*test if current case is a wall*/ game_is_black(g, k,
j)) {
if (/*test if current case is a wall*/ game_is_black(g, k, j)) {
wall = true;
} else {
int tmp = checklightbulb(g, k, j, wall);
@@ -309,8 +285,7 @@ bool check_update(game g) {
}
wall = false;
for (int k = j - 1; k >= 0; k--) {
if (/*test if current case is a wall*/ game_is_black(g, i,
k)) {
if (/*test if current case is a wall*/ game_is_black(g, i, k)) {
wall = true;
} else {
int tmp = checklightbulb(g, i, k, wall);
@@ -324,8 +299,7 @@ bool check_update(game g) {
}
wall = false;
for (int k = j + 1; k < DEFAULT_SIZE; k++) {
if (/*test if current case is a wall*/ game_is_black(g, i,
k)) {
if (/*test if current case is a wall*/ game_is_black(g, i, k)) {
wall = true;
} else {
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,
j)) {
} else if (/*test if current case is a wall*/ game_is_black(g, i, j)) {
if (game_get_black_number(g, i, j) != -1) {
// lookup for lightbulb and emptycells
size = 0;
@@ -370,8 +343,7 @@ bool check_update(game g) {
notempty++;
}
for (int l = 0; l < size; l++) {
if (choice[l] == (S_LIGHTBULB | F_LIGHTED) ||
choice[l] == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) {
if (choice[l] == (S_LIGHTBULB | F_LIGHTED) || choice[l] == (S_LIGHTBULB | F_LIGHTED | F_ERROR)) {
lb++;
} else if (choice[l] != S_BLANK) {
notempty++;
@@ -381,8 +353,7 @@ bool check_update(game g) {
res = false;
}
// look if there is enough empty cell around the wall
else if (notempty >
abs(game_get_black_number(g, i, j) - 4)) {
else if (notempty > abs(game_get_black_number(g, i, j) - 4)) {
res = false;
}
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");
exit(EXIT_FAILURE);
}
square list[] = {S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2,
S_BLACK3, S_BLACK4, S_BLACKU, S_BLANK};
square list[] = {S_LIGHTBULB, S_MARK, S_BLACK0, S_BLACK1, S_BLACK2, S_BLACK3, S_BLACK4, S_BLACKU, S_BLANK};
for (uint i = 0; i < DEFAULT_SIZE; i++) {
for (uint j = 0; j < DEFAULT_SIZE; 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() {
game g = game_new_empty();
game_set_square(g, 0, 0, S_LIGHTBULB);
if ((game_get_square(g, 0, 0) == S_LIGHTBULB) &&
game_is_lightbulb(g, 0, 0)) {
if ((game_get_square(g, 0, 0) == S_LIGHTBULB) && game_is_lightbulb(g, 0, 0)) {
game_delete(g);
return true;
}
+1 -2
View File
@@ -79,8 +79,7 @@ int main(void) {
return EXIT_SUCCESS;
} else if (c == 'l' || c == 'm' || c == 'b') {
if (scanf(" %u %u", &i, &j) == 2) {
if (i < DEFAULT_SIZE && j < DEFAULT_SIZE &&
!game_is_black(g, i, j)) {
if (i < DEFAULT_SIZE && j < DEFAULT_SIZE && !game_is_black(g, i, j)) {
if (c == 'l') {
game_set_square(g, i, j, S_LIGHTBULB);
game_update_flags(g);