diff --git a/src/board/test_board.c b/src/board/test_board.c index 5ef77225edb1abb15554c4bef7fd9cee0c407999..4d385626c5f6e35f0504950a9163f840e8c7d7c3 100644 --- a/src/board/test_board.c +++ b/src/board/test_board.c @@ -24,8 +24,8 @@ void test_create_board() { assert(board[i] != NULL && RED "Row allocation failed\n" RESET); } - printf(GREEN "test_create_board: PASSED\n" RESET); destroy_board(rows, board); + printf(GREEN "test_create_board: PASSED\n" RESET); } void test_fill_board() { @@ -42,6 +42,6 @@ void test_fill_board() { } } - printf(GREEN "test_fill_board: PASSED\n" RESET); destroy_board(rows, board); + printf(GREEN "test_fill_board: PASSED\n" RESET); } diff --git a/src/computer/test_computer.c b/src/computer/test_computer.c index 35e71226c33d0581d9a251cfe044d46293ee87b0..c23e4ce8e14e69181b972d6cf00ef4c3cf32ee01 100644 --- a/src/computer/test_computer.c +++ b/src/computer/test_computer.c @@ -2,7 +2,7 @@ void test_is_column_full() { int rows = 6, cols = 7; - int** board = setup_board(rows, cols, EMPTY); + int** board = setup_board(rows, cols); // An empty column should not be considered full assert(is_column_full(1, rows, board) == false && RED "test_is_column_full: FAILED - column should not be full\n" RESET); @@ -19,7 +19,7 @@ void test_is_column_full() { void test_select_smart_column() { int rows = 6, cols = 7; - int** board = setup_board(rows, cols, EMPTY); + int** board = setup_board(rows, cols); // Simulate a situation where the AI can win immediately board[5][0] = PLAYER2; @@ -41,7 +41,7 @@ void test_select_smart_column() { void test_select_random_column() { int rows = 6, cols = 7; - int** board = setup_board(rows, cols, EMPTY); + int** board = setup_board(rows, cols); // Select a random column on an empty board int col = select_random_column(cols, rows, board); diff --git a/src/game/test_game.c b/src/game/test_game.c index 7f2ec445c382acd8ca3b8e738a015e0a9c767bee..30d96316a1cf305ba0fcbf68d354c1cc540f073c 100644 --- a/src/game/test_game.c +++ b/src/game/test_game.c @@ -2,7 +2,7 @@ void test_place_token() { int rows = 6, cols = 7; - int** board = setup_board(rows, cols, EMPTY); + int** board = setup_board(rows, cols); // Player1 struct coordinate coord = { 2, 3 }; @@ -21,7 +21,7 @@ void test_place_token() { void test_find_empty_slot() { int rows = 6, cols = 7; - int** board = setup_board(rows, cols, EMPTY); + int** board = setup_board(rows, cols); // Search for an empty slot in a column board[5][2] = PLAYER1; @@ -58,7 +58,7 @@ void test_is_board_full() { void test_does_player_win() { int rows = 6, cols = 7; - int** board = setup_board(rows, cols, EMPTY); + int** board = setup_board(rows, cols); // Test horizontal win board[5][0] = PLAYER1; diff --git a/src/test_puissance4.c b/src/test_puissance4.c index 74004d565109255c37f16d046f25584f29fd5b15..e3ee4644b4db93a07e2ff8f0b9c562c639fb1907 100644 --- a/src/test_puissance4.c +++ b/src/test_puissance4.c @@ -22,18 +22,13 @@ int main() { return EXIT_SUCCESS; } -int** setup_board(int rows, int cols, int default_value) { +int** setup_board(int rows, int cols) { int** board = create_board(rows, cols); if (board == NULL) { fprintf(stderr, "Error: Unable to allocate memory for the board.\n"); exit(EXIT_FAILURE); } - - for (int i = 0; i < rows; i++) { - for (int j = 0; j < cols; j++) { - board[i][j] = default_value; - } - } + fill_board(rows, cols, board); return board; } diff --git a/src/test_puissance4.h b/src/test_puissance4.h index 3b4ac3120403e508a5ecbfa7904d4297c6f1e1d0..c44495ae437376597986311f60deab044713116c 100644 --- a/src/test_puissance4.h +++ b/src/test_puissance4.h @@ -15,7 +15,7 @@ #define RED "\033[1;31m" #define RESET "\033[0m" -int** setup_board(int rows, int cols, int default_value); +int** setup_board(int rows, int cols); void reset_board(int rows, int cols, int** board); #endif