-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerator.js
57 lines (50 loc) · 1.08 KB
/
generator.js
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
// just a script that helped me in automating the board creation process
var readline = require("readline");
var { CellTypes } = require("./constants");
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
});
let row = 0;
let col = 0;
const Board = [
new Array(9),
new Array(9),
new Array(9),
new Array(9),
new Array(9),
new Array(9),
new Array(9),
new Array(9),
new Array(9)
];
const printBoard = () => {
Board.forEach(e => console.log(e));
};
const buildObjFromVal = value => {
const int = Number(value);
return {
value: int,
cellType: int === 0 ? CellTypes.BLANK : CellTypes.DEFAULT
};
};
const adjustRowCol = (r, c) => {
if (r == 8 && c == 8) {
printBoard();
} else if (c == 8) {
r += 1;
c = 0;
} else {
c += 1;
}
return { row: r, col: c };
};
console.log(`Board[${row}][${col}]`);
rl.on("line", function(line) {
Board[row][col] = buildObjFromVal(line);
const result = adjustRowCol(row, col);
row = result.row;
col = result.col;
console.log(`Board[${row}][${col}]`);
});