-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterview_template.js
More file actions
196 lines (177 loc) · 5.51 KB
/
interview_template.js
File metadata and controls
196 lines (177 loc) · 5.51 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/**
* Queens Go Game - Interview Template
*
* This file provides the structure for implementing the Queens Go game.
* Focus on clear organization and understandability rather than efficiency.
*
* Game Rules:
* - The game is played on an 8x8 board
* - Only two pieces exist: a Red queen and a Blue queen
* - Queens move as in chess (horizontally, vertically, and diagonally)
* - Any square that a queen starts on, passes through, or lands on turns to that queen's color
* - Once a 2x2 square of the same color is formed, those squares are "locked" and can't change color
* - If a queen traverses a square of the opponent's color that isn't locked, it changes to the moving queen's color
* - Queens can still move through locked squares even if they can't change their color
*/
import { BOARD_SIZE, COLORS } from './src/utils/constants.js';
// TODO: Implement the Board component
class Board {
/**
* Create a new game board
*/
constructor() {
// TODO: Initialize the board cells
}
/**
* Creates an empty game board
* @returns {Array} The initialized game board
*/
createBoard() {
// TODO: Create and return an 8x8 board where each cell tracks:
// - color (NONE, RED, BLUE)
// - locked status (boolean)
}
/**
* Color a square on the board
* @param {number} row - The row of the square
* @param {number} col - The column of the square
* @param {string} color - The color to apply
*/
colorSquare(row, col, color) {
// TODO: Implement coloring logic
// 1. Check if the square is locked
// 2. If not locked, change the color
}
/**
* Check for and lock 2x2 squares of the same color
*/
checkAndLockSquares() {
// TODO: Implement locking logic
// 1. Check each possible 2x2 square
// 2. If all four squares have the same color (not NONE), lock them
}
/**
* Print the board with the given queen positions
* @param {Object} redQueenPosition - The position of the red queen {row, col}
* @param {Object} blueQueenPosition - The position of the blue queen {row, col}
*/
print(redQueenPosition, blueQueenPosition) {
// TODO: Implement board printing logic
// Consider using the COLORS.ICONS for better visualization
}
}
// TODO: Implement the Queen component
class Queen {
/**
* Create a new queen
* @param {string} color - The color of the queen
* @param {number} row - Initial row position
* @param {number} col - Initial column position
*/
constructor(color, row, col) {
// TODO: Initialize the queen with color and position
}
/**
* Update the queen's position
* @param {number} row - New row position
* @param {number} col - New column position
*/
updatePosition(row, col) {
// TODO: Update the queen's position
}
/**
* Validates if a queen move is legal according to chess rules
* @param {number} endRow - Ending row
* @param {number} endCol - Ending column
* @returns {boolean} Whether the move is valid
*/
isValidMove(endRow, endCol) {
// TODO: Implement move validation
// 1. Check if within board boundaries
// 2. Check if the move follows queen movement rules (horizontal, vertical, diagonal)
}
/**
* Calculate the path a queen takes when moving
* @param {number} endRow - Ending row
* @param {number} endCol - Ending column
* @returns {Array} Array of positions {row, col} in the path
*/
calculatePath(endRow, endCol) {
// TODO: Implement path calculation
// 1. Determine the direction of movement
// 2. Generate all points along the path
}
}
// TODO: Implement the Game component that brings everything together
class Game {
/**
* Create a new game
*/
constructor() {
// TODO:
// 1. Create a new board
// 2. Create red and blue queens at random positions
// 3. Color the initial squares
}
/**
* Creates a queen at a random position
* @param {string} color - The color of the queen
* @returns {Queen} The created queen
*/
createQueenRandomly(color) {
// TODO:
// 1. Generate random position
// 2. Make sure queens don't overlap
// 3. Return a new Queen instance
}
/**
* Move a queen to a new position
* @param {string} color - The color of the queen to move
* @param {number} endRow - Target row
* @param {number} endCol - Target column
* @returns {boolean} Whether the move was successful
*/
moveQueen(color, endRow, endCol) {
// TODO: Implement queen movement
// 1. Get the queen object based on color
// 2. Validate the move
// 3. Calculate the path
// 4. Color all squares in the path
// 5. Update queen position
// 6. Check and lock 2x2 squares
// 7. Return success/failure
}
/**
* Validate if a move from a given position is valid for a queen
* @param {number} startRow - Starting row
* @param {number} startCol - Starting column
* @param {number} endRow - Ending row
* @param {number} endCol - Ending column
* @returns {boolean} Whether the move is valid
*/
isValidQueenMove(startRow, startCol, endRow, endCol) {
// TODO: Create a temporary queen at the start position to check move validity
}
/**
* Print the current board state
*/
printBoard() {
// TODO: Use the board's print method to display the current state
}
}
// Example usage
function demonstrateGame() {
const game = new Game();
console.log("Initial board:");
game.printBoard();
// TODO: Add example moves here
}
// Uncomment to run a demonstration
// demonstrateGame();
export {
Game,
Queen,
Board,
COLORS,
BOARD_SIZE
};