opti + memory leak fixed
This commit is contained in:
1 parent
0f88c8a773
commit
f61621a927
2 files changed
+27
-55
No files matched your search
+8
-35
@@ -2,39 +2,13 @@
|
||||
#include <stdio.h>
|
||||
#include "game.h"
|
||||
|
||||
char charPrintCell(square sqState) {
|
||||
if (sqState == S_BLANK) {
|
||||
return ' ';
|
||||
}
|
||||
if ((sqState == S_LIGHTBULB) ||
|
||||
(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))) {
|
||||
return '-';
|
||||
}
|
||||
if (sqState == S_BLACK0 || sqState == (S_BLACK0 | F_ERROR)) {
|
||||
return '0';
|
||||
}
|
||||
if (sqState == S_BLACK1 || sqState == (S_BLACK1 | F_ERROR)) {
|
||||
return '1';
|
||||
}
|
||||
if (sqState == S_BLACK2 || sqState == (S_BLACK2 | F_ERROR)) {
|
||||
return '2';
|
||||
}
|
||||
if (sqState == S_BLACK3 || sqState == (S_BLACK3 | F_ERROR)) {
|
||||
return '3';
|
||||
}
|
||||
if (sqState == S_BLACK4 || sqState == (S_BLACK4 | F_ERROR)) {
|
||||
return '4';
|
||||
}
|
||||
if (sqState == S_BLACKU || sqState == (S_BLACKU | F_ERROR)) {
|
||||
return 'w';
|
||||
}
|
||||
if (sqState == F_LIGHTED) {
|
||||
return '.';
|
||||
}
|
||||
return -1;
|
||||
char charPrintCell(cgame g, uint i, uint j) {
|
||||
square sqState = game_get_state(g, i, j);
|
||||
square sqFlags = game_get_flags(g, i, j);
|
||||
char tab[] = {' ', '*', '-', '?', '?', '?', '?', '?', '0', '1', '2', '3', '4', 'w', '?', '?', '.'};
|
||||
if (!sqState)
|
||||
return tab[sqFlags];
|
||||
return tab[sqState];
|
||||
}
|
||||
|
||||
void game_print(cgame g) {
|
||||
@@ -52,7 +26,7 @@ void game_print(cgame g) {
|
||||
for (i = 0; i < DEFAULT_SIZE; i++) {
|
||||
printf("%u |", i);
|
||||
for (uint j = 0; j < DEFAULT_SIZE; j++) {
|
||||
printf("%c", charPrintCell(game_get_square(g, i, j)));
|
||||
printf("%c", charPrintCell(g, i, j));
|
||||
}
|
||||
printf("|\n");
|
||||
}
|
||||
@@ -88,6 +62,5 @@ game game_default_solution(void) {
|
||||
game_set_square(g, 5, 0, S_LIGHTBULB);
|
||||
game_set_square(g, 5, 5, S_LIGHTBULB);
|
||||
game_set_square(g, 6, 1, S_LIGHTBULB);
|
||||
game_update_flags(g);
|
||||
return g;
|
||||
}
|
||||
+19
-20
@@ -4,7 +4,7 @@
|
||||
#include "game.h"
|
||||
#include "game_aux.h"
|
||||
|
||||
bool checkerr(game g, char taberr[]) {
|
||||
bool checkerr(cgame g, char taberr[]) {
|
||||
if (taberr == NULL || g == NULL) {
|
||||
return -1;
|
||||
}
|
||||
@@ -74,36 +74,35 @@ int main(void) {
|
||||
game_print(g);
|
||||
} else if (c == 'q') {
|
||||
printf("Solution: \n");
|
||||
game_print(game_default_solution());
|
||||
game sol = game_default_solution();
|
||||
game_update_flags(sol);
|
||||
game_print(sol);
|
||||
game_delete(sol);
|
||||
game_delete(g);
|
||||
printf("shame\n");
|
||||
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 (c == 'l') {
|
||||
game_set_square(g, i, j, S_LIGHTBULB);
|
||||
game_update_flags(g);
|
||||
game_print(g);
|
||||
} else if (c == 'm') {
|
||||
game_set_square(g, i, j, S_MARK);
|
||||
game_update_flags(g);
|
||||
game_print(g);
|
||||
} else if (c == 'b') {
|
||||
game_set_square(g, i, j, S_BLANK);
|
||||
game_update_flags(g);
|
||||
game_print(g);
|
||||
}
|
||||
} else {
|
||||
if (c == 'l' && game_check_move(g, i, j, S_LIGHTBULB)) {
|
||||
game_play_move(g, i, j, S_LIGHTBULB);
|
||||
game_print(g);
|
||||
} else if (c == 'm' && game_check_move(g, i, j, S_MARK)) {
|
||||
game_play_move(g, i, j, S_MARK);
|
||||
game_print(g);
|
||||
} else if (c == 'b' && game_check_move(g, i, j, S_BLANK)) {
|
||||
game_play_move(g, i, j, S_BLANK);
|
||||
game_print(g);
|
||||
} else
|
||||
printf("Erreur: (<i>,<j>) invalide.\n");
|
||||
}
|
||||
} else {
|
||||
printf("Commande inconnue.\n");
|
||||
}
|
||||
} else {
|
||||
printf("Commande inconnue.\n");
|
||||
}
|
||||
} else {
|
||||
printf("Commande inconnue.\n");
|
||||
}
|
||||
}
|
||||
printf("congratulation\n");
|
||||
game_delete(g);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
Reference in new issue
Block a user