summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/chess.c2
-rw-r--r--src/console.c18
-rw-r--r--src/console.h2
3 files changed, 12 insertions, 10 deletions
diff --git a/src/chess.c b/src/chess.c
index 42adad0..a90b9f3 100644
--- a/src/chess.c
+++ b/src/chess.c
@@ -67,7 +67,7 @@ int main(int argc, char **argv) {
while (1) {
//draw the board, write some info
clear_screen();
- draw_board(board.pieces);
+ draw_board(board.pieces, !isWhite);
if (turn == isWhite) {
/* awaiting the remote player */
printf("Waiting for %s's move\n", turn ? "black" : "white");
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;
diff --git a/src/console.h b/src/console.h
index c0ca9f7..090647b 100644
--- a/src/console.h
+++ b/src/console.h
@@ -5,7 +5,7 @@
#define COLOR_WARN "\033[5;31;49m"
#define COLOR_RESET "\033[0m"
-void draw_board(int** board);
+void draw_board(int** board, char flipBoard);
vector_t user_input_pos();
void clear_screen();
void warn_user(char* message);