update flags finished not sure if it works well

This commit is contained in:
Théophyl Hoguet committed 2021-11-29 20:36:20 +01:00
1 parent f98641b3ff
commit ae53f99df9
2 files changed
+99 -2

No files matched your search

+1 -1
View File
@@ -26,7 +26,7 @@ Projet Techno
| [game_has_error](./game.c#L?) | [bool game_has_error(cgame g, uint i, uint j)](./game.h#L240-252) | @nnunes | | <ul><li>[ ] </li></ul> |
| [game_check_move](./game.c#L122-128) | [bool game_check_move(cgame g, uint i, uint j, square s)](./game.h#L242-269) | @thoguet | | <ul><li>[X] </li></ul> |
| [game_play_move](./game.c#L130-133) | [void game_play_move(game g, uint i, uint j, square s)](./game.h#L271-284) | @thoguet | | <ul><li>[X] </li></ul> |
| [game_update_flags](./game.c#L?) | [void game_update_flags(game g)](./game.h#L145-406) | @thoguet | | <ul><li>[ ] </li></ul> |
| [game_update_flags](./game.c#L?135-234) | [void game_update_flags(game g)](./game.h#L145-406) | @thoguet | | <ul><li>[X] </li></ul> |
| [game_is_over](./game.c#L139-150) | [bool game_is_over(cgame g)](./game.h#L295-304) | @thoguet | | <ul><li>[X] </li></ul> |
| [game_restart](./game.c#L152-160) | [void game_restart(game g)](./game.h#L306-313) | @thoguet | | <ul><li>[X] </li></ul> |
+98 -1
View File
@@ -133,7 +133,104 @@ void game_play_move(game g, uint i, uint j, square s) {
}
void game_update_flags(game g) {
return;
// 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));
}
}
// update flags
for (uint i = 0; i < DEFAULT_SIZE; i++) {
for (uint j = 0; j < DEFAULT_SIZE; j++) {
if (game_get_state(g, i, j) == S_LIGHTBULB) {
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 (uint 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 (uint 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));
}
} else if (game_is_black(g, i, j)) {
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)) {
lb++;
} else if (choice[l] != S_BLANK) {
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));
}
}
}
}
}
bool game_is_over(cgame g) {