summaryrefslogtreecommitdiff
path: root/src/console.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/console.c')
-rw-r--r--src/console.c18
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;