|
|
|
@ -23,10 +23,10 @@ export class SudokuService {
|
|
|
|
|
this.hard = jsonResponse["hard"];
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
this.correction = [[3,8,7,1,2,6,5,4,9],[2,1,6,9,4,5,8,7,3],[5,9,4,3,8,7,6,2,1],[4,2,8,5,9,1,7,3,6],[7,5,1,2,6,3,9,8,4],[6,3,9,8,7,4,1,5,2],[1,7,5,6,3,2,4,9,8],[9,4,3,7,1,8,2,6,5],[8,6,2,4,5,9,3,1,7]];
|
|
|
|
|
this.easy = [[3,8,0,1,2,0,5,0,9],[2,1,6,9,0,0,8,0,0],[5,9,4,3,8,0,0,0,1],[4,2,8,5,0,0,7,3,6],[7,5,1,2,6,3,9,0,4],[0,3,0,0,0,0,1,5,2],[1,7,5,6,3,0,4,9,0],[9,4,3,0,1,8,0,0,5],[8,6,0,4,5,0,3,1,7]];
|
|
|
|
|
this.medium = [[3,0,0,0,0,0,0,4,0],[0,1,6,0,4,5,0,0,3],[0,9,0,3,8,0,0,2,0],[4,2,0,5,0,0,0,3,6],[7,5,0,2,6,0,0,8,4],[0,0,0,0,0,0,0,5,0],[1,0,5,6,3,0,0,9,8],[0,0,0,7,1,8,0,6,5],[0,0,2,4,0,0,0,0,0]];
|
|
|
|
|
this.hard = [[0,0,0,1,0,0,0,0,0],[0,1,6,9,0,0,8,0,0],[0,0,0,0,8,0,6,0,0],[0,0,0,5,0,0,0,0,0],[0,0,0,0,6,3,0,0,0],[0,0,0,0,0,0,0,0,0],[0,7,5,0,0,0,0,0,0],[9,0,3,0,0,0,0,0,5],[8,0,0,0,5,0,3,1,0]];
|
|
|
|
|
this.correction = this.transformFormat([[3,8,7,1,2,6,5,4,9],[2,1,6,9,4,5,8,7,3],[5,9,4,3,8,7,6,2,1],[4,2,8,5,9,1,7,3,6],[7,5,1,2,6,3,9,8,4],[6,3,9,8,7,4,1,5,2],[1,7,5,6,3,2,4,9,8],[9,4,3,7,1,8,2,6,5],[8,6,2,4,5,9,3,1,7]]);
|
|
|
|
|
this.easy = this.transformFormat([[3,8,0,1,2,0,5,0,9],[2,1,6,9,0,0,8,0,0],[5,9,4,3,8,0,0,0,1],[4,2,8,5,0,0,7,3,6],[7,5,1,2,6,3,9,0,4],[0,3,0,0,0,0,1,5,2],[1,7,5,6,3,0,4,9,0],[9,4,3,0,1,8,0,0,5],[8,6,0,4,5,0,3,1,7]]);
|
|
|
|
|
this.medium = this.transformFormat([[3,0,0,0,0,0,0,4,0],[0,1,6,0,4,5,0,0,3],[0,9,0,3,8,0,0,2,0],[4,2,0,5,0,0,0,3,6],[7,5,0,2,6,0,0,8,4],[0,0,0,0,0,0,0,5,0],[1,0,5,6,3,0,0,9,8],[0,0,0,7,1,8,0,6,5],[0,0,2,4,0,0,0,0,0]]);
|
|
|
|
|
this.hard = this.transformFormat([[0,0,0,1,0,0,0,0,0],[0,1,6,9,0,0,8,0,0],[0,0,0,0,8,0,6,0,0],[0,0,0,5,0,0,0,0,0],[0,0,0,0,6,3,0,0,0],[0,0,0,0,0,0,0,0,0],[0,7,5,0,0,0,0,0,0],[9,0,3,0,0,0,0,0,5],[8,0,0,0,5,0,3,1,0]]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public getCorrection(): number[][]{
|
|
|
|
@ -47,16 +47,15 @@ export class SudokuService {
|
|
|
|
|
|
|
|
|
|
public validationGrille(userGrille: number[][]): number[][] {
|
|
|
|
|
let validation: number[][] = [];
|
|
|
|
|
for (let x:number = 0; x<userGrille.length; x++) {
|
|
|
|
|
for (let y:number = 0; y<userGrille.length; y++) {
|
|
|
|
|
validation.push([]);
|
|
|
|
|
for (let y:number = 0; y<userGrille[x].length; y++) {
|
|
|
|
|
if (userGrille[x][y] == 0) {
|
|
|
|
|
validation[x].push(0);
|
|
|
|
|
}
|
|
|
|
|
if (userGrille[x][y] == this.correction[x][y]) {
|
|
|
|
|
validation[x].push(1);
|
|
|
|
|
for (let x:number = 0; x<userGrille[y].length; x++) {
|
|
|
|
|
if (userGrille[y][x] == 0) {
|
|
|
|
|
validation[y].push(0);
|
|
|
|
|
} else if (userGrille[y][x] == this.correction[y][x]) {
|
|
|
|
|
validation[y].push(1);
|
|
|
|
|
} else {
|
|
|
|
|
validation[x].push(-1);
|
|
|
|
|
validation[y].push(-1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -66,10 +65,34 @@ export class SudokuService {
|
|
|
|
|
public isCorrect(userGrille: number[][]): boolean {
|
|
|
|
|
for (let x:number = 0; x<userGrille.length; x++) {
|
|
|
|
|
for (let y:number = 0; y<userGrille[x].length; y++) {
|
|
|
|
|
if (userGrille[x][y] == 0 || userGrille[x][y] != this.correction[x][y]) return true;
|
|
|
|
|
if (userGrille[x][y] == 0 || userGrille[x][y] != this.correction[x][y]) return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private transformFormat(grill: number[][]): number[][] { // convertie le format de la grille pour faciliter l'affichage après.
|
|
|
|
|
let newgrid: number[][] = [];
|
|
|
|
|
for (let y=0; y<9; y++) {
|
|
|
|
|
newgrid.push([]);
|
|
|
|
|
for (let x=0; x<9; x++) {
|
|
|
|
|
newgrid[y].push(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for (let y=0; y<grill.length; y++) {
|
|
|
|
|
for (let x=0; x<grill[y].length; x++) {
|
|
|
|
|
let a = this.getXYfromOtherXY(x,y);
|
|
|
|
|
newgrid[a[1]][a[0]] =grill[y][x];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return newgrid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private getXYfromOtherXY(x:number, y:number):number[] {
|
|
|
|
|
let a = Math.floor(x/3);
|
|
|
|
|
let b = Math.floor(y/3);
|
|
|
|
|
let newy:number = b*3+a;
|
|
|
|
|
let newx:number = (y%3)*3+(x%3);
|
|
|
|
|
return [newx,newy];
|
|
|
|
|
}
|
|
|
|
|
}
|