From e7497d2dde46b8fae5493c127f4dc33307a65da5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Benencia?= Date: Fri, 27 Mar 2015 11:19:16 -0300 Subject: initial commit --- lib/print.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 lib/print.c (limited to 'lib/print.c') diff --git a/lib/print.c b/lib/print.c new file mode 100644 index 0000000..431641e --- /dev/null +++ b/lib/print.c @@ -0,0 +1,45 @@ +#include +#include + +#include "print.h" +#include "piece.h" + +/* Printing related functions */ +void print_piece(Piece p) { + putchar(piece_character(p)); +} + +void print_square(Square s) { + puts("+-+\n|"); + + if (s.piece == NULL) + switch (s.color) { + case WHITE: + putchar(' '); + break;; + case BLACK: + putchar('/'); + break; + default: + perror("Wait... what?\n"); + exit(EXIT_FAILURE); + } + else + print_piece(*s.piece); + + puts("|\n+-+"); + + return; +} + +void print_board(Board *b) { + int i, j; + + for (i = 0; i < SIZE; i++) { + for (j = 0; j < SIZE; j++) { + print_square(*b[i][j]); + } + + putchar('\n'); + } +} -- cgit v1.2.3