-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPathValidator.cpp
More file actions
32 lines (25 loc) · 845 Bytes
/
Copy pathPathValidator.cpp
File metadata and controls
32 lines (25 loc) · 845 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//
// Created by sahoo on 25-06-2026.
//
#include "PathValidator.h"
#include "MovementPatterns.h"
#include "Utils.h"
// returns true if any piece blocks the path between startPos and endPos
bool PathValidator::isPathBlocked(ChessBoard &board, int startPos, int endPos) {
// determine movement direction
Direction moveDirection = MovementPatterns::getMoveDirection(startPos, endPos);
// get all squares along the movement ray
const std::vector<int>& ray = AttackTables::rayTable.getRay(startPos, moveDirection);
// traverse the ray
for (int square : ray) {
// reached destination
if (square == endPos) {
break;
}
// another piece blocks the path
if (Utils::checkBit(board.getAllOccupancy(), square)) {
return true;
}
}
return false;
}