-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdiagonal-win.js
40 lines (38 loc) · 1.06 KB
/
diagonal-win.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
export class DiagonalWinInspector {
constructor(columns) {
this.column = columns;
}
//hi
/*
[*][*][*][*]
[*][*][*][*]
[*][*][*][*]
[*][*][*][*]
[*][*][*][*]
*/
inspect() {
for (let i = 5; i >= 3; i--) {
if (this.column[0].getTokenAt(i) !== null) {
if (
this.column[0].getTokenAt(i) === this.column[1].getTokenAt(i - 1) &&
this.column[0].getTokenAt(i) === this.column[2].getTokenAt(i - 2) &&
this.column[0].getTokenAt(i) === this.column[3].getTokenAt(i - 3)
) {
return this.column[0].getTokenAt(i);
}
}
}
for (let i = 2; i >= 0; i--) {
if (this.column[0].getTokenAt(i) !== null) {
if (
this.column[0].getTokenAt(i) === this.column[1].getTokenAt(i + 1) &&
this.column[0].getTokenAt(i) === this.column[2].getTokenAt(i + 2) &&
this.column[0].getTokenAt(i) === this.column[3].getTokenAt(i + 3)
) {
return this.column[0].getTokenAt(i);
}
}
}
return 0;
}
}