Rev 177 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 177 | Rev 193 | ||
---|---|---|---|
Line 141... | Line 141... | ||
141 | // now, disambiguate. |
141 | // now, disambiguate. |
142 | return (SAN_DisambiguateMove (move, new_move)); |
142 | return (SAN_DisambiguateMove (move, new_move)); |
143 | } |
143 | } |
144 | 144 | ||
145 | 145 | ||
146 | bool Move_DescribeInSAN (boardmove_t *move, boardmove_t * |
146 | bool Move_DescribeInSAN (boardmove_t *move, boardmove_t *previousmove, wchar_t *out_pgntext, size_t out_buflen, bool use_localized_abbreviations) |
147 | { |
147 | { |
148 | // convert a board and its part placements into a SAN notation, writing in the |
148 | // convert a board and its part placements into a SAN notation, writing in the out_pgntext buffer |
149 | 149 | ||
150 | int line; |
150 | int line; |
151 | int column; |
151 | int column; |
152 | boardslot_t *slot; |
152 | boardslot_t *slot; |
153 | bool needs_line; |
153 | bool needs_line; |
154 | bool needs_column; |
154 | bool needs_column; |
155 | 155 | ||
156 | // build move string in abbreviated algebraic notation |
156 | // build move string in abbreviated algebraic notation |
157 |
|
157 | out_pgntext[0] = 0; |
158 | 158 | ||
159 | // is it a king castling or a normal move ? |
159 | // is it a king castling or a normal move ? |
160 | if ((move->part == PART_KING) && (move->source[1] == 4) && (move->target[1] == 2)) |
160 | if ((move->part == PART_KING) && (move->source[1] == 4) && (move->target[1] == 2)) |
161 | wcscat_s ( |
161 | wcscat_s (out_pgntext, out_buflen, L"O-O-O"); // long castle |
162 | else if ((move->part == PART_KING) && (move->source[1] == 4) && (move->target[1] == 6)) |
162 | else if ((move->part == PART_KING) && (move->source[1] == 4) && (move->target[1] == 6)) |
163 | wcscat_s ( |
163 | wcscat_s (out_pgntext, out_buflen, L"O-O"); // short castle |
164 | else |
164 | else |
165 | { |
165 | { |
166 | // part identifier (omit it if pawn) |
166 | // part identifier (omit it if pawn) |
167 | if (move->part == PART_ROOK) |
- | |
168 |
|
167 | if (move->part == PART_ROOK) wcscat_s (out_pgntext, out_buflen, (use_localized_abbreviations ? options.part_letters.rook : L"R")); |
169 | else if (move->part == PART_KNIGHT) |
- | |
170 |
|
168 | else if (move->part == PART_KNIGHT) wcscat_s (out_pgntext, out_buflen, (use_localized_abbreviations ? options.part_letters.knight : L"N")); |
171 | else if (move->part == PART_BISHOP) |
- | |
172 |
|
169 | else if (move->part == PART_BISHOP) wcscat_s (out_pgntext, out_buflen, (use_localized_abbreviations ? options.part_letters.bishop : L"B")); |
173 | else if (move->part == PART_QUEEN) |
- | |
174 |
|
170 | else if (move->part == PART_QUEEN) wcscat_s (out_pgntext, out_buflen, (use_localized_abbreviations ? options.part_letters.queen : L"Q")); |
175 | else if (move->part == PART_KING) |
- | |
176 |
|
171 | else if (move->part == PART_KING) wcscat_s (out_pgntext, out_buflen, (use_localized_abbreviations ? options.part_letters.king : L"K")); |
177 | 172 | ||
178 | // is it a pawn taking ? |
173 | // is it a pawn taking ? |
179 | if ((move->part == PART_PAWN) && (move->has_captured)) |
174 | if ((move->part == PART_PAWN) && (move->has_captured)) |
180 | wcscat_s ( |
175 | wcscat_s (out_pgntext, out_buflen, COLUMN_TO_WSTRING (move->source[1])); |
181 | 176 | ||
182 | // else is there a possible ambiguity ? (not for pawns) |
177 | // else is there a possible ambiguity ? (not for pawns) |
183 | if ((move->part != PART_PAWN) && (Move_CountPartsByColorAndType (move, move->color, move->part) > 1)) |
178 | if ((move->part != PART_PAWN) && (Move_CountPartsByColorAndType (move, move->color, move->part) > 1)) |
184 | { |
179 | { |
185 | // assume we don't need to disambiguate neither by column nor by line |
180 | // assume we don't need to disambiguate neither by column nor by line |
Line 203... | Line 198... | ||
203 | } |
198 | } |
204 | } |
199 | } |
205 | 200 | ||
206 | // do we need to write start column or start line ? |
201 | // do we need to write start column or start line ? |
207 | if (needs_column) |
202 | if (needs_column) |
208 | wcscat_s ( |
203 | wcscat_s (out_pgntext, out_buflen, COLUMN_TO_WSTRING (move->source[1])); // if so, write start column |
209 | if (needs_line) |
204 | if (needs_line) |
210 | wcscat_s ( |
205 | wcscat_s (out_pgntext, out_buflen, LINE_TO_WSTRING (move->source[0])); // if so, write start line |
211 | } |
206 | } |
212 | 207 | ||
213 | // does it capture something ? |
208 | // does it capture something ? |
214 | if (move->has_captured) |
209 | if (move->has_captured) |
215 | wcscat_s ( |
210 | wcscat_s (out_pgntext, out_buflen, L"x"); |
216 | 211 | ||
217 | // target column, target line |
212 | // target column, target line |
218 | wcscat_s ( |
213 | wcscat_s (out_pgntext, out_buflen, COLUMN_TO_WSTRING (move->target[1])); |
219 | wcscat_s ( |
214 | wcscat_s (out_pgntext, out_buflen, LINE_TO_WSTRING (move->target[0])); |
220 | 215 | ||
221 | // is there a promotion ? |
216 | // is there a promotion ? |
222 | if (move->promotion_type |
217 | if (move->promotion_type != PART_NONE) |
- | 218 | { |
|
223 | wcscat_s ( |
219 | wcscat_s (out_pgntext, out_buflen, L"="); // drop the equal sign |
224 | else if (move->promotion_type == PART_KNIGHT) |
- | |
225 |
|
220 | if (move->promotion_type == PART_ROOK) wcscat_s (out_pgntext, out_buflen, (use_localized_abbreviations ? options.part_letters.rook : L"R")); |
226 | else if (move->promotion_type == |
221 | else if (move->promotion_type == PART_KNIGHT) wcscat_s (out_pgntext, out_buflen, (use_localized_abbreviations ? options.part_letters.knight : L"N")); |
227 |
|
222 | else if (move->promotion_type == PART_BISHOP) wcscat_s (out_pgntext, out_buflen, (use_localized_abbreviations ? options.part_letters.bishop : L"B")); |
228 | else if (move->promotion_type == PART_QUEEN) |
223 | else if (move->promotion_type == PART_QUEEN) wcscat_s (out_pgntext, out_buflen, (use_localized_abbreviations ? options.part_letters.queen : L"Q")); |
229 |
|
224 | else if (move->promotion_type == PART_KING) wcscat_s (out_pgntext, out_buflen, (use_localized_abbreviations ? options.part_letters.king : L"K")); // weird promotion type... |
230 |
|
225 | } |
231 | wcscat_s (move->pgntext, WCHAR_SIZEOF (move->pgntext), L"=K"); |
- | |
232 | 226 | ||
233 | // is there a check or a checkmate ? |
227 | // is there a check or a checkmate ? |
234 | if (move->is_check) |
228 | if (move->is_check) |
235 | { |
229 | { |
236 | if (move->is_stalemate) |
230 | if (move->is_stalemate) |
237 | wcscat_s ( |
231 | wcscat_s (out_pgntext, out_buflen, L"#"); // checkmate |
238 | else |
232 | else |
239 | wcscat_s ( |
233 | wcscat_s (out_pgntext, out_buflen, L"+"); // normal check |
240 | } |
234 | } |
241 | 235 | ||
242 | // is it an en passant coup ? |
236 | // is it an en passant coup ? |
243 | if (move->is_enpassant) |
237 | if (move->is_enpassant) |
244 | wcscat_s ( |
238 | wcscat_s (out_pgntext, out_buflen, L"e.p."); |
245 | } |
239 | } |
246 | 240 | ||
247 | return (true); // finished |
241 | return (true); // finished |
248 | } |
242 | } |
249 | 243 |