From 6b5a8486c4baa2642a4f0e08e241f1f0ef530fde Mon Sep 17 00:00:00 2001 From: Kai Stevenson Date: Fri, 24 Mar 2023 15:44:02 -0700 Subject: displays board backwards when playing black --- src/console.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'src/console.c') diff --git a/src/console.c b/src/console.c index 400a7f5..ef7d808 100644 --- a/src/console.c +++ b/src/console.c @@ -5,19 +5,21 @@ #include "chesshelpers.h" #include "console.h" -void draw_board(int** board) { - printf(" A B C D E F G H\n"); - int tileColor = 0; +void draw_board(int** board, char flipBoard) { + printf(!flipBoard ? " A B C D E F G H\n" : " H G F E D C B A\n"); + char tileColor = 0; for(int r = 0; r < 8; r++) { + int rf = !flipBoard ? r : 7 - r; tileColor = !tileColor; char* line = calloc(2 + (8 * 16) + 9, sizeof(char)); - line[0] = '8' - r; + line[0] = '8' - rf; line[1] = ' '; - for(int c = 0; c < 8; c++) { + for(int c = 0; c < 8; c++) { + int cf = !flipBoard ? c : 7 - c; tileColor = !tileColor; strcat(line, tileColor == 0 ? COLOR_CHESS_WHITE : COLOR_CHESS_BLACK); - if(board[c][r] <= 6) { - switch(board[c][r]) { + if(board[cf][rf] <= 6) { + switch(board[cf][rf]) { case 0: strcat(line, " "); break; @@ -42,7 +44,7 @@ void draw_board(int** board) { } } else { - switch(board[c][r] - 6) { + switch(board[cf][rf] - 6) { case pawn: strcat(line, "p"); break; -- cgit v1.3.1