probably made the ROOK, BISHOP and QUEEN moves work

This commit is contained in:
Odweta
2026-02-18 15:11:50 +01:00
parent ec44c7c07f
commit 357e22fd38
+46 -10
View File
@@ -75,23 +75,59 @@ bool compare_pos(pos_t a, pos_t b) {
return a.x == b.x && a.y == b.y;
}
pos_t pos_multiply_scalar(pos_t a, int b) {
return (pos_t){a.x*b, a.y*b};
}
/**
* check the wanted pos_t against all valid move options
* of the current piece
*/
bool is_move_legal(move_t move) {
valid_move_t valid_moves[PIECE_COUNT] = DEFAULT_VALID_MOVES;
for (int i = 0; i < PIECE_COUNT; i++) {
for (int j = 0;
j < valid_moves[i].piece_move_count &&
move.piece == valid_moves[i].piece;
j++
) {
pos_t new_pos = {move.from.x+move.to.x, move.from.y+move.to.y};
if (compare_pos(new_pos, valid_moves[i].options[j]) == true) {
return true;
switch (move.piece) {
case NONE:
case PAWN:
case KNIGHT:
case KING:
for (int i = 0; i < PIECE_COUNT; i++) {
for (int j = 0;
j < valid_moves[i].piece_move_count &&
move.piece == valid_moves[i].piece;
j++
) {
pos_t new_pos = {move.from.x+move.to.x, move.from.y+move.to.y};
if (compare_pos(new_pos, valid_moves[i].options[j]) == true) {
return true;
}
}
}
}
break;
case ROOK:
case BISHOP:
case QUEEN:
for (int i = 0; i < PIECE_COUNT; i++) {
for (int j = 0;
j < valid_moves[i].piece_move_count &&
move.piece == valid_moves[i].piece;
j++
) {
/** NOTE: BOARD_HORIZONTAL assuming HORIZONTAL & VERTICAL are the same */
for (int k = 0; k < BOARD_HORIZONTAL; k++) {
pos_t new_pos = {
move.from.x+move.to.x,
move.from.y+move.to.y
};
if (compare_pos(
new_pos,
pos_multiply_scalar(valid_moves[i].options[j], k)
) == true) {
return true;
}
}
}
}
break;
}
return false;