src/chess/bishop.c

changeset 169
9962f5d98764
parent 163
2a6d83f4677e
child 170
bde99d803caf
equal deleted inserted replaced
168:663676cfef6e 169:9962f5d98764
50 } 50 }
51 } 51 }
52 52
53 return false; 53 return false;
54 } 54 }
55
56 size_t bishop_moves(GameState *gamestate, Color c, Row r, File f, Move *moves) {
57
58 size_t count = 0;
59 const int directions[4][2] = {
60 { 1, 1},
61 { 1, -1},
62 {-1, 1},
63 {-1, -1}
64 };
65
66 for (size_t i = 0 ; i < 4 ; i++) {
67 int row = r + directions[i][0];
68 int file = f + directions[i][1];
69
70 while (isidx(row) && isidx(file)) {
71 moves[count] = (Move){0};
72 moves[count].piece = mkpiece(BISHOP, c);
73 moves[count].fromrow = r;
74 moves[count].fromfile = f;
75 moves[count].torow = row;
76 moves[count].tofile = file;
77 moves[count].capture = piece_at(gamestate, row, file) != 0;
78 count++;
79
80 row += directions[i][0];
81 file += directions[i][1];
82 }
83 }
84
85 return count;
86 }

mercurial