diff options
author | Raúl Benencia <rul@kalgan.cc> | 2015-03-27 11:19:16 -0300 |
---|---|---|
committer | Raúl Benencia <rul@kalgan.cc> | 2015-03-27 11:19:16 -0300 |
commit | e7497d2dde46b8fae5493c127f4dc33307a65da5 (patch) | |
tree | 4f60b18a3cf917b201f627bc448debafcf04a38b /lib/piece.c |
initial commit
Diffstat (limited to 'lib/piece.c')
-rw-r--r-- | lib/piece.c | 53 |
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 |