| 106 |
106 |
| 107 return str[0] == '-' ? 1 : 2; |
107 return str[0] == '-' ? 1 : 2; |
| 108 } |
108 } |
| 109 |
109 |
| 110 static size_t fen_halfmove(char *str, const GameState *gamestate) { |
110 static size_t fen_halfmove(char *str, const GameState *gamestate) { |
| 111 // TODO: respect a possible fifty_ctr_start |
111 unsigned int hm = gamestate->fifty_cntr_start; |
| 112 unsigned int hm = 0; |
|
| 113 for (unsigned int i = 0; i < gamestate->movecount; i++) { |
112 for (unsigned int i = 0; i < gamestate->movecount; i++) { |
| 114 if (gamestate->moves[i].capture |
113 if (gamestate->moves[i].capture |
| 115 || piece_type(gamestate->moves[i].piece) == PAWN) { |
114 || piece_type(gamestate->moves[i].piece) == PAWN) { |
| 116 hm = 0; |
115 hm = 0; |
| 117 } else { |
116 } else { |
| 121 |
120 |
| 122 return sprintf(str, "%u", hm); |
121 return sprintf(str, "%u", hm); |
| 123 } |
122 } |
| 124 |
123 |
| 125 static size_t fen_movenr(char *str, const GameState *gamestate) { |
124 static size_t fen_movenr(char *str, const GameState *gamestate) { |
| 126 unsigned mc = gamestate->movecount + gamestate->move_start; |
125 return sprintf(str, "%u", move_number(gamestate)); |
| 127 return sprintf(str, "%u", 1 + mc / 2); |
|
| 128 } |
126 } |
| 129 |
127 |
| 130 static size_t fen_space(char *str) { |
128 static size_t fen_space(char *str) { |
| 131 *str = ' '; |
129 *str = ' '; |
| 132 return 1; |
130 return 1; |