-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkResult.js
48 lines (40 loc) · 1.61 KB
/
checkResult.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
function checkTheResult(fields) {
for (let i = 0; i < fields.length; i++) {
const row = fields[i];
const valueOfTile1 = row[0].getValue();
const valueOfTile2 = row[1].getValue();
const valueOfTile3 = row[2].getValue();
if (valueOfTile1 === valueOfTile2 && valueOfTile2 === valueOfTile3 && valueOfTile1 === valueOfTile3 && valueOfTile1 !== null) {
return valueOfTile1;
}
}
for (let i = 0; i < fields.length; i++) {
const valueOfTile1 = fields[0][i].getValue();
const valueOfTile2 = fields[1][i].getValue();
const valueOfTile3 = fields[2][i].getValue();
if (valueOfTile1 === valueOfTile2 && valueOfTile2 === valueOfTile3 && valueOfTile1 === valueOfTile3 && valueOfTile1 !== null) {
return valueOfTile1;
}
}
const valueOfCenterTile = fields[1][1].getValue();
const valueOfTile1 = fields[0][0].getValue();
const valueOfTile2 = fields[2][2].getValue();
const valueOfTile3 = fields[0][2].getValue();
const valueOfTile4 = fields[2][0].getValue();
if (
(valueOfTile1 === valueOfCenterTile && valueOfTile1 === valueOfTile2 && valueOfTile2 !== null) ||
(valueOfTile3 === valueOfCenterTile && valueOfTile3 === valueOfTile4 && valueOfTile4 !== null)
) {
return valueOfCenterTile;
}
for (let i = 0; i < fields.length; i++) {
const row = fields[i];
for (let j = 0; j < row.length; j++) {
const tile = row[j];
if (tile.getValue() === null) {
return null;
}
}
}
return WEAPON.DRAW;
}