From 92bf31b31a86d639d308b890ea8f03002aeb735a Mon Sep 17 00:00:00 2001
From: Anthony <bouillant.anthony@gmail.com>
Date: Thu, 3 Apr 2025 17:11:28 +0200
Subject: [PATCH] Refacto board print

---
 src/board.c | 71 ++++++++++++++++++++++++++++-------------------------
 1 file changed, 37 insertions(+), 34 deletions(-)

diff --git a/src/board.c b/src/board.c
index f8d640f..6e349fe 100644
--- a/src/board.c
+++ b/src/board.c
@@ -19,52 +19,55 @@ int destroy_board(int rows, int** board) {
 }
 
 void print_board(int rows, int cols, int** board) {
-    // Top border of the board
-    printf("\n┌");
-    for (int col = 0; col < cols; col++) {
-        printf("─");
-        if (col < cols - 1) {
-            printf("┬");
+    for (int row = -1; row <= rows; row++) {
+        if (row == -1) {
+            // Top border of the board
+            printf("\n┌");
+        } else if (row == rows) {
+            // Bottom border of the board
+            printf("└");
+        } else {
+            // Print left vertical border
+            printf("│");
         }
-    }
-    printf("┐\n");
 
-    // Print the board rows
-    for (int row = 0; row < rows; row++) {
-        // Print left vertical border
-        printf("│");
-        // Print data and vertical separators
         for (int col = 0; col < cols; col++) {
-            printf("%c", transform_state_to_char(board[row][col]));
+            if (row == -1 || row == rows) {
+                printf("─");
+            } else {
+                printf("%c", transform_state_to_char(board[row][col]));
+            }
+
             if (col < cols - 1) {
-                printf("│");
+                if (row == -1) {
+                    printf("┬");
+                } else if (row == rows) {
+                    printf("┴");
+                } else {
+                    printf("│");
+                }
             }
         }
-        // Print right vertical border
-        printf("│\n");
 
-        // Print row separator
-        if (row < rows - 1) {
-            printf("├");
-            for (int col = 0; col < cols; col++) {
-                printf("─");
-                if (col < cols - 1) {
-                    printf("┼");
+        if (row == -1) {
+            printf("┐\n");
+        } else if (row == rows) {
+            printf("┘\n");
+        } else {
+            printf("│\n");
+            if (row < rows - 1) {
+                printf("├");
+                for (int col = 0; col < cols; col++) {
+                    printf("─");
+                    if (col < cols - 1) {
+                        printf("┼");
+                    }
                 }
+                printf("┤\n");
             }
-            printf("┤\n");
         }
     }
 
-    // Print bottom border of the board
-    printf("└");
-    for (int col = 0; col < cols; col++) {
-        printf("─");
-        if (col < cols - 1) {
-            printf("┴");
-        }
-    }
-    printf("┘\n");
     for (int i = 1; i < cols + 1; i++) {
         printf(" %d", i);
     }
-- 
GitLab