summaryrefslogtreecommitdiff
path: root/lib/piece.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/piece.c
initial commit
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