src/chess/rules.c

changeset 166
1a9b662bc201
parent 165
3e27c99ed721
child 167
fd1d3f0a7a73
equal deleted inserted replaced
165:3e27c99ed721 166:1a9b662bc201
1038 Move move; 1038 Move move;
1039 return eval_move1(mstr, &move, color); 1039 return eval_move1(mstr, &move, color);
1040 } 1040 }
1041 1041
1042 bool is_protected(const GameState *gamestate, Row row, File file, Color color) { 1042 bool is_protected(const GameState *gamestate, Row row, File file, Color color) {
1043 Move threats[16]; 1043 Move candidates[16];
1044 size_t threatcount; 1044 size_t ccount;
1045 if (get_real_threats(gamestate, row, file, color, threats, &threatcount)) { 1045 /* we need all candidates - not only threats! */
1046 for (size_t i = 0 ; i < threatcount ; i++) { 1046 if (get_candidates(gamestate, row, file, color, candidates, &ccount)) {
1047 if (threats[i].piece != (color|KING)) { 1047 for (size_t i = 0 ; i < ccount ; i++) {
1048 return true; 1048 /* skip the king */
1049 } 1049 if (piece_type(candidates[i].piece) == KING) continue;
1050 } 1050 /* skip pinned pieces */
1051 return false; 1051 if (is_pinned(gamestate, &candidates[i])) continue;
1052 } else { 1052 /* found one */
1053 return false; 1053 return true;
1054 } 1054 }
1055 }
1056 return false;
1055 } 1057 }
1056 1058
1057 uint16_t remaining_movetime(const GameState *gamestate, Color color) { 1059 uint16_t remaining_movetime(const GameState *gamestate, Color color) {
1058 unsigned move_number = gamestate->movecount; 1060 unsigned move_number = gamestate->movecount;
1059 if (color == BLACK) { 1061 if (color == BLACK) {

mercurial