src/chess/rook.c

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

mercurial