Merge branch 'main' of gitlab.emi.u-bordeaux.fr:pt2/teams/a42/lightup-a42e
This commit is contained in:
commit
9c60c774a5
5 files changed
+67
-37
No files matched your search
Vendored
+25
@@ -4,6 +4,31 @@
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "(gdb) game_text",
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"program": "${workspaceFolder}/build/game_text",
|
||||
"args": [],
|
||||
"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 thoguet",
|
||||
"type": "cppdbg",
|
||||
|
||||
+6
-1
@@ -25,9 +25,11 @@ target_link_libraries(game_test_thperrier game history)
|
||||
target_link_libraries(game_test_nnunes game history)
|
||||
target_link_libraries(history_test game history)
|
||||
|
||||
add_library (game game.c game_aux.c)
|
||||
#Libraries
|
||||
add_library (game game.c game_aux.c game_ext.c)
|
||||
add_library(history history.c)
|
||||
|
||||
#Tests THOGUET
|
||||
add_test(test_thoguet_dummy ./game_test_thoguet dummy)
|
||||
add_test(test_thoguet_game_new ./game_test_thoguet game_new)
|
||||
add_test(test_thoguet_game_print ./game_test_thoguet game_print)
|
||||
@@ -40,6 +42,7 @@ add_test(test_thoguet_game_update_flags ./game_test_thoguet game_update_flags)
|
||||
add_test(test_thoguet_game_play_move ./game_test_thoguet game_play_move)
|
||||
add_test(test_thoguet_game_check_move ./game_test_thoguet game_check_move)
|
||||
|
||||
#Tests THPERRIER
|
||||
add_test(test_thperrier_dummy ./game_test_thperrier dummy)
|
||||
add_test(test_thperrier_game_copy ./game_test_thperrier game_copy)
|
||||
add_test(test_thperrier_game_new_empty ./game_test_thperrier game_new_empty)
|
||||
@@ -50,6 +53,7 @@ add_test(test_thperrier_game_is_lightbulb ./game_test_thperrier game_is_lightbul
|
||||
add_test(test_thperrier_game_is_black ./game_test_thperrier game_is_black)
|
||||
add_test(test_thperrier_game_get_black_number ./game_test_thperrier game_get_black_number)
|
||||
|
||||
#Tests NNUNES
|
||||
add_test(test_nnunes_dummy ./game_test_nnunes dummy)
|
||||
add_test(test_nnunes_game_set_square ./game_test_nnunes game_set_square)
|
||||
add_test(test_nnunes_game_get_state ./game_test_nnunes game_get_state)
|
||||
@@ -58,6 +62,7 @@ add_test(test_nnunes_game_is_marked ./game_test_nnunes game_is_marked)
|
||||
add_test(test_nnunes_game_is_lighted ./game_test_nnunes game_is_lighted)
|
||||
add_test(test_nnunes_game_has_error ./game_test_nnunes game_has_error)
|
||||
|
||||
#Tests HISTORY
|
||||
add_test(test_history_history_alloc ./history_test history_alloc)
|
||||
add_test(test_history_create_empty ./history_test history_create_empty)
|
||||
add_test(test_history_delete_entire_history ./history_test history_delete_entire_history)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "game.h"
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "game_ext.h"
|
||||
|
||||
int max(int a, int b) {
|
||||
if (a > b)
|
||||
@@ -53,19 +54,19 @@ game game_copy(cgame g1) {
|
||||
game g2 = game_new_empty_ext(g1->height, g1->width, g1->wrapping);
|
||||
for (int i = 0; i < g2->height; i++) {
|
||||
for (int j = 0; j < g2->width; j++) {
|
||||
if (g1->tab_cell[i][j] == S_BLANK || g1->tab_cell[i][j] == S_LIGHTBULB || g1->tab_cell[i][j] == S_MARK){
|
||||
if (g1->tab_cell[i][j] == S_BLANK || g1->tab_cell[i][j] == S_LIGHTBULB || g1->tab_cell[i][j] == S_MARK) {
|
||||
game_play_move(g2, i, j, g1->tab_cell[i][j]);
|
||||
}
|
||||
else {
|
||||
g2->tab_cell[i][j] = g1->tab_cell[i][j];
|
||||
} else {
|
||||
g2->tab_cell[i][j] = g1->tab_cell[i][j];
|
||||
}
|
||||
}
|
||||
}
|
||||
return g2;
|
||||
}
|
||||
|
||||
// TODO
|
||||
bool game_equal(cgame g1, cgame g2) {
|
||||
if (g1->height != g2->height || g1->width != g2->width || g1->wrapping != g2->wrapping)
|
||||
return false;
|
||||
for (int i = 0; i < DEFAULT_SIZE; i++) {
|
||||
for (int j = 0; j < DEFAULT_SIZE; j++) {
|
||||
if (g1->tab_cell[i][j] != g2->tab_cell[i][j]) {
|
||||
@@ -166,12 +167,11 @@ bool game_check_move(cgame g, uint i, uint j, square s) {
|
||||
void game_play_move(game g, uint i, uint j, square s) {
|
||||
game_set_square(g, i, j, s);
|
||||
game_update_flags(g);
|
||||
if (g->hist == NULL){
|
||||
if (g->hist == NULL) {
|
||||
g->hist = history_create_empty();
|
||||
g->hist = history_insert_first(g->hist, s, i, j);
|
||||
}
|
||||
else {
|
||||
g->hist = history_next(history_insert_after(g->hist,g->hist,s,i,j));
|
||||
} else {
|
||||
g->hist = history_next(history_insert_after(g->hist, g->hist, s, i, j));
|
||||
g->hist = history_delete_all_after(g->hist, g->hist);
|
||||
}
|
||||
}
|
||||
@@ -205,18 +205,20 @@ void game_update_flags(game g) {
|
||||
// add FLIGHTED on the 4 directions, when a wall is hit stop this direction, when another lightbulb is hit put the initial lighbulb on error
|
||||
int tab[] = {-1, 0, 1, 0, 0, -1, 0, 1};
|
||||
for (int x = 1; x < max(g->width, g->height); x++) {
|
||||
for (uint y = 0; y < 7; y = y + 2) {
|
||||
if (tab[y] != tab[y + 1] && j + x * tab[y + 1] >= 0 && j + x * tab[y + 1] < g->width && i + x * tab[y] >= 0 &&
|
||||
i + x * tab[y] < g->height) {
|
||||
if (game_is_black(g, i + x * tab[y], j + x * tab[y + 1])) {
|
||||
for (uint y = 0; y < 7 /*tab size*/; y = y + 2) {
|
||||
if (/* test if both tab are not 0*/ tab[y] != tab[y + 1] &&
|
||||
(/* normal check */ (j + x * tab[y + 1] >= 0 && j + x * tab[y + 1] < g->width && i + x * tab[y] >= 0 &&
|
||||
i + x * tab[y] < g->height) ||
|
||||
/* wrapping check*/ g->wrapping)) {
|
||||
if (game_is_black(g, ((i + g->height + x * tab[y]) % g->height), ((j + g->width + x * tab[y + 1]) % g->width))) {
|
||||
tab[y] = 0;
|
||||
tab[y + 1] = 0;
|
||||
} else {
|
||||
// if we found another lightbulb on the line
|
||||
if (game_get_state(g, i + x * tab[y], j + x * tab[y + 1]) == S_LIGHTBULB)
|
||||
if (game_get_state(g, ((i + g->height + x * tab[y]) % g->height), ((j + g->width + x * tab[y + 1]) % g->width)) == S_LIGHTBULB)
|
||||
// update initial lightbulb on F_ERROR
|
||||
game_set_square(g, i, j, (S_LIGHTBULB | F_LIGHTED | F_ERROR));
|
||||
addF_LIGHTED(g, i + x * tab[y], j + x * tab[y + 1]);
|
||||
addF_LIGHTED(g, ((i + g->height + x * tab[y]) % g->height), ((j + g->width + x * tab[y + 1]) % g->width));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -232,10 +234,12 @@ void game_update_flags(game g) {
|
||||
int notempty = 0;
|
||||
int tab[] = {-1, 0, 1, 0, 0, -1, 0, 1};
|
||||
for (uint y = 0; y < 7; y = y + 2) {
|
||||
if (j + tab[y + 1] >= 0 && j + tab[y + 1] < g->width && i + tab[y] >= 0 && i + tab[y] < g->height) {
|
||||
if (game_is_lightbulb(g, i + tab[y], j + tab[y + 1]))
|
||||
if (/* normal check*/ (j + tab[y + 1] >= 0 && j + tab[y + 1] < g->width && i + tab[y] >= 0 && i + tab[y] < g->height) ||
|
||||
/*wrapping check*/ g->wrapping) {
|
||||
if (game_is_lightbulb(g, (i + g->height + tab[y]) % g->height, (j + g->width + tab[y + 1]) % g->width))
|
||||
lb++;
|
||||
else if (!game_is_blank(g, i + tab[y], j + tab[y + 1]) || game_is_lighted(g, i + tab[y], j + tab[y + 1]))
|
||||
else if (!game_is_blank(g, (i + g->height + tab[y]) % g->height, (j + g->width + tab[y + 1]) % g->width) ||
|
||||
game_is_lighted(g, (i + g->height + tab[y]) % g->height, (j + g->width + tab[y + 1]) % g->width))
|
||||
notempty++;
|
||||
} else {
|
||||
notempty++;
|
||||
|
||||
+8
-9
@@ -44,25 +44,24 @@ game game_new_empty_ext(uint nb_rows, uint nb_cols, bool wrapping) {
|
||||
}
|
||||
|
||||
uint game_nb_rows(cgame g) {
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint game_nb_cols(cgame g) {
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool game_is_wrapping(cgame g) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
|
||||
void game_undo(game g) {
|
||||
if (history_prev(g->hist) == NULL){
|
||||
if (history_prev(g->hist) == NULL) {
|
||||
printf("waiting for your first move");
|
||||
}
|
||||
else{
|
||||
game_set_square(g, history_i(history_prev(g->hist)), history_j(history_prev(g->hist)), history_state(history_prev(g->hist)));
|
||||
game_update_flags(g);
|
||||
g->hist = history_prev(g->hist);
|
||||
} else {
|
||||
game_set_square(g, history_i(history_prev(g->hist)), history_j(history_prev(g->hist)), history_state(history_prev(g->hist)));
|
||||
game_update_flags(g);
|
||||
g->hist = history_prev(g->hist);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
-9
@@ -3,6 +3,7 @@
|
||||
#include <stdlib.h>
|
||||
#include "game.h"
|
||||
#include "game_aux.h"
|
||||
#include "game_ext.h"
|
||||
|
||||
bool checkerr(cgame g, char taberr[]) {
|
||||
if (taberr == NULL || g == NULL) {
|
||||
@@ -70,12 +71,10 @@ int main(void) {
|
||||
} else if (c == 'r') {
|
||||
game_restart(g);
|
||||
printf("Partie réinitialisé avec success !\n");
|
||||
game_update_flags(g);
|
||||
game_print(g);
|
||||
} else if (c == 'q') {
|
||||
printf("Solution: \n");
|
||||
game sol = game_default_solution();
|
||||
game_update_flags(sol);
|
||||
game_print(sol);
|
||||
game_delete(sol);
|
||||
game_delete(g);
|
||||
@@ -83,17 +82,15 @@ int main(void) {
|
||||
return EXIT_SUCCESS;
|
||||
} else if (c == 'l' || c == 'm' || c == 'b') {
|
||||
if (scanf(" %u %u", &i, &j) == 2) {
|
||||
if (c == 'l' && game_check_move(g, i, j, S_LIGHTBULB)) {
|
||||
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)) {
|
||||
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)) {
|
||||
else if (c == 'b' && game_check_move(g, i, j, S_BLANK))
|
||||
game_play_move(g, i, j, S_BLANK);
|
||||
game_print(g);
|
||||
} else
|
||||
else
|
||||
printf("Erreur: (<i>,<j>) invalide.\n");
|
||||
game_print(g);
|
||||
}
|
||||
} else {
|
||||
printf("Commande inconnue.\n");
|
||||
|
||||
Reference in new issue
Block a user