Rev 74 | Rev 177 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 74 | Rev 82 | ||
|---|---|---|---|
| Line 19... | Line 19... | ||
| 19 | // helper function to translate a SAN move into numeric from and to positions on the specified board |
19 | // helper function to translate a SAN move into numeric from and to positions on the specified board |
| 20 | // WARNING: THIS FUNCTION DOES NOT RETURN WITH A FULLY CONSTRUCTED MOVE! |
20 | // WARNING: THIS FUNCTION DOES NOT RETURN WITH A FULLY CONSTRUCTED MOVE! |
| 21 | 21 | ||
| 22 | // FIXME: accelerate this function by reducing the number of towupper()/towlower() calls |
22 | // FIXME: accelerate this function by reducing the number of towupper()/towlower() calls |
| 23 | 23 | ||
| - | 24 | wchar_t character; |
|
| 24 | int fieldstart; |
25 | int fieldstart; |
| 25 | int fieldstop; |
26 | int fieldstop; |
| 26 | int length; |
27 | int length; |
| 27 | 28 | ||
| 28 | // first, get move string length |
29 | // first, get move string length |
| Line 79... | Line 80... | ||
| 79 | { |
80 | { |
| 80 | // does it end with the optional "en passant" prefix ? |
81 | // does it end with the optional "en passant" prefix ? |
| 81 | if ((fieldstop >= fieldstart + 4) && (wcsncmp (&new_move->pgntext[fieldstop - 3], L"e.p.", 4) == 0)) |
82 | if ((fieldstop >= fieldstart + 4) && (wcsncmp (&new_move->pgntext[fieldstop - 3], L"e.p.", 4) == 0)) |
| 82 | fieldstop -= 4; // if so, chop it off |
83 | fieldstop -= 4; // if so, chop it off |
| 83 | 84 | ||
| 84 | // is the last character a part type ? (WARNING: PART TYPES ARE |
85 | // is the last character a part type ? (WARNING: PART TYPES ARE SUPPOSED TO BE UPPERCASE BUT SOME ENGINES DON'T COMPLY AND SEND IT IN LOWERCASE) |
| 85 | if |
86 | if (fieldstop >= fieldstart) |
| 86 | { |
87 | { |
| 87 | new_move->promotion_type = PART_ROOK; // there's a promotion to rook |
- | |
| 88 | fieldstop--; // proceed to previous character |
- | |
| 89 | } |
- | |
| 90 |
|
88 | character = towupper (new_move->pgntext[fieldstop]); // get the character here |
| 91 | { |
- | |
| 92 | new_move->promotion_type = |
89 | if (character == L'R') { fieldstop--; new_move->promotion_type = PART_ROOK; } // there's a promotion to rook |
| 93 | fieldstop--; // proceed to previous character |
- | |
| 94 | } |
- | |
| 95 | else if ( |
90 | else if (character == L'N') { fieldstop--; new_move->promotion_type = PART_KNIGHT; } // there's a promotion to knight |
| 96 | { |
- | |
| 97 | new_move->promotion_type = PART_BISHOP; // there's a promotion to bishop |
91 | else if (character == L'B') { fieldstop--; new_move->promotion_type = PART_BISHOP; } // there's a promotion to bishop |
| 98 | fieldstop--; // proceed to previous character |
- | |
| 99 | } |
- | |
| 100 | else if ((fieldstop >= fieldstart) && (new_move->pgntext[fieldstop] == L'Q')) |
- | |
| 101 | { |
- | |
| 102 | new_move->promotion_type = PART_QUEEN; // there's a promotion to queen |
92 | else if (character == L'Q') { fieldstop--; new_move->promotion_type = PART_QUEEN; } // there's a promotion to queen |
| 103 | fieldstop--; // proceed to previous character |
- | |
| 104 | } |
93 | } |
| 105 | 94 | ||
| 106 | // is there the promotion's equal sign ? |
95 | // is there the promotion's equal sign ? |
| 107 | if ((fieldstop >= fieldstart) && (new_move->pgntext[fieldstop] == L'=')) |
96 | if ((fieldstop >= fieldstart) && (new_move->pgntext[fieldstop] == L'=')) |
| 108 | fieldstop--; // skip it, it's redundant |
97 | fieldstop--; // skip it, it's redundant |