summaryrefslogtreecommitdiff
path: root/lib/print.c
diff options
context:
space:
mode:
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