clangformat

This commit is contained in:
nessar committed 2021-11-26 22:50:31 +01:00
1 parent 60cc903de3
commit bdcd253d7b
7 files changed
+283 -155

No files matched your search

+148
View File
@@ -0,0 +1,148 @@
---
Language: Cpp
# BasedOnStyle: Chromium
AccessModifierOffset: -1
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: true
BinPackParameters: false
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^<ext/.*\.h>'
Priority: 2
- Regex: '^<.*\.h>'
Priority: 1
- Regex: '^<.*'
Priority: 2
- Regex: '.*'
Priority: 3
IncludeIsMainRegex: '([-_](test|unittest))?$'
IndentCaseLabels: true
IndentPPDirectives: None
IndentWidth: 4
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Never
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Left
RawStringFormats:
- Language: Cpp
Delimiters:
- cc
- CC
- cpp
- Cpp
- CPP
- 'c++'
- 'C++'
CanonicalDelimiter: ''
BasedOnStyle: google
- Language: TextProto
Delimiters:
- pb
- PB
- proto
- PROTO
EnclosingFunctions:
- EqualsProto
- EquivToProto
- PARSE_PARTIAL_TEXT_PROTO
- PARSE_TEST_PROTO
- PARSE_TEXT_PROTO
- ParseTextOrDie
- ParseTextProtoOrDie
CanonicalDelimiter: ''
BasedOnStyle: google
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Auto
TabWidth: 4
UseTab: ForIndentation
...
+2 -40
View File
@@ -1,6 +1,6 @@
#include <stdlib.h>
#include <stdio.h>
#include "game.h"
#include <stdio.h>
#include <stdlib.h>
struct game_s {
square** tab_cell;
@@ -27,120 +27,82 @@ game game_new(square *squares){
return g;
}
game game_new_empty(void) {
return;
}
game game_copy(cgame g) {
return;
}
bool game_equal(cgame g1, cgame g2) {
return;
}
void game_delete(game g) {
return;
}
void game_set_square(game g, uint i, uint j, square s) {
return;
}
square game_get_square(cgame g, uint i, uint j) {
return;
}
square game_get_state(cgame g, uint i, uint j) {
return;
}
square game_get_flags(cgame g, uint i, uint j) {
return;
}
bool game_is_blank(cgame g, uint i, uint j) {
return;
}
bool game_is_lightbulb(cgame g, uint i, uint j) {
return;
}
bool game_is_black(cgame g, uint i, uint j) {
return;
}
int game_get_black_number(cgame g, uint i, uint j) {
return;
}
bool game_is_marked(cgame g, uint i, uint j) {
return;
}
bool game_is_lighted(cgame g, uint i, uint j) {
return;
}
bool game_has_error(cgame g, uint i, uint j) {
return;
}
bool game_check_move(cgame g, uint i, uint j, square s) {
return;
}
void game_play_move(game g, uint i, uint j, square s) {
return;
}
void game_update_flags(game g) {
return;
}
bool game_is_over(cgame g) {
return;
}
void game_restart(game g) {
return;
}
+6 -2
View File
@@ -6,10 +6,14 @@ 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))){
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))){
if ((sqState == S_MARK) ||
(sqState == (S_MARK | F_ERROR)) | (sqState == (S_MARK | F_LIGHTED))) {
return '-';
}
if (sqState == S_BLACK0 || sqState == (S_BLACK0 | F_ERROR)) {
+13 -18
View File
@@ -1,8 +1,8 @@
#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <assert.h>
#include "game.h"
#include "game_aux.h"
@@ -332,7 +332,8 @@ 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;
}
@@ -349,7 +350,8 @@ bool test_game_has_error(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_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;
}
@@ -367,31 +369,24 @@ int main(int argc, char * argv[]){
success = test_dummy();
else if (strcmp("game_get_square", argv[1]) == 0) {
success = test_game_get_square();
}
else if (strcmp("game_get_state", argv[1]) == 0){
} else if (strcmp("game_get_state", argv[1]) == 0) {
success = test_game_get_state();
}
else if (strcmp("game_get_flags", argv[1]) == 0){
} else if (strcmp("game_get_flags", argv[1]) == 0) {
success = test_game_get_flags();
}
else if (strcmp("game_is_marked", argv[1]) == 0){
} else if (strcmp("game_is_marked", argv[1]) == 0) {
success = test_game_is_marked();
}
else if (strcmp("game_is_lighted", argv[1]) == 0){
} else if (strcmp("game_is_lighted", argv[1]) == 0) {
success = test_game_is_lighted();
}
else if (strcmp("game_has_error", argv[1]) == 0){
} else if (strcmp("game_has_error", argv[1]) == 0) {
success = test_game_has_error();
}
else {
} else {
fprintf(stderr, "Error: test \"%s\" not found!\n", argv[1]);
exit(EXIT_FAILURE);
}
if (success) {
fprintf(stderr, "Test \"%s\" finished: SUCCESS\n", argv[1]);
return EXIT_SUCCESS;
}
else {
} else {
fprintf(stderr, "Test \"%s\" finished: FAILURE\n", argv[1]);
return EXIT_FAILURE;
}
+88 -63
View File
@@ -1,8 +1,8 @@
#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <assert.h>
#include "game.h"
#include "game_aux.h"
typedef unsigned int uint;
@@ -58,7 +58,9 @@ 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++) {
@@ -78,7 +80,8 @@ 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++) {
@@ -97,13 +100,25 @@ 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);
}
}
@@ -116,17 +131,21 @@ bool test_game_default(void){
game g = game_default();
// a verif aps sur
assert(g);
square tab[49] =
{
/*X0 X1 X2 X3 X4 X5 X6*/
/*Y 0*/ S_BLANK, S_BLANK, S_BLACK1, S_BLANK, S_BLANK, S_BLANK, S_BLANK,
/*Y 1*/ S_BLANK, S_BLANK, S_BLACK2, S_BLANK, S_BLANK, S_BLANK, S_BLANK,
/*Y 2*/ S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLACKU, S_BLACK2,
/*Y 3*/ S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK,
/*Y 4*/ S_BLACK1, S_BLACKU, S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLANK,
/*Y 5*/ S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLACK2, S_BLANK, S_BLANK,
/*Y 6*/ S_BLANK, S_BLANK, S_BLANK, S_BLANK, S_BLACKU, S_BLANK, S_BLANK
};
square tab[49] = {/*X0 X1 X2 X3 X4 X5 X6*/
/*Y 0*/ S_BLANK, S_BLANK, S_BLACK1, S_BLANK,
S_BLANK, S_BLANK, S_BLANK,
/*Y 1*/ S_BLANK, S_BLANK, S_BLACK2, S_BLANK,
S_BLANK, S_BLANK, S_BLANK,
/*Y 2*/ S_BLANK, S_BLANK, S_BLANK, S_BLANK,
S_BLANK, S_BLACKU, S_BLACK2,
/*Y 3*/ S_BLANK, S_BLANK, S_BLANK, S_BLANK,
S_BLANK, S_BLANK, S_BLANK,
/*Y 4*/ S_BLACK1, S_BLACKU, S_BLANK, S_BLANK,
S_BLANK, S_BLANK, S_BLANK,
/*Y 5*/ S_BLANK, S_BLANK, S_BLANK, S_BLANK,
S_BLACK2, S_BLANK, S_BLANK,
/*Y 6*/ S_BLANK, S_BLANK, S_BLANK, S_BLANK,
S_BLACKU, S_BLANK, S_BLANK};
game g1 = game_new(tab);
assert(game_equal(g, g1));
game_delete(g);
@@ -163,31 +182,34 @@ bool test_game_default_solution(void){
int checklightbulb(game g, uint i, uint j, bool wall) {
square flags = game_get_flags(g, i, j);
// square state = game_get_state(g,i,j);
//test if the current case is a lightbulb and if it has been well updated if true we can break the loop because every others cases wont be lighted by the bulb we are testing
// test if the current case is a lightbulb and if it has been well updated
// 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;
}
return -1;
}
//if no wall(s) before test if the light of the lightbulb has been well updated
// if no wall(s) before test if the light of the lightbulb has been well
// updated
if (!wall) {
// test if the current case is not lighted
if (flags != F_LIGHTED) {
// printf("170\n");
return 0;
}
}
else{
} else {
if (/*test if the current case is lighted*/ flags == F_LIGHTED) {
// printf("i:%d j:%d\n",i,j);
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)) {
@@ -196,7 +218,8 @@ 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)) {
@@ -205,7 +228,8 @@ 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)) {
@@ -214,7 +238,8 @@ 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)) {
@@ -239,17 +264,19 @@ 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 {
} else {
int tmp = checklightbulb(g, k, j, wall);
if (tmp == -1) {
break;
@@ -261,10 +288,10 @@ 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 {
} else {
int tmp = checklightbulb(g, k, j, wall);
if (tmp == -1) {
break;
@@ -276,10 +303,10 @@ 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 {
} else {
int tmp = checklightbulb(g, i, k, wall);
if (tmp == -1) {
break;
@@ -291,10 +318,10 @@ 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 {
} else {
int tmp = checklightbulb(g, i, k, wall);
if (tmp == -1) {
break;
@@ -304,8 +331,8 @@ 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;
@@ -315,36 +342,32 @@ bool check_update(game g){
if (i > 0) {
choice[size] = game_get_square(g, i - 1, j);
size++;
}
else{
} else {
notempty++;
}
if (i < DEFAULT_SIZE - 1) {
choice[size] = game_get_square(g, i + 1, j);
size++;
}
else{
} else {
notempty++;
}
if (j > 0) {
choice[size] = game_get_square(g, i, j - 1);
size++;
}
else{
} else {
notempty++;
}
if (j < DEFAULT_SIZE - 1) {
choice[size] = game_get_square(g, i, j + 1);
size++;
}
else{
} else {
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){
} else if (choice[l] != S_BLANK) {
notempty++;
}
}
@@ -352,7 +375,8 @@ 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) {
@@ -360,7 +384,9 @@ bool check_update(game g){
}
if (!res) {
// printf("386\n");
//printf("lb:%d notempty:%d i:%d j:%d state : %d, flags: %d\n",lb,notempty,i,j,game_get_state(g,i,j),game_get_flags(g,i,j));
// printf("lb:%d notempty:%d i:%d j:%d state : %d,
// flags:
// %d\n",lb,notempty,i,j,game_get_state(g,i,j),game_get_flags(g,i,j));
return res;
}
}
@@ -374,7 +400,8 @@ bool check_update(game g){
bool brutforce(game g, int a, bool* deldup) {
// char c;
bool* delDupNext = (bool*)calloc(DEFAULT_SIZE * DEFAULT_SIZE, sizeof(bool));
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);
@@ -398,7 +425,8 @@ bool brutforce(game g,int a, bool * deldup){
game_update_flags(g);
if (!check_update(g)) {
game_print(g);
//printf("i:%d j:%d state : %d, flags: %d\n",i,j,game_get_state(g,i,j),game_get_flags(g,i,j));
// printf("i:%d j:%d state : %d, flags:
// %d\n",i,j,game_get_state(g,i,j),game_get_flags(g,i,j));
free(delDupNext);
return false;
}
@@ -449,7 +477,6 @@ bool test_game_play_move(void){
return EXIT_SUCCESS;
}
/* ***** game_check_move ***** */
bool test_game_check_move(void) {
@@ -479,8 +506,7 @@ bool test_game_check_move(void){
/* ********** USAGE ********** */
int usage(int argc, char *argv[])
{
int usage(int argc, char* argv[]) {
fprintf(stderr, "Usage: %s <testname> [<...>]\n", argv[0]);
exit(EXIT_FAILURE);
}
@@ -523,8 +549,7 @@ int main(int argc, char * argv[]){
if (!ok) {
fprintf(stderr, "Test \"%s\" finished: SUCCESS\n", argv[1]);
return EXIT_SUCCESS;
}
else {
} else {
fprintf(stderr, "Test \"%s\" finished: FAILURE\n", argv[1]);
return EXIT_FAILURE;
}
+17 -28
View File
@@ -1,12 +1,11 @@
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <assert.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "game.h"
#include "game_aux.h"
/* ********** DUMMY ********** */
bool test_dummy() {
return true;
@@ -123,7 +122,8 @@ 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;
}
@@ -228,43 +228,32 @@ int main (int argc, char *argv[]){
bool success = false;
if (argc != 2) {
usage(argc, argv);
}
else if (strcmp("dummy", argv[1]) == 0){
} else if (strcmp("dummy", argv[1]) == 0) {
success = test_dummy();
}
else if (strcmp("game_new_empty", argv[1]) == 0){
} else if (strcmp("game_new_empty", argv[1]) == 0) {
success = test_game_new_empty();
}
else if (strcmp("game_copy", argv[1]) == 0){
} else if (strcmp("game_copy", argv[1]) == 0) {
success = test_game_copy();
}
else if (strcmp("game_equal", argv[1]) == 0){
} else if (strcmp("game_equal", argv[1]) == 0) {
success = test_game_equal();
}
else if (strcmp("game_delete", argv[1]) == 0){
} else if (strcmp("game_delete", argv[1]) == 0) {
success = test_game_delete();
}
else if (strcmp("game_is_blank", argv[1]) == 0){
} else if (strcmp("game_is_blank", argv[1]) == 0) {
success = test_game_is_blank();
}
else if (strcmp("game_is_lightbulb", argv[1]) == 0){
} else if (strcmp("game_is_lightbulb", argv[1]) == 0) {
success = test_game_is_lightbulb();
}
else if (strcmp("game_is_black", argv[1]) == 0){
} else if (strcmp("game_is_black", argv[1]) == 0) {
success = test_game_is_black();
}
else if (strcmp("game_get_black_number", argv[1]) == 0){
} else if (strcmp("game_get_black_number", argv[1]) == 0) {
success = test_game_get_black_number();
}
else{
} else {
fprintf(stderr, "test \"%s\" is not a valid test name.\n", argv[1]);
return EXIT_FAILURE;
}
if (success) {
fprintf(stderr, "test \"%s\" finished successfully\n", argv[1]);
return EXIT_SUCCESS;
}
else {
} else {
fprintf(stderr, "test \"%s\" error\n", argv[1]);
return EXIT_FAILURE;
}
+9 -4
View File
@@ -1,6 +1,6 @@
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include "game.h"
#include "game_aux.h"
@@ -39,9 +39,13 @@ void printhelp(void){
printf("h : Affiche cette aide.\n");
printf("r : Réinitialise la partie.\n");
printf("q : Quitter la partie (abandon).\n");
printf("l <i> <j> : Place une ampoule (*light bulb*) dans la case (<i>,<j>).\n");
printf(
"l <i> <j> : Place une ampoule (*light bulb*) dans la case "
"(<i>,<j>).\n");
printf("m <i> <j> : Place une marque (*mark*) dans la case (<i>,<j>).\n");
printf("b <i> <j> : Place placer une case vide (*blank*) à la position (<i>,<j>).\n");
printf(
"b <i> <j> : Place placer une case vide (*blank*) à la position "
"(<i>,<j>).\n");
}
int main(void) {
@@ -75,7 +79,8 @@ 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);