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/piece.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 lib/piece.c (limited to 'lib/piece.c') 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 +#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 -- cgit v1.2.3