src/chess/knight.c

changeset 195
27d02ccb0cef
parent 194
619f07c95894
equal deleted inserted replaced
194:619f07c95894 195:27d02ccb0cef
37 37
38 return (dx == 2 && dy == 1) || (dx == 1 && dy == 2); 38 return (dx == 2 && dy == 1) || (dx == 1 && dy == 2);
39 } 39 }
40 40
41 size_t knight_moves(const GameState *gamestate, 41 size_t knight_moves(const GameState *gamestate,
42 Color c, Rank r, File f, Move *moves) { 42 Color c, File f, Rank r, Move *moves) {
43 43
44 size_t count = 0; 44 size_t count = 0;
45 const int offsets[8][2] = { 45 const int offsets[8][2] = {
46 { 2, 1}, 46 { 2, 1},
47 { 2, -1}, 47 { 2, -1},
62 moves[count].piece = mkpiece(KNIGHT, c); 62 moves[count].piece = mkpiece(KNIGHT, c);
63 moves[count].fromrank = r; 63 moves[count].fromrank = r;
64 moves[count].fromfile = f; 64 moves[count].fromfile = f;
65 moves[count].torank = rank; 65 moves[count].torank = rank;
66 moves[count].tofile = file; 66 moves[count].tofile = file;
67 moves[count].capture = piece_at(gamestate, rank, file) != 0; 67 moves[count].capture = piece_at(gamestate, file, rank) != 0;
68 count++; 68 count++;
69 } 69 }
70 } 70 }
71 71
72 return count; 72 return count;

mercurial