clangformat
This commit is contained in:
1 parent
60cc903de3
commit
bdcd253d7b
7 files changed
+1150
-1022
No files matched your search
+261
-236
@@ -1,27 +1,27 @@
|
||||
#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;
|
||||
|
||||
/* ********** DUMMY ********** */
|
||||
bool test_dummy(void){
|
||||
bool test_dummy(void) {
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
/* ******* game_is_over ******* */
|
||||
|
||||
bool test_game_is_over(void){
|
||||
bool test_game_is_over(void) {
|
||||
game g = game_default_solution();
|
||||
game_update_flags(g);
|
||||
assert(game_is_over(g));
|
||||
game_set_square(g,0,0,(S_LIGHTBULB|F_LIGHTED|F_ERROR));
|
||||
game_set_square(g, 0, 0, (S_LIGHTBULB | F_LIGHTED | F_ERROR));
|
||||
assert(!game_is_over(g));
|
||||
game_update_flags(g);
|
||||
game_set_square(g,0,1,S_BLANK);
|
||||
game_set_square(g, 0, 1, S_BLANK);
|
||||
assert(!game_is_over(g));
|
||||
game_delete(g);
|
||||
g = game_default();
|
||||
@@ -33,21 +33,21 @@ bool test_game_is_over(void){
|
||||
|
||||
/* ******* game_restart ******* */
|
||||
|
||||
bool test_game_restart(void){
|
||||
bool test_game_restart(void) {
|
||||
game g = game_default();
|
||||
game g1 = game_default_solution();
|
||||
game_set_square(g,1,5,S_BLACK4);
|
||||
game_set_square(g1,1,5,S_BLACK4);
|
||||
game_set_square(g,3,2,S_BLACK3);
|
||||
game_set_square(g1,3,2,S_BLACK3);
|
||||
game_set_square(g,0,1,S_LIGHTBULB);
|
||||
game_set_square(g1,0,1,S_LIGHTBULB);
|
||||
game_play_move(g,2,0,S_MARK);
|
||||
game_play_move(g1,2,0,S_MARK);
|
||||
assert(!game_equal(g,g1));
|
||||
game_set_square(g, 1, 5, S_BLACK4);
|
||||
game_set_square(g1, 1, 5, S_BLACK4);
|
||||
game_set_square(g, 3, 2, S_BLACK3);
|
||||
game_set_square(g1, 3, 2, S_BLACK3);
|
||||
game_set_square(g, 0, 1, S_LIGHTBULB);
|
||||
game_set_square(g1, 0, 1, S_LIGHTBULB);
|
||||
game_play_move(g, 2, 0, S_MARK);
|
||||
game_play_move(g1, 2, 0, S_MARK);
|
||||
assert(!game_equal(g, g1));
|
||||
game_restart(g1);
|
||||
game_restart(g);
|
||||
assert(game_equal(g,g1));
|
||||
assert(game_equal(g, g1));
|
||||
game_delete(g);
|
||||
game_delete(g1);
|
||||
return EXIT_SUCCESS;
|
||||
@@ -55,16 +55,18 @@ bool test_game_restart(void){
|
||||
|
||||
/* ********* game_new ********* */
|
||||
|
||||
bool test_game_new(void){
|
||||
square tab[DEFAULT_SIZE*DEFAULT_SIZE];
|
||||
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};
|
||||
for (uint i = 0; i < sizeof(list)/sizeof(list[0]) ; i ++){
|
||||
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++){
|
||||
for (uint j = 0; j < DEFAULT_SIZE * DEFAULT_SIZE; j++) {
|
||||
tab[j] = list[i];
|
||||
}
|
||||
printf("%d\n",i);
|
||||
printf("%d\n", i);
|
||||
g = game_new(tab);
|
||||
assert(g);
|
||||
game_delete(g);
|
||||
@@ -76,15 +78,16 @@ bool test_game_new(void){
|
||||
|
||||
// est ce qu'il faut faire avec un tab invalide ?
|
||||
|
||||
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};
|
||||
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};
|
||||
game g;
|
||||
for (uint i = 0; i < sizeof(list)/sizeof(list[0]) ; i ++){
|
||||
for (uint j = 0; j < DEFAULT_SIZE*DEFAULT_SIZE; j++){
|
||||
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];
|
||||
}
|
||||
printf("%d\n",i);
|
||||
printf("%d\n", i);
|
||||
g = game_new(tab);
|
||||
game_print(g);
|
||||
game_delete(g);
|
||||
@@ -94,16 +97,28 @@ bool test_game_print(void){
|
||||
|
||||
/* ******* game_get_square ******* */
|
||||
|
||||
bool test_game_get_square(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};
|
||||
for (uint i = 0; i < sizeof(list)/sizeof(list[0]) ; i ++){
|
||||
for (uint j = 0; j < DEFAULT_SIZE*DEFAULT_SIZE; j++){
|
||||
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};
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -112,23 +127,27 @@ bool test_game_get_square(void){
|
||||
|
||||
/* ******* game_default ******* */
|
||||
|
||||
bool test_game_default(void){
|
||||
bool test_game_default(void) {
|
||||
game g = game_default();
|
||||
//a verif aps sur
|
||||
// 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));
|
||||
assert(game_equal(g, g1));
|
||||
game_delete(g);
|
||||
game_delete(g1);
|
||||
return EXIT_SUCCESS;
|
||||
@@ -136,23 +155,23 @@ bool test_game_default(void){
|
||||
|
||||
/* *** game_default_solution *** */
|
||||
|
||||
bool test_game_default_solution(void){
|
||||
bool test_game_default_solution(void) {
|
||||
game g = game_default_solution();
|
||||
game g1 = game_default();
|
||||
assert(g);
|
||||
//solution
|
||||
game_set_square(g1,0,0,S_LIGHTBULB);
|
||||
game_set_square(g1,1,1,S_LIGHTBULB);
|
||||
game_set_square(g1,0,3,S_LIGHTBULB);
|
||||
game_set_square(g1,1,6,S_LIGHTBULB);
|
||||
game_set_square(g1,2,2,S_LIGHTBULB);
|
||||
game_set_square(g1,3,6,S_LIGHTBULB);
|
||||
game_set_square(g1,4,4,S_LIGHTBULB);
|
||||
game_set_square(g1,5,0,S_LIGHTBULB);
|
||||
game_set_square(g1,5,5,S_LIGHTBULB);
|
||||
game_set_square(g1,6,1,S_LIGHTBULB);
|
||||
// solution
|
||||
game_set_square(g1, 0, 0, S_LIGHTBULB);
|
||||
game_set_square(g1, 1, 1, S_LIGHTBULB);
|
||||
game_set_square(g1, 0, 3, S_LIGHTBULB);
|
||||
game_set_square(g1, 1, 6, S_LIGHTBULB);
|
||||
game_set_square(g1, 2, 2, S_LIGHTBULB);
|
||||
game_set_square(g1, 3, 6, S_LIGHTBULB);
|
||||
game_set_square(g1, 4, 4, S_LIGHTBULB);
|
||||
game_set_square(g1, 5, 0, S_LIGHTBULB);
|
||||
game_set_square(g1, 5, 5, S_LIGHTBULB);
|
||||
game_set_square(g1, 6, 1, S_LIGHTBULB);
|
||||
game_update_flags(g1);
|
||||
assert(game_equal(g,g1));
|
||||
assert(game_equal(g, g1));
|
||||
game_delete(g);
|
||||
game_delete(g1);
|
||||
return EXIT_SUCCESS;
|
||||
@@ -160,207 +179,214 @@ bool test_game_default_solution(void){
|
||||
|
||||
/* **** game_update_flags **** */
|
||||
|
||||
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
|
||||
if (game_is_lightbulb(g,i,j)){
|
||||
if (/*test if this lightbulb is well updated*/ flags == S_BLANK || flags == F_ERROR){
|
||||
//printf("156\n");
|
||||
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
|
||||
if (game_is_lightbulb(g, i, j)) {
|
||||
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 (!wall){
|
||||
|
||||
//test if the current case is not lighted
|
||||
if (flags != F_LIGHTED){
|
||||
//printf("170\n");
|
||||
return 0;
|
||||
// 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{
|
||||
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)){
|
||||
|
||||
} 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)) {
|
||||
return -1;
|
||||
}
|
||||
if (flags != F_LIGHTED && flags != (F_LIGHTED|S_MARK)){
|
||||
if (flags != F_LIGHTED && flags != (F_LIGHTED | S_MARK)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
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)){
|
||||
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)) {
|
||||
return -1;
|
||||
}
|
||||
if (flags != F_LIGHTED && flags != (F_LIGHTED|S_MARK)){
|
||||
if (flags != F_LIGHTED && flags != (F_LIGHTED | S_MARK)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
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)){
|
||||
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)) {
|
||||
return -1;
|
||||
}
|
||||
if (flags != F_LIGHTED && flags != (F_LIGHTED|S_MARK)){
|
||||
if (flags != F_LIGHTED && flags != (F_LIGHTED | S_MARK)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
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)){
|
||||
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)) {
|
||||
return -1;
|
||||
}
|
||||
if (flags != F_LIGHTED && flags != (F_LIGHTED|S_MARK)){
|
||||
if (flags != F_LIGHTED && flags != (F_LIGHTED | S_MARK)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
//printf("220\n");
|
||||
// printf("220\n");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
bool check_update(game g){
|
||||
bool check_update(game g) {
|
||||
uint size;
|
||||
square choice[4];
|
||||
uint lb;
|
||||
uint notempty;
|
||||
bool res;
|
||||
bool wall;
|
||||
for (uint i = 0; i < DEFAULT_SIZE; i++){
|
||||
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){
|
||||
//printf("196\n");
|
||||
for (uint i = 0; i < DEFAULT_SIZE; i++) {
|
||||
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) {
|
||||
// printf("196\n");
|
||||
return false;
|
||||
}
|
||||
//loop checking every case before i
|
||||
// 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)){
|
||||
for (int k = i - 1; k > 0; k--) {
|
||||
if (/*test if current case is a wall*/ game_is_black(g, k,
|
||||
j)) {
|
||||
wall = true;
|
||||
}
|
||||
else {
|
||||
int tmp = checklightbulb(g,k,j,wall);
|
||||
if (tmp == -1){
|
||||
} else {
|
||||
int tmp = checklightbulb(g, k, j, wall);
|
||||
if (tmp == -1) {
|
||||
break;
|
||||
}
|
||||
if (!tmp){
|
||||
if (!tmp) {
|
||||
return tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
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)){
|
||||
for (int k = i + 1; k < DEFAULT_SIZE; k++) {
|
||||
if (/*test if current case is a wall*/ game_is_black(g, k,
|
||||
j)) {
|
||||
wall = true;
|
||||
}
|
||||
else {
|
||||
int tmp = checklightbulb(g,k,j,wall);
|
||||
if (tmp == -1){
|
||||
} else {
|
||||
int tmp = checklightbulb(g, k, j, wall);
|
||||
if (tmp == -1) {
|
||||
break;
|
||||
}
|
||||
if (!tmp){
|
||||
if (!tmp) {
|
||||
return tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
wall = false;
|
||||
for (int k = j-1; k > 0; k--){
|
||||
if (/*test if current case is a wall*/ game_is_black(g,i,k)){
|
||||
for (int k = j - 1; k > 0; 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);
|
||||
if (tmp == -1){
|
||||
} else {
|
||||
int tmp = checklightbulb(g, i, k, wall);
|
||||
if (tmp == -1) {
|
||||
break;
|
||||
}
|
||||
if (!tmp){
|
||||
if (!tmp) {
|
||||
return tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
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)){
|
||||
for (int k = j + 1; k < DEFAULT_SIZE; 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);
|
||||
if (tmp == -1){
|
||||
} else {
|
||||
int tmp = checklightbulb(g, i, k, wall);
|
||||
if (tmp == -1) {
|
||||
break;
|
||||
}
|
||||
if (!tmp){
|
||||
if (!tmp) {
|
||||
return tmp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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
|
||||
} 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;
|
||||
lb = 0;
|
||||
notempty = 0;
|
||||
res = true;
|
||||
if (i > 0){
|
||||
choice[size] = game_get_square(g,i-1,j);
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
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)){
|
||||
for (int l = 0; l < size; l++) {
|
||||
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++;
|
||||
}
|
||||
}
|
||||
if (lb > game_get_black_number(g,i,j)){
|
||||
if (lb > game_get_black_number(g, i, j)) {
|
||||
res = false;
|
||||
}
|
||||
//look if there is enough empty cell around the wall
|
||||
else if (notempty > abs(game_get_black_number(g,i,j)-4)){
|
||||
// look if there is enough empty cell around the wall
|
||||
else if (notempty >
|
||||
abs(game_get_black_number(g, i, j) - 4)) {
|
||||
res = false;
|
||||
}
|
||||
if (game_get_flags(g,i,j) == F_ERROR){
|
||||
if (game_get_flags(g, i, j) == F_ERROR) {
|
||||
res = !res;
|
||||
}
|
||||
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));
|
||||
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));
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -371,34 +397,36 @@ bool check_update(game g){
|
||||
}
|
||||
|
||||
// a > 2 = temps d'exec > 3 min et expo
|
||||
bool brutforce(game g,int a, bool * deldup){
|
||||
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};
|
||||
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);
|
||||
if (deldup == NULL || !(deldup[i*DEFAULT_SIZE+j])){
|
||||
if (game_get_state(g,i,j) == S_BLANK){
|
||||
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};
|
||||
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);
|
||||
if (deldup == NULL || !(deldup[i * DEFAULT_SIZE + j])) {
|
||||
if (game_get_state(g, i, j) == S_BLANK) {
|
||||
if (delDupNext != NULL && a > 0)
|
||||
delDupNext[i*DEFAULT_SIZE+j] = true;
|
||||
for (uint k = 0 ; k < 9; k++){
|
||||
game_set_square(g,i,j,list[k]);
|
||||
delDupNext[i * DEFAULT_SIZE + j] = true;
|
||||
for (uint k = 0; k < 9; k++) {
|
||||
game_set_square(g, i, j, list[k]);
|
||||
// if (k == 0){
|
||||
// game_print(g);
|
||||
// scanf("%c",&c);
|
||||
// }
|
||||
if (a > 0){
|
||||
if (!brutforce(g,a-1,delDupNext)){
|
||||
//printf("341\n");
|
||||
if (a > 0) {
|
||||
if (!brutforce(g, a - 1, delDupNext)) {
|
||||
// printf("341\n");
|
||||
free(delDupNext);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
game_update_flags(g);
|
||||
if (!check_update(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;
|
||||
}
|
||||
@@ -411,9 +439,9 @@ bool brutforce(game g,int a, bool * deldup){
|
||||
return true;
|
||||
}
|
||||
|
||||
bool test_game_update_flags(void){
|
||||
bool test_game_update_flags(void) {
|
||||
game g = game_default();
|
||||
if (!brutforce(g,1,NULL)){
|
||||
if (!brutforce(g, 1, NULL)) {
|
||||
game_delete(g);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
@@ -423,72 +451,70 @@ bool test_game_update_flags(void){
|
||||
|
||||
/* ****** game_play_move ****** */
|
||||
|
||||
bool test_game_play_move(void){
|
||||
bool test_game_play_move(void) {
|
||||
game g = game_new_empty();
|
||||
game g1 = game_new_empty();
|
||||
game_play_move(g,0,0,S_LIGHTBULB);
|
||||
assert(!game_equal(g,g1));
|
||||
game_set_square(g1,0,0,S_LIGHTBULB);
|
||||
assert(!game_equal(g,g1));
|
||||
game_play_move(g, 0, 0, S_LIGHTBULB);
|
||||
assert(!game_equal(g, g1));
|
||||
game_set_square(g1, 0, 0, S_LIGHTBULB);
|
||||
assert(!game_equal(g, g1));
|
||||
game_update_flags(g1);
|
||||
assert(game_equal(g,g1));
|
||||
game_play_move(g,3,0,S_MARK);
|
||||
assert(!game_equal(g,g1));
|
||||
game_set_square(g1,3,0,S_MARK);
|
||||
assert(!game_equal(g,g1));
|
||||
assert(game_equal(g, g1));
|
||||
game_play_move(g, 3, 0, S_MARK);
|
||||
assert(!game_equal(g, g1));
|
||||
game_set_square(g1, 3, 0, S_MARK);
|
||||
assert(!game_equal(g, g1));
|
||||
game_update_flags(g1);
|
||||
assert(game_equal(g,g1));
|
||||
game_play_move(g,0,3,S_BLANK);
|
||||
assert(game_equal(g,g1));
|
||||
game_set_square(g1,0,3,S_BLANK);
|
||||
assert(!game_equal(g,g1));
|
||||
assert(game_equal(g, g1));
|
||||
game_play_move(g, 0, 3, S_BLANK);
|
||||
assert(game_equal(g, g1));
|
||||
game_set_square(g1, 0, 3, S_BLANK);
|
||||
assert(!game_equal(g, g1));
|
||||
game_update_flags(g1);
|
||||
assert(game_equal(g,g1));
|
||||
assert(game_equal(g, g1));
|
||||
game_delete(g);
|
||||
game_delete(g1);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
/* ***** game_check_move ***** */
|
||||
|
||||
bool test_game_check_move(void){
|
||||
bool test_game_check_move(void) {
|
||||
game g = game_new_empty();
|
||||
assert(!game_check_move(g,10,10,S_BLANK));
|
||||
assert(!game_check_move(g,10,10,S_BLACK0));
|
||||
assert(!game_check_move(g,0,0,S_BLACK0));
|
||||
assert(!game_check_move(g,0,0,S_BLACK1));
|
||||
assert(!game_check_move(g,0,0,S_BLACK2));
|
||||
assert(!game_check_move(g,0,0,S_BLACK3));
|
||||
assert(!game_check_move(g,0,0,S_BLACK4));
|
||||
assert(!game_check_move(g,0,0,S_BLACKU));
|
||||
assert(!game_check_move(g,0,0,F_LIGHTED));
|
||||
assert(!game_check_move(g,0,0,F_ERROR));
|
||||
for (uint i = 0 ; i < S_BLACKU-S_BLACK0 ; i ++){
|
||||
game_set_square(g,0,0,S_BLACK0+i);
|
||||
assert(!game_check_move(g,0,0,S_BLANK));
|
||||
assert(!game_check_move(g,0,0,S_MARK));
|
||||
assert(!game_check_move(g,0,0,S_LIGHTBULB));
|
||||
assert(!game_check_move(g, 10, 10, S_BLANK));
|
||||
assert(!game_check_move(g, 10, 10, S_BLACK0));
|
||||
assert(!game_check_move(g, 0, 0, S_BLACK0));
|
||||
assert(!game_check_move(g, 0, 0, S_BLACK1));
|
||||
assert(!game_check_move(g, 0, 0, S_BLACK2));
|
||||
assert(!game_check_move(g, 0, 0, S_BLACK3));
|
||||
assert(!game_check_move(g, 0, 0, S_BLACK4));
|
||||
assert(!game_check_move(g, 0, 0, S_BLACKU));
|
||||
assert(!game_check_move(g, 0, 0, F_LIGHTED));
|
||||
assert(!game_check_move(g, 0, 0, F_ERROR));
|
||||
for (uint i = 0; i < S_BLACKU - S_BLACK0; i++) {
|
||||
game_set_square(g, 0, 0, S_BLACK0 + i);
|
||||
assert(!game_check_move(g, 0, 0, S_BLANK));
|
||||
assert(!game_check_move(g, 0, 0, S_MARK));
|
||||
assert(!game_check_move(g, 0, 0, S_LIGHTBULB));
|
||||
}
|
||||
assert(game_check_move(g,1,0,S_BLANK));
|
||||
assert(game_check_move(g,1,0,S_MARK));
|
||||
assert(game_check_move(g,1,0,S_LIGHTBULB));
|
||||
assert(game_check_move(g, 1, 0, S_BLANK));
|
||||
assert(game_check_move(g, 1, 0, S_MARK));
|
||||
assert(game_check_move(g, 1, 0, S_LIGHTBULB));
|
||||
game_delete(g);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
/* ********** USAGE ********** */
|
||||
|
||||
int usage(int argc, char *argv[])
|
||||
{
|
||||
fprintf(stderr, "Usage: %s <testname> [<...>]\n", argv[0]);
|
||||
exit(EXIT_FAILURE);
|
||||
int usage(int argc, char* argv[]) {
|
||||
fprintf(stderr, "Usage: %s <testname> [<...>]\n", argv[0]);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
/* ********** MAIN ********** */
|
||||
|
||||
int main(int argc, char * argv[]){
|
||||
if (argc == 1){
|
||||
int main(int argc, char* argv[]) {
|
||||
if (argc == 1) {
|
||||
usage(argc, argv);
|
||||
}
|
||||
fprintf(stderr, "=> Start test \"%s\"\n", argv[1]);
|
||||
@@ -516,16 +542,15 @@ int main(int argc, char * argv[]){
|
||||
else if (strcmp("game_check_move", argv[1]) == 0)
|
||||
ok = test_game_check_move();
|
||||
else {
|
||||
fprintf(stderr, "Error: test \"%s\" not found!\n", argv[1]);
|
||||
exit(EXIT_FAILURE);
|
||||
fprintf(stderr, "Error: test \"%s\" not found!\n", argv[1]);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
// print test result
|
||||
if (!ok){
|
||||
fprintf(stderr, "Test \"%s\" finished: SUCCESS\n", argv[1]);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "Test \"%s\" finished: FAILURE\n", argv[1]);
|
||||
return EXIT_FAILURE;
|
||||
if (!ok) {
|
||||
fprintf(stderr, "Test \"%s\" finished: SUCCESS\n", argv[1]);
|
||||
return EXIT_SUCCESS;
|
||||
} else {
|
||||
fprintf(stderr, "Test \"%s\" finished: FAILURE\n", argv[1]);
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user