summaryrefslogtreecommitdiff
path: root/lib/print.c
diff options
context:
space:
mode:
authorRaúl Benencia <rul@kalgan.cc>2015-03-28 17:40:19 -0300
committerRaúl Benencia <rul@kalgan.cc>2015-03-28 17:40:19 -0300
commitcf31f0866ef4f33890a56a48631a2440e801ba6c (patch)
tree18b7bdf030f10498be6b3a8a6f4fb8adb2216cd3 /lib/print.c
parent739262092f1287f254c9379fec0cad97dad65b6a (diff)
print coordinatescoords
Diffstat (limited to 'lib/print.c')
-rw-r--r--lib/print.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/print.c b/lib/print.c
index 39b6d8e..8bf63fb 100644
--- a/lib/print.c
+++ b/lib/print.c
@@ -9,6 +9,7 @@
static void _print_row_separator() {
int j;
+ printf(" ");
for (j = 0; j < SIZE; j++)
printf("+---");
@@ -22,6 +23,30 @@ static Coord _next_coord(Coord c, Color side) {
return coord_prev(c);
}
+static int _first_column(char col, Color side) {
+ if (side == WHITE && col == 'a')
+ return 1;
+
+ if (side == BLACK && col == 'h')
+ return 1;
+
+ return 0;
+}
+
+static void _print_columns(Color side) {
+ char c;
+
+ putchar(' ');
+ if (side == WHITE)
+ for (c = 'a'; c <= 'h'; c++)
+ printf(" %c", c);
+ else
+ for (c = 'h'; c >= 'a'; c--)
+ printf(" %c", c);
+
+ putchar('\n');
+}
+
/* Printing related functions */
void print_piece(Piece p) {
putchar(piece_character(p));
@@ -47,6 +72,10 @@ void print_board(Board b, Color side) {
_print_row_separator();
while (!coord_is_null(c)) {
+ // Print row if it's the first column
+ if (_first_column(coord_get_col(c), side))
+ printf("%c ", current_row);
+
// Print the square
printf("| ");
print_square(board_get_square(b, c));
@@ -63,4 +92,6 @@ void print_board(Board b, Color side) {
current_row = coord_get_row(c);
}
}
+
+ _print_columns(side);
}
nihil fit ex nihilo