| 335 } |
335 } |
| 336 } |
336 } |
| 337 |
337 |
| 338 static int validate_move_rules(GameState *gamestate, Move *move) { |
338 static int validate_move_rules(GameState *gamestate, Move *move) { |
| 339 /* validate indices (don't trust opponent) */ |
339 /* validate indices (don't trust opponent) */ |
| 340 if (!chkidx(move)) { |
340 if (!isidx(move->fromrow) || !isidx(move->fromfile) || |
| 341 return INVALID_POSITION; |
341 !isidx(move->torow) || !isidx(move->tofile)) { |
| |
342 return INVALID_MOVE_SYNTAX; |
| 342 } |
343 } |
| 343 |
344 |
| 344 /* must move */ |
345 /* must move */ |
| 345 if (move->fromfile == move->tofile && move->fromrow == move->torow) { |
346 if (move->fromfile == move->tofile && move->fromrow == move->torow) { |
| 346 return INVALID_MOVE_SYNTAX; |
347 return INVALID_MOVE_SYNTAX; |
| 842 return NEED_PROMOTION; |
843 return NEED_PROMOTION; |
| 843 } |
844 } |
| 844 |
845 |
| 845 move->piece |= color; |
846 move->piece |= color; |
| 846 |
847 |
| 847 if (!chkidx_to(move)) { |
848 /* up to this point |
| 848 return INVALID_POSITION; |
849 * destination indices must be specified and valid |
| |
850 * source indices must either be valid or unspecified |
| |
851 */ |
| |
852 if (!isidxr(move->fromrow) || !isidxr(move->fromfile) || |
| |
853 !isidx(move->torow) || !isidx(move->tofile)) { |
| |
854 return INVALID_MOVE_SYNTAX; |
| 849 } |
855 } |
| 850 |
856 |
| 851 return VALID_MOVE_SYNTAX; |
857 return VALID_MOVE_SYNTAX; |
| 852 } |
858 } |
| 853 |
859 |
| 856 int result = eval_move1(mstr, move, color); |
862 int result = eval_move1(mstr, move, color); |
| 857 if (result == VALID_MOVE_SYNTAX) { |
863 if (result == VALID_MOVE_SYNTAX) { |
| 858 if (move->fromfile == POS_UNSPECIFIED |
864 if (move->fromfile == POS_UNSPECIFIED |
| 859 || move->fromrow == POS_UNSPECIFIED) { |
865 || move->fromrow == POS_UNSPECIFIED) { |
| 860 return getlocation(gamestate, move); |
866 return getlocation(gamestate, move); |
| 861 } else if (!chkidx_from(move)) { |
|
| 862 return INVALID_POSITION; |
|
| 863 } |
867 } |
| 864 } |
868 } |
| 865 return result; |
869 return result; |
| 866 } |
870 } |
| 867 |
871 |