src/chess/rules.c

changeset 186
8230904458a7
parent 185
c0acc89d6c01
equal deleted inserted replaced
185:c0acc89d6c01 186:8230904458a7
533 gamestate_cleanup(&simulation); 533 gamestate_cleanup(&simulation);
534 return canescape ? 1 : 2; 534 return canescape ? 1 : 2;
535 } 535 }
536 536
537 537
538 static void format_move_impl(const GameState *gamestate, Move *move) { 538 void format_move(const GameState *gamestate, Move *move) {
539 char *string = &(move->string[0]); 539 char *string = &(move->string[0]);
540 540
541 /* at least 8 characters should be available, wipe them out */ 541 /* at least 8 characters should be available, wipe them out */
542 memset(string, 0, 8); 542 memset(string, 0, 8);
543 543
618 if (move->checkmate) { 618 if (move->checkmate) {
619 string[idx++] = '#'; 619 string[idx++] = '#';
620 } else if (move->check) { 620 } else if (move->check) {
621 string[idx++] = '+'; 621 string[idx++] = '+';
622 } 622 }
623 }
624
625 void format_move(const GameState *gamestate, Move *move) {
626 /* correct check/checkmate flags */
627 move->check = move->checkmate = false;
628 switch (determine_check_or_checkmate(gamestate, move)) {
629 case 2: move->checkmate = true;
630 case 1: move->check = true;
631 }
632
633 /* format the move string */
634 format_move_impl(gamestate, move);
635 } 623 }
636 624
637 static int validate_move_rules(const GameState *gamestate, const Move *move) { 625 static int validate_move_rules(const GameState *gamestate, const Move *move) {
638 assert((move->piece & ~(PIECE_MASK|COLOR_MASK)) == 0); 626 assert((move->piece & ~(PIECE_MASK|COLOR_MASK)) == 0);
639 627
1023 if (len < 1 || len > 6) { 1011 if (len < 1 || len > 6) {
1024 return INVALID_MOVE_SYNTAX; 1012 return INVALID_MOVE_SYNTAX;
1025 } 1013 }
1026 char mstr[8]; 1014 char mstr[8];
1027 strcpy(mstr, pstr); 1015 strcpy(mstr, pstr);
1016 strcpy(move->string, pstr);
1028 1017
1029 /* evaluate check/checkmate flags */ 1018 /* evaluate check/checkmate flags */
1030 if (mstr[len-1] == '+' || mstr[len-1] == '#') { 1019 if (mstr[len-1] == '+' || mstr[len-1] == '#') {
1031 move->check = true; 1020 move->check = true;
1032 move->checkmate = mstr[len-1] == '#'; 1021 move->checkmate = mstr[len-1] == '#';
1153 } 1142 }
1154 1143
1155 return VALID_MOVE_SYNTAX; 1144 return VALID_MOVE_SYNTAX;
1156 } 1145 }
1157 1146
1158 int eval_move2(const GameState *gamestate, 1147 static int eval_move2(const GameState *gamestate,
1159 const char *mstr, Color color, Move *move, bool lazy) { 1148 const char *mstr, Color color, Move *move, bool lazy) {
1160 int result = eval_move1(mstr, move, color); 1149 int result = eval_move1(mstr, move, color);
1161 if (result == VALID_MOVE_SYNTAX) { 1150 if (result == VALID_MOVE_SYNTAX) {
1162 if (move->fromfile == POS_UNSPECIFIED 1151 if (move->fromfile == POS_UNSPECIFIED
1163 || move->fromrow == POS_UNSPECIFIED) { 1152 || move->fromrow == POS_UNSPECIFIED) {
1170 switch (determine_check_or_checkmate(gamestate, move)) { 1159 switch (determine_check_or_checkmate(gamestate, move)) {
1171 case 2: move->checkmate = true; 1160 case 2: move->checkmate = true;
1172 case 1: move->check = true; 1161 case 1: move->check = true;
1173 } 1162 }
1174 } 1163 }
1175
1176 /* format the move string */
1177 format_move_impl(gamestate, move);
1178 } 1164 }
1179 } 1165 }
1180 return result; 1166 return result;
1181 } 1167 }
1182 1168

mercurial