| 714 } else { |
714 } else { |
| 715 return INVALID_POSITION; |
715 return INVALID_POSITION; |
| 716 } |
716 } |
| 717 } |
717 } |
| 718 |
718 |
| 719 static int eval_move1(char *mstr, Move *move, uint8_t color) { |
719 static int eval_move1(const char *pstr, Move *move, uint8_t color) { |
| 720 memset(move, 0, sizeof(Move)); |
720 memset(move, 0, sizeof(Move)); |
| 721 move->fromfile = POS_UNSPECIFIED; |
721 move->fromfile = POS_UNSPECIFIED; |
| 722 move->fromrow = POS_UNSPECIFIED; |
722 move->fromrow = POS_UNSPECIFIED; |
| 723 |
723 |
| 724 size_t len = strlen(mstr); |
724 size_t len = strlen(pstr); |
| 725 if (len < 1 || len > 6) { |
725 if (len < 1 || len > 6) { |
| 726 return INVALID_MOVE_SYNTAX; |
726 return INVALID_MOVE_SYNTAX; |
| 727 } |
727 } |
| |
728 char mstr[8]; |
| |
729 strcpy(mstr, pstr); |
| 728 |
730 |
| 729 /* evaluate check/checkmate flags */ |
731 /* evaluate check/checkmate flags */ |
| 730 if (mstr[len-1] == '+' || mstr[len-1] == '#') { |
732 if (mstr[len-1] == '+' || mstr[len-1] == '#') { |
| 731 len--; mstr[len] = '\0'; |
733 len--; mstr[len] = '\0'; |
| 732 move->check = true; |
734 move->check = true; |
| 842 } |
844 } |
| 843 |
845 |
| 844 return VALID_MOVE_SYNTAX; |
846 return VALID_MOVE_SYNTAX; |
| 845 } |
847 } |
| 846 |
848 |
| 847 int eval_move(GameState *gamestate, char *mstr, Move *move, uint8_t color) { |
849 int eval_move(GameState *gamestate, const char *mstr, |
| |
850 Move *move, uint8_t color) { |
| 848 int result = eval_move1(mstr, move, color); |
851 int result = eval_move1(mstr, move, color); |
| 849 if (result == VALID_MOVE_SYNTAX) { |
852 if (result == VALID_MOVE_SYNTAX) { |
| 850 if (move->fromfile == POS_UNSPECIFIED |
853 if (move->fromfile == POS_UNSPECIFIED |
| 851 || move->fromrow == POS_UNSPECIFIED) { |
854 || move->fromrow == POS_UNSPECIFIED) { |
| 852 return getlocation(gamestate, move); |
855 return getlocation(gamestate, move); |
| 855 } |
858 } |
| 856 } |
859 } |
| 857 return result; |
860 return result; |
| 858 } |
861 } |
| 859 |
862 |
| 860 int check_move(char *mstr, uint8_t color) { |
863 int check_move(const char *mstr, uint8_t color) { |
| 861 Move move; |
864 Move move; |
| 862 return eval_move1(mstr, &move, color); |
865 return eval_move1(mstr, &move, color); |
| 863 } |
866 } |
| 864 |
867 |
| 865 bool is_protected(GameState *gamestate, uint8_t row, uint8_t file, |
868 bool is_protected(GameState *gamestate, uint8_t row, uint8_t file, |