Finished
1111 black: [blackRow, blackColumn] = [],
1212 white: [whiteRow, whiteColumn] = [],
1313 } = {}) {
14 throw new Error('Remove this line and implement the function');
14 // Edge Case: Missing positions - default to [0,0] for both queens
15 if (blackRow === undefined || blackColumn === undefined) {
16 blackRow = 0;
17 blackColumn = 0;
18 }
19
20 if (whiteRow === undefined || whiteColumn === undefined) {
21 whiteRow = 0;
22 whiteColumn = 0;
23 }
24
25 // Edge Case: Negative coordinates
26 if (blackRow < 0 || blackColumn < 0 || whiteRow < 0 || whiteColumn < 0) {
27 throw new Error("Queen must be placed on the board");
28 }
29
30 // Edge Case: Coordinates outside board boundaries
31 if (blackRow > 7 || blackColumn > 7 || whiteRow > 7 || whiteColumn > 7) {
32 throw new Error("Queen must be placed on the board");
33 }
34
35 // Edge Case: Queens on same square
36 if (blackRow === whiteRow && blackColumn === whiteColumn) {
37 throw new Error("Queens cannot share the same space");
38 }
39
40 this.black = [blackRow, blackColumn];
41 this.white = [whiteRow, whiteColumn];
1542 }
1643
1744 /**
1845 * @returns {string}
1946 */
2047 toString() {
21 throw new Error('Remove this line and implement the function');
48 const board = Array(8).fill().map(() => Array(8).fill('_'));
49
50 board[this.white[0]][this.white[1]] = 'W';
51 board[this.black[0]][this.black[1]] = 'B';
52
53 return board.map(row => row.join(' ')).join('\n');
2254 }
2355
2456 /**
2557 * @returns {boolean}
2658 */
2759 get canAttack() {
28 throw new Error('Remove this line and implement the function');
60 const [whiteRow, whiteColumn] = this.white;
61 const [blackRow, blackColumn] = this.black;
62
63 // Edge Case: Queens on same row
64 if (whiteRow === blackRow) {
65 return true;
66 }
67
68 // Edge Case: Queens on same column
69 if (whiteColumn === blackColumn) {
70 return true;
71 }
72
73 // Edge Case: Queens on same diagonal
74 const rowDiff = Math.abs(whiteRow - blackRow);
75 const colDiff = Math.abs(whiteColumn - blackColumn);
76
77 if (rowDiff === colDiff) {
78 return true;
79 }
80
81 return false;
2982 }
3083}
84
85// Handled Edge Cases: queens on same square, queens on same row, queens on same column, queens on same diagonal, negative coordinates, coordinates outside board boundaries, missing positions
Test NameStatus
board with queens at their starting positions
Fail
board with the black queen at her starting positions
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
board
Pass
board with queens at the edges
Pass

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