export class QueenAttack {
constructor({ white, black } = {}) {
this.white = white || [0, 3];
this.black = black || [7, 3];
if (this.white[0] === this.black[0] && this.white[1] === this.black[1]) {
throw new Error('Queens cannot share the same space');
}
[...this.white, ...this.black].forEach(coord => {
if (coord < 0 || coord > 7) {
throw new Error('Queen must be placed on the board');
}
});
}
toString() {
let board = Array.from({ length: 8 }, () => Array(8).fill('_'));
board[this.white[0]][this.white[1]] = 'W';
board[this.black[0]][this.black[1]] = 'B';
return board.map(row => row.join(' ')).join('\n');
}
get canAttack() {
const [wr, wc] = this.white;
const [br, bc] = this.black;
return wr === br || wc === bc || Math.abs(wr - br) === Math.abs(wc - bc);
}
}