/*
* This program creates an 8x8 integer board.
* For each row:
* - All values are set to zero
* - One random column is chosen
* - A random value (1..100) is placed in that column
*
* It mirrors the structure of the C++ version:
* initializeBoard()
* printBoard()
* main logic
*/
const BOARD_SIZE: number = 8;
/*
* initializeBoard:
* - Sets all values to zero
* - For each row:
* * randomly selects one column (0..7)
* * places a random integer (1..100) in that column
*/
function initializeBoard(board: number[][]): void {
for (let row: number = 0; row < BOARD_SIZE; row++) {
// Set entire row to zero
for (let col: number = 0; col < BOARD_SIZE; col++) {
board[row][col] = 0;
}
// Choose a random column index
const randomCol: number = Math.floor(Math.random() * BOARD_SIZE);
// Place a random non-zero value (1..100)
const randomValue: number = Math.floor(Math.random() * 100) + 1;
board[row][randomCol] = randomValue;
}
}
/*
* printBoard:
* - Prints the 8x8 board in a readable grid format
*/
function printBoard(board: number[][]): void {
for (let row: number = 0; row < BOARD_SIZE; row++) {
console.log(board[row].join(" "));
}
}
// ------------------------
// Main program
// ------------------------
const board: number[][] = Array.from(
{ length: BOARD_SIZE },
(): number[] => Array.from({ length: BOARD_SIZE }, (): number => 0)
);
initializeBoard(board);
printBoard(board);
/*
run:
0 0 33 0 0 0 0 0
0 0 0 0 35 0 0 0
0 0 0 0 0 0 6 0
0 96 0 0 0 0 0 0
0 0 0 0 0 0 0 8
0 0 0 0 49 0 0 0
62 0 0 0 0 0 0 0
0 0 0 0 0 0 80 0
*/