summaryrefslogtreecommitdiff
path: root/lib/print.c
diff options
context:
space:
mode:
authorRaúl Benencia <rul@kalgan.cc>2015-03-27 11:19:16 -0300
committerRaúl Benencia <rul@kalgan.cc>2015-03-27 11:19:16 -0300
commite7497d2dde46b8fae5493c127f4dc33307a65da5 (patch)
tree4f60b18a3cf917b201f627bc448debafcf04a38b /lib/print.c
initial commit
Diffstat (limited to 'lib/print.c')
-rw-r--r--lib/print.c45
1 files changed, 45 insertions, 0 deletions
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 <stdio.h>
+#include <stdlib.h>
+
+#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');
+ }
+}
nihil fit ex nihilo