diff options
| author | Kai Stevenson <kai@kaistevenson.com> | 2023-03-24 15:44:02 -0700 |
|---|---|---|
| committer | Kai Stevenson <kai@kaistevenson.com> | 2023-03-24 15:44:02 -0700 |
| commit | 6b5a8486c4baa2642a4f0e08e241f1f0ef530fde (patch) | |
| tree | ee2f368fc2c8a54f477f9c48172055cf3e75e02c /src/console.c | |
| parent | 80afcfd294f625d9f8e87f66fbd350a9b9742459 (diff) | |
Diffstat (limited to 'src/console.c')
| -rw-r--r-- | src/console.c | 18 |
1 files changed, 10 insertions, 8 deletions
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; |
