Skip to content
Snippets Groups Projects
Commit 5836e139 authored by anthony.bouillan's avatar anthony.bouillan
Browse files

refactor setup_board function

parent 9e2ee5eb
Branches
No related tags found
No related merge requests found
Pipeline #39551 passed
......@@ -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);
}
......@@ -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);
......
......@@ -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;
......
......@@ -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;
}
......
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment