src/chess/fen.c

changeset 163
2a6d83f4677e
parent 134
ce2d285d2ccb
equal deleted inserted replaced
162:f0fc70b6f8f9 163:2a6d83f4677e
40 if (gamestate->board[row][file]) { 40 if (gamestate->board[row][file]) {
41 if (skip > 0) { 41 if (skip > 0) {
42 str[i++] = '0'+skip; 42 str[i++] = '0'+skip;
43 skip = 0; 43 skip = 0;
44 } 44 }
45 switch (gamestate->board[row][file] & ~ENPASSANT_THREAT) { 45 switch (piece_at(gamestate, row, file)) {
46 case WHITE|KING: str[i++] = 'K'; break; 46 case WHITE|KING: str[i++] = 'K'; break;
47 case WHITE|QUEEN: str[i++] = 'Q'; break; 47 case WHITE|QUEEN: str[i++] = 'Q'; break;
48 case WHITE|BISHOP: str[i++] = 'B'; break; 48 case WHITE|BISHOP: str[i++] = 'B'; break;
49 case WHITE|KNIGHT: str[i++] = 'N'; break; 49 case WHITE|KNIGHT: str[i++] = 'N'; break;
50 case WHITE|ROOK: str[i++] = 'R'; break; 50 case WHITE|ROOK: str[i++] = 'R'; break;
118 static size_t fen_enpassant(char *str, GameState *gamestate) { 118 static size_t fen_enpassant(char *str, GameState *gamestate) {
119 119
120 str[0] = '-'; 120 str[0] = '-';
121 121
122 for (int file = 0 ; file < 8 ; file++) { 122 for (int file = 0 ; file < 8 ; file++) {
123 if (gamestate->board[3][file] & ENPASSANT_THREAT) { 123 if (enpassant_threat_exists(gamestate, 3, file)) {
124 str[0] = filechr(file); 124 str[0] = filechr(file);
125 str[1] = rowchr(2); 125 str[1] = rowchr(2);
126 } 126 }
127 if (gamestate->board[4][file] & ENPASSANT_THREAT) { 127 if (enpassant_threat_exists(gamestate, 4, file)) {
128 str[0] = filechr(file); 128 str[0] = filechr(file);
129 str[1] = rowchr(5); 129 str[1] = rowchr(5);
130 } 130 }
131 } 131 }
132 132
135 135
136 static size_t fen_halfmove(char *str, GameState *gamestate) { 136 static size_t fen_halfmove(char *str, GameState *gamestate) {
137 unsigned int hm = 0; 137 unsigned int hm = 0;
138 for (unsigned int i = 0; i < gamestate->movecount; i++) { 138 for (unsigned int i = 0; i < gamestate->movecount; i++) {
139 if (gamestate->moves[i].capture 139 if (gamestate->moves[i].capture
140 || (gamestate->moves[i].piece & PIECE_MASK) == PAWN) { 140 || piece_type(gamestate->moves[i].piece) == PAWN) {
141 hm = 0; 141 hm = 0;
142 } else { 142 } else {
143 hm++; 143 hm++;
144 } 144 }
145 } 145 }

mercurial