-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
takuzu.js
32 lines (26 loc) · 842 Bytes
/
takuzu.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
class Takuzu {
constructor(size) {
this.grid = Grid.init(size);
this.size = size;
this.grid.generate();
this.clearCells();
}
clearCells(attempts = 5) {
let i;
while(attempts > 0) {
while(this.grid.cells[i = Math.floor(random(this.size ** 2))].value === null);
let value = this.grid.cells[i].value;
this.grid.cells[i].value = null;
this.grid.cells[i].stored = false;
let testGrid = this.grid.clone();
testGrid.solutions = 0;
testGrid.solve();
console.log(testGrid.solutions);
if(testGrid.solutions !== 1) {
this.grid.cells[i].value = value;
this.grid.cells[i].stored = true;
attempts--;
}
}
}
}