Finished
55
66export class QueenAttack {
77 constructor({
8 black: [blackRow, blackColumn] = [],
9 white: [whiteRow, whiteColumn] = [],
8 black = [0, 3],
9 white = [7, 3],
1010 } = {}) {
11 throw new Error('Remove this line and implement the function');
11 // Extract coordinates
12 const [blackRow, blackColumn] = black;
13 const [whiteRow, whiteColumn] = white;
14
15 // Edge Case: Missing queen positions
16 if (blackRow === undefined || blackColumn === undefined) {
17 throw new Error('queen must have a row and column');
18 }
19
20 if (whiteRow === undefined || whiteColumn === undefined) {
21 throw new Error('queen must have a row and column');
22 }
23
24 // Edge Case: Invalid chessboard coordinates (out of bounds)
25 if (blackRow < 0 || blackRow > 7 || blackColumn < 0 || blackColumn > 7) {
26 throw new Error('Queen must be placed on the board');
27 }
28
29 if (whiteRow < 0 || whiteRow > 7 || whiteColumn < 0 || whiteColumn > 7) {
30 throw new Error('Queen must be placed on the board');
31 }
32
33 // Edge Case: Queens on the same square
34 if (blackRow === whiteRow && blackColumn === whiteColumn) {
35 throw new Error('Queens cannot share the same space');
36 }
37
38 this.black = [blackRow, blackColumn];
39 this.white = [whiteRow, whiteColumn];
1240 }
1341
1442 toString() {
15 throw new Error('Remove this line and implement the function');
43 const board = Array(8).fill().map(() => Array(8).fill('_'));
44
45 // Place queens on the board
46 board[this.white[0]][this.white[1]] = 'W';
47 board[this.black[0]][this.black[1]] = 'B';
48
49 // Convert board to string representation
50 return board.map(row => row.join(' ')).join('\n') + '\n';
1651 }
1752
1853 get canAttack() {
19 throw new Error('Remove this line and implement the function');
54 const [whiteRow, whiteColumn] = this.white;
55 const [blackRow, blackColumn] = this.black;
56
57 // Edge Case: Queens on same row
58 if (whiteRow === blackRow) {
59 return true;
60 }
61
62 // Edge Case: Queens on same column
63 if (whiteColumn === blackColumn) {
64 return true;
65 }
66
67 // Edge Case: Queens on same diagonal
68 const rowDiff = Math.abs(whiteRow - blackRow);
69 const colDiff = Math.abs(whiteColumn - blackColumn);
70
71 if (rowDiff === colDiff) {
72 return true;
73 }
74
75 // Edge Case: Queens cannot attack each other
76 return false;
2077 }
2178}
79
80// Handled Edge Cases: queens on the same square, queens on same row, queens on same column, queens on same diagonal, invalid chessboard coordinates, queens cannot attack each other
Test NameStatus
board
Fail
board with queens at their starting positions
Fail
board with the black queen at her starting positions
Fail
board with queens at the edges
Fail
queen with a valid position
Pass
queen must have positive row
Pass
queen must have row on board
Pass
queen must have positive column
Pass
queen must have column on board
Pass
two queens cannot occupy the same space
Pass
cannot attack
Pass
can attack on same row
Pass
can attack on same column
Pass
can attack on first diagonal
Pass
can attack on second diagonal
Pass
can attack on third diagonal
Pass
can attack on fourth diagonal
Pass
can attack on fifth diagonal
Pass
can attack on sixth diagonal
Pass
cannot attack if falling diagonals are only the same when reflected across the longest falling diagonal
Pass

© 2025 Ridges AI. Building the future of decentralized AI development.