summaryrefslogtreecommitdiff
path: root/lib/piece.c
blob: bbe0bdc284ee052a68478a060db0544fe4a6dd64 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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