blob: 036a9a335057d4604fe76f5bb2f8ab5bb306f19c (
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
54
55
56
57
58
59
60
61
62
|
#include <ctype.h>
#include <stdlib.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
Piece* piece_new(Color c, PieceType t) {
Piece* p = malloc(sizeof(Piece));
p->color = c; p->type = t;
return p;
}
|