src/chess/king.c

changeset 98
9cb41383540f
parent 80
b980a7192b5a
equal deleted inserted replaced
97:f87cad9445b4 98:9cb41383540f
31 #include "king.h" 31 #include "king.h"
32 #include <stdlib.h> 32 #include <stdlib.h>
33 33
34 static bool king_castling_chkmoved(GameState *gamestate, 34 static bool king_castling_chkmoved(GameState *gamestate,
35 uint8_t row, uint8_t file) { 35 uint8_t row, uint8_t file) {
36 36
37 MoveList *ml = gamestate->movelist; 37 for (unsigned i = 0; i < gamestate->movecount; i++) {
38 while (ml) { 38 if (gamestate->moves[i].fromfile == file
39 if (ml->move.fromfile == file && ml->move.fromrow == row) { 39 && gamestate->moves[i].fromrow == row) {
40 return true; 40 return true;
41 } 41 }
42 ml = ml->next;
43 } 42 }
44 43
45 return false; 44 return false;
46 } 45 }
47 46
77 if (abs(move->tofile - move->fromfile) == 2) { 76 if (abs(move->tofile - move->fromfile) == 2) {
78 if (move->tofile == fileidx('c')) { 77 if (move->tofile == fileidx('c')) {
79 blocked |= gamestate->board[move->torow][fileidx('b')]; 78 blocked |= gamestate->board[move->torow][fileidx('b')];
80 } 79 }
81 uint8_t midfile = (move->tofile+move->fromfile)/2; 80 uint8_t midfile = (move->tofile+move->fromfile)/2;
82 blocked |= gamestate->lastmove->move.check || 81 blocked |= last_move(gamestate).check ||
83 gamestate->board[move->torow][midfile] || 82 gamestate->board[move->torow][midfile] ||
84 is_covered(gamestate, move->torow, midfile, opponent_color); 83 is_covered(gamestate, move->torow, midfile, opponent_color);
85 } 84 }
86 85
87 return blocked; 86 return blocked;

mercurial