connected method
Whether a
and b
are connected by a move in direction
.
Implementation
bool connected(int a, int b, Direction direction) {
int fileDiff = file(b) - file(a);
if (direction.h == 0 && fileDiff != 0) return false;
int rankDiff = rank(b) - rank(a);
if (direction.v == 0 && rankDiff != 0) return false;
if (direction.h != 0 && fileDiff % direction.h != 0) return false;
if (direction.v != 0 && rankDiff % direction.v != 0) return false;
return true;
}