summaryrefslogtreecommitdiff
path: root/lib/piece.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/piece.c')
-rw-r--r--lib/piece.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/lib/piece.c b/lib/piece.c
new file mode 100644
index 0000000..bbe0bdc
--- /dev/null
+++ b/lib/piece.c
@@ -0,0 +1,53 @@
+#include <ctype.h>
+#include "piece.h"
+
+#ifdef UTF8
+
+# TODO
+int piece_character(Piece p) {
+ switch (p.color) {
+
+ case WHITE:
+ switch (p.type) {
+ case PAWN: return '♙';
+ case ROCK: return '♖';
+ case KNIGHT: return '♘';
+ case BISHOP: return '♗';
+ case QUEEN: return '♕';
+ case KING: return '♔';
+ }
+
+ case BLACK:
+ switch (p.type) {
+ case PAWN: return '♟';
+ case ROCK: return '♜';
+ case KNIGHT: return '♞';
+ case BISHOP: return '♝';
+ case QUEEN: return '♛';
+ case KING: return '♚';
+ }
+ }
+}
+
+#else
+
+int piece_character(Piece p) {
+ int res;
+
+ switch (p.type) {
+
+ case PAWN: res = 'p'; break;
+ case ROCK: res = 'r'; break;
+ case KNIGHT: res = 'n'; break;
+ case BISHOP: res = 'b'; break;
+ case QUEEN: res = 'q'; break;
+ case KING: res = 'k'; break;
+ }
+
+ if (p.color == BLACK)
+ return toupper(res);
+
+ return res;
+}
+
+#endif
nihil fit ex nihilo