not finished WIP
This commit is contained in:
1 parent
f0d6f2e20e
commit
d9627ab957
2 files changed
+59
-16
No files matched your search
Vendored
+28
@@ -28,6 +28,34 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"preLaunchTask": "make_build"
|
"preLaunchTask": "make_build"
|
||||||
|
},{
|
||||||
|
"name": "(gdb) game_solve",
|
||||||
|
"type": "cppdbg",
|
||||||
|
"request": "launch",
|
||||||
|
"program": "${workspaceFolder}/build/game_solve",
|
||||||
|
"args": [
|
||||||
|
"-s gdefault.txt",
|
||||||
|
"gdefault.txt",
|
||||||
|
"gdefaultsol.txt"
|
||||||
|
],
|
||||||
|
"stopAtEntry": false,
|
||||||
|
"cwd": "${fileDirname}",
|
||||||
|
"environment": [],
|
||||||
|
"externalConsole": false,
|
||||||
|
"MIMode": "gdb",
|
||||||
|
"setupCommands": [
|
||||||
|
{
|
||||||
|
"description": "Enable pretty-printing for gdb",
|
||||||
|
"text": "-enable-pretty-printing",
|
||||||
|
"ignoreFailures": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "Set Disassembly Flavor to Intel",
|
||||||
|
"text": "-gdb-set disassembly-flavor intel",
|
||||||
|
"ignoreFailures": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"preLaunchTask": "make_build"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "(gdb) debug tests",
|
"name": "(gdb) debug tests",
|
||||||
|
|||||||
+31
-16
@@ -101,12 +101,26 @@ void game_save(cgame g, char* filename) {
|
|||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool game_has_error_general(cgame g) {
|
||||||
|
for (uint i = 0; i < game_nb_rows(g); i++) {
|
||||||
|
for (uint j = 0; j < game_nb_cols(g); j++) {
|
||||||
|
if (game_has_error(g, i, j))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool aux_game_solve(game g, uint deep) {
|
bool aux_game_solve(game g, uint deep) {
|
||||||
for (uint i = 0; i < game_nb_rows(g); i++) {
|
for (uint i = 0; i < game_nb_rows(g); i++) {
|
||||||
for (uint j = 0; j < game_nb_cols(g); j++) {
|
for (uint j = 0; j < game_nb_cols(g); j++) {
|
||||||
if (game_get_state(g, i, j) == S_BLANK) {
|
if (game_get_state(g, i, j) == S_BLANK) {
|
||||||
game_set_square(g, i, j, S_LIGHTBULB);
|
game_set_square(g, i, j, S_LIGHTBULB);
|
||||||
game_update_flags(g);
|
game_update_flags(g);
|
||||||
|
if (game_has_error_general(g)) {
|
||||||
|
game_set_square(g, i, j, S_BLANK);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if (game_is_over(g))
|
if (game_is_over(g))
|
||||||
return true;
|
return true;
|
||||||
if (deep > 1) {
|
if (deep > 1) {
|
||||||
@@ -127,14 +141,14 @@ void add_next_to(game g, uint i, uint j, square s) {
|
|||||||
if (/* normal check*/ (JNORMAL < game_nb_cols(g) && INORMAL < game_nb_rows(g)) ||
|
if (/* normal check*/ (JNORMAL < game_nb_cols(g) && INORMAL < game_nb_rows(g)) ||
|
||||||
/*wrapping check*/ (game_is_wrapping(g) &&
|
/*wrapping check*/ (game_is_wrapping(g) &&
|
||||||
/*not the same case*/ !(IWRAPPING == i && JWRAPPING == j))) {
|
/*not the same case*/ !(IWRAPPING == i && JWRAPPING == j))) {
|
||||||
if (game_get_state(g, IWRAPPING, JWRAPPING) == S_BLANK) {
|
if (game_get_state(g, IWRAPPING, JWRAPPING) == S_BLANK || game_get_state(g, IWRAPPING, JWRAPPING) == S_LIGHTBULB) {
|
||||||
game_set_square(g, IWRAPPING, JWRAPPING, s);
|
game_set_square(g, IWRAPPING, JWRAPPING, s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void game_analyze(game g) {
|
bool game_analyze(game g, uint deep) {
|
||||||
uint not_empty = 0;
|
uint not_empty = 0;
|
||||||
int dir[] = {1, 0, -1, 0, 0, 1, 0, -1};
|
int dir[] = {1, 0, -1, 0, 0, 1, 0, -1};
|
||||||
for (uint i = 0; i < game_nb_rows(g); i++) {
|
for (uint i = 0; i < game_nb_rows(g); i++) {
|
||||||
@@ -152,27 +166,28 @@ void game_analyze(game g) {
|
|||||||
}
|
}
|
||||||
if (not_empty == abs(game_get_black_number(g, i, j) - 4)) {
|
if (not_empty == abs(game_get_black_number(g, i, j) - 4)) {
|
||||||
add_next_to(g, i, j, S_LIGHTBULB);
|
add_next_to(g, i, j, S_LIGHTBULB);
|
||||||
|
game_update_flags(g);
|
||||||
|
if (game_analyze(g, deep))
|
||||||
|
return true;
|
||||||
|
add_next_to(g, i, j, S_BLANK);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
} else if (game_get_state(g, i, j) == S_BLACK0)
|
} else if (game_get_state(g, i, j) == S_BLACK0) {
|
||||||
add_next_to(g, i, j, S_MARK);
|
add_next_to(g, i, j, S_MARK);
|
||||||
|
game_update_flags(g);
|
||||||
|
if (game_analyze(g, deep))
|
||||||
|
return true;
|
||||||
|
add_next_to(g, i, j, S_BLANK);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return aux_game_solve(g, deep);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool game_solve(game g) {
|
bool game_solve(game g) {
|
||||||
game g_copy = game_copy(g);
|
for (uint deep = 1; deep < game_nb_cols(g) * game_nb_rows(g); deep++) {
|
||||||
game_analyze(g_copy);
|
if (game_analyze(g, deep)) {
|
||||||
if (game_is_over(g_copy)) {
|
|
||||||
game to_delete = g;
|
|
||||||
*g = *g_copy;
|
|
||||||
game_delete(to_delete);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
for (uint deep = 1; deep < game_nb_cols(g_copy) * game_nb_rows(g_copy); deep++) {
|
|
||||||
if (aux_game_solve(g_copy, deep)) {
|
|
||||||
game to_delete = g;
|
|
||||||
*g = *g_copy;
|
|
||||||
game_delete(to_delete);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user