-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontroller.js
More file actions
115 lines (102 loc) · 3.45 KB
/
controller.js
File metadata and controls
115 lines (102 loc) · 3.45 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
//DOM INTERACTIONA
var explainCounter = 0;
var explainLength = 0;
function clearButtons() {
resetButtons();
$("#pros-analysis").empty();
$("#cons-analysis").empty();
$("#neutral-analysis").empty();
}
$("#analysis-button").click(function () {
var fen = game.fen().split(" ").slice(0, 3).join(" ");
if (promotionOccuring) {
$("#warning-paragraph").text("Analysis cannot be made during promotion");
} else if (openingMap[fen]) {
$(".explanation-paragraph")
.first()
.text("Book Opening: " + openingMap[fen].name);
} else if (moveList === "") {
$(".explanation-paragraph").empty();
$(".explanation-paragraph")
.first()
.text("Play a move first to have Chess Explainer analyze it.");
} else {
var analysisObject = analyzePosition();
console.log(analysisObject);
$(".explanation-paragraph").empty();
$("#pros-analysis").empty();
for (let i = 0; i < analysisObject.pros.length; i++) {
$("#pros-analysis").append(
"<li>" + analysisObject.pros[i].statement + "</li>"
);
}
$("#cons-analysis").empty();
for (let i = 0; i < analysisObject.cons.length; i++) {
$("#cons-analysis").append(
"<li>" + analysisObject.cons[i].statement + "</li>"
);
}
$("#neutral-analysis").empty();
for (let i = 0; i < analysisObject.neutral.length; i++) {
$("#neutral-analysis").append(
"<li>" + analysisObject.neutral[i].statement + "</li>"
);
}
explainLength =
analysisObject.pros.length +
analysisObject.cons.length +
analysisObject.neutral.length;
if (explainLength > 0) {
analysisOccuring = true;
$("#next-button").show();
$("#analysis-button").hide();
}
}
});
$("#next-button").click(function () {
$("#pros-analysis li").css("background-color", "");
$("#cons-analysis li").css("background-color", "");
$("#neutral-analysis li").css("background-color", "");
setDefaultSquareLighting();
var analysisObject = analyzePosition();
if (explainCounter < explainLength) {
var prosLength = $("#pros-analysis li").length;
var consLength = $("#cons-analysis li").length;
var neutralLength = $("#neutral-analysis li").length;
var index = explainCounter;
var turnToReplay = 0;
if (index < prosLength) {
$("#pros-analysis li").eq(index).css("background-color", "#69140e");
highlightSquares(analysisObject.pros[index].squares);
turnToReplay = analysisObject.pros[index].turn === "w" ? 2 : 1;
actionReplay(turnToReplay);
} else {
index -= prosLength;
if (index < consLength) {
$("#cons-analysis li").eq(index).css("background-color", "#69140e");
highlightSquares(analysisObject.cons[index].squares);
turnToReplay = analysisObject.cons[index].turn === "w" ? 2 : 1;
actionReplay(turnToReplay);
} else {
index -= consLength;
if (index < neutralLength) {
$("#neutral-analysis li")
.eq(index)
.css("background-color", "#69140e");
highlightSquares(analysisObject.neutral[index].squares);
turnToReplay = analysisObject.neutral[index].turn === "w" ? 2 : 1;
actionReplay(turnToReplay);
}
}
}
explainCounter++;
} else {
resetButtons();
}
});
$("#reset-button").click(function () {
applyFenString("rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1");
moveList = "";
stock.postMessage("ucinewgame");
clearButtons();
});