Skip to content

Commit 9399fc6

Browse files
committed
ceval data refactoring
ceval.pvs[].pv -> ceval.pvs[].moves - now an Array, not a String ceval.pvs[].best -> ceval.pvs[].moves[0] Also makes the assumption that ceval.pvs[].moves[0] exists.
1 parent 5e5c571 commit 9399fc6

File tree

10 files changed

+34
-41
lines changed

10 files changed

+34
-41
lines changed

ui/analyse/src/autoShape.js

+8-9
Original file line numberDiff line numberDiff line change
@@ -59,36 +59,35 @@ module.exports = {
5959
}
6060
if (hovering && hovering.fen === n.fen) shapes = shapes.concat(makeAutoShapesFromUci(color, hovering.uci, 'paleBlue'));
6161
if (ctrl.vm.showAutoShapes() && ctrl.vm.showComputer()) {
62-
if (n.eval && n.eval.best)
63-
shapes = shapes.concat(makeAutoShapesFromUci(rcolor, n.eval.best, 'paleGreen'));
62+
if (n.eval) shapes = shapes.concat(makeAutoShapesFromUci(rcolor, n.eval.moves[0], 'paleGreen'));
6463
if (!hovering) {
6564
var nextBest = ctrl.nextNodeBest();
66-
if (!nextBest && instance.enabled() && n.ceval && n.ceval.best) nextBest = n.ceval.best;
65+
if (!nextBest && instance.enabled() && n.ceval) nextBest = n.ceval.moves[0];
6766
if (nextBest) shapes = shapes.concat(makeAutoShapesFromUci(color, nextBest, 'paleBlue'));
6867
if (instance.enabled() && n.ceval && n.ceval.pvs && n.ceval.pvs[1] && !(ctrl.vm.threatMode && n.threat && n.threat.pvs && n.threat.pvs[2])) {
6968
n.ceval.pvs.forEach(function(pv) {
70-
if (pv.best === nextBest) return;
69+
if (pv.moves[0] === nextBest) return;
7170
var shift = winningChances.povDiff(color, n.ceval.pvs[0], pv);
7271
if (shift > 0.2 || isNaN(shift) || shift < 0) return;
73-
shapes = shapes.concat(makeAutoShapesFromUci(color, pv.best, 'paleGrey', {
72+
shapes = shapes.concat(makeAutoShapesFromUci(color, pv.moves[0], 'paleGrey', {
7473
lineWidth: Math.round(12 - shift * 50) // 12 to 2
7574
}));
7675
});
7776
}
7877
}
7978
}
80-
if (instance.enabled() && ctrl.vm.threatMode && n.threat && n.threat.best) {
79+
if (instance.enabled() && ctrl.vm.threatMode && n.threat && n.threat.moves[0]) {
8180
if (n.threat.pvs[1]) {
82-
shapes = shapes.concat(makeAutoShapesFromUci(rcolor, n.threat.best, 'paleRed'));
81+
shapes = shapes.concat(makeAutoShapesFromUci(rcolor, n.threat.moves[0], 'paleRed'));
8382
n.threat.pvs.slice(1).forEach(function(pv) {
8483
var shift = winningChances.povDiff(rcolor, pv, n.threat.pvs[0]);
8584
if (shift > 0.2 || isNaN(shift) || shift < 0) return;
86-
shapes = shapes.concat(makeAutoShapesFromUci(rcolor, pv.best, 'paleRed', {
85+
shapes = shapes.concat(makeAutoShapesFromUci(rcolor, pv.moves[0], 'paleRed', {
8786
lineWidth: Math.round(11 - shift * 45) // 11 to 2
8887
}));
8988
});
9089
} else
91-
shapes = shapes.concat(makeAutoShapesFromUci(rcolor, n.threat.best, 'red'));
90+
shapes = shapes.concat(makeAutoShapesFromUci(rcolor, n.threat.moves[0], 'red'));
9291
}
9392
return shapes;
9493
}

ui/analyse/src/ctrl.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ module.exports = function(opts) {
432432

433433
this.nextNodeBest = function() {
434434
return tree.ops.withMainlineChild(this.vm.node, function(n) {
435-
return n.eval ? n.eval.best : null;
435+
return n.eval ? n.eval.moves[0] : null;
436436
});
437437
}.bind(this);
438438

@@ -643,7 +643,7 @@ module.exports = function(opts) {
643643
}.bind(this);
644644

645645
this.playBestMove = function() {
646-
var uci = this.nextNodeBest() || (this.vm.node.ceval && this.vm.node.ceval.best);
646+
var uci = this.nextNodeBest() || this.vm.node.ceval;
647647
if (uci) this.playUci(uci);
648648
}.bind(this);
649649

ui/analyse/src/evalCache.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function toPutData(eval) {
2121
return {
2222
cp: pv.cp,
2323
mate: pv.mate,
24-
moves: pv.pv.split(' ', evalPutMaxMoves).join(' ')
24+
moves: pv.moves.slice(0, evalPutMaxMoves).join(' ')
2525
};
2626
})
2727
};
@@ -35,8 +35,7 @@ function toCeval(e) {
3535
depth: e.depth,
3636
pvs: e.pvs.map(function(from) {
3737
var to = {
38-
pv: from.moves,
39-
best: from.moves.split(' ', 1)[0]
38+
pv: from.moves.split(' ')
4039
};
4140
if (defined(from.cp)) to.cp = from.cp;
4241
else to.mate = from.mate;
@@ -46,7 +45,6 @@ function toCeval(e) {
4645
};
4746
if (defined(res.pvs[0].cp)) res.cp = res.pvs[0].cp;
4847
else res.mate = res.pvs[0].mate;
49-
res.best = res.pvs[0].best;
5048
res.cloud = true;
5149
return res;
5250
}

ui/analyse/src/practice/practiceCtrl.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ module.exports = function(root, playableDepth) {
4747
} : node.ceval;
4848
var shift = -winningChances.povDiff(root.bottomColor(), nodeEval, prev.ceval);
4949

50-
best = prev.ceval.best;
50+
best = prev.ceval.moves[0];
5151
if (best === node.uci || best === altCastles[node.uci]) best = null;
5252

5353
if (!best) verdict = 'good';
@@ -64,7 +64,7 @@ module.exports = function(root, playableDepth) {
6464
verdict: verdict,
6565
best: best ? {
6666
uci: best,
67-
san: pv2san(root.data.game.variant.key, prev.fen, false, best)
67+
san: pv2san(root.data.game.variant.key, prev.fen, false, [best])
6868
} : null
6969
};
7070
}
@@ -84,7 +84,7 @@ module.exports = function(root, playableDepth) {
8484
if (isMyTurn()) {
8585
var h = hinting();
8686
if (h) {
87-
h.uci = node.ceval.best;
87+
h.uci = node.ceval.moves[0];
8888
root.setAutoShapes();
8989
}
9090
} else {
@@ -95,7 +95,7 @@ module.exports = function(root, playableDepth) {
9595
comment(makeComment(parentNode, node, root.vm.path));
9696
}
9797
if (!played() && playable(node)) {
98-
root.playUci(node.ceval.best);
98+
root.playUci(node.ceval.moves[0]);
9999
played(true);
100100
}
101101
}
@@ -169,7 +169,7 @@ module.exports = function(root, playableDepth) {
169169
root.setAutoShapes();
170170
},
171171
hint: function() {
172-
var best = root.vm.node.ceval ? root.vm.node.ceval.best : null;
172+
var best = root.vm.node.ceval ? root.vm.node.ceval.moves[0] : null;
173173
var prev = hinting();
174174
if (!best || (prev && prev.mode === 'move')) hinting(null);
175175
else hinting({

ui/analyse/test/pv2san.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ var initialFen = require('chess').initialFen;
33

44
exports.testCrazyhouse = function(test) {
55
var fen = 'r4b1N~/1ppk1P2/p1b5/6p1/8/1PBPPq2/P1PR1P2/1K4N1/PNBRPPPrqnn b - - 71 36';
6-
test.equal(pv2san('crazyhouse', fen, false, 'N@a3 b1b2 R@b1', -2), '36... N@a3+ 37. Kb2 R@b1#');
6+
test.equal(pv2san('crazyhouse', fen, false, 'N@a3 b1b2 R@b1'.split(' '), -2), '36... N@a3+ 37. Kb2 R@b1#');
77
test.done();
88
};
99

1010
exports.testKingmove = function(test) {
11-
test.equal(pv2san('standard', initialFen, false, 'e2e4 e7e5 e1e2'), '1. e4 e5 2. Ke2');
11+
test.equal(pv2san('standard', initialFen, false, 'e2e4 e7e5 e1e2'.split(' ')), '1. e4 e5 2. Ke2');
1212
test.done();
1313
};

ui/ceval/src/pv2san.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,10 @@ function san(board, uci) {
214214
return san;
215215
}
216216

217-
module.exports = function(variant, fen, threat, pv, mate) {
217+
module.exports = function(variant, fen, threat, moves, mate) {
218218
var board = readFen(fen);
219219
if (threat) board.turn = !board.turn;
220220
var turn = board.turn;
221-
var moves = pv.split(' ').slice(0, 10);
222221

223222
var first = true;
224223
var line = moves.map(function(uci) {

ui/ceval/src/stockfishProtocol.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ module.exports = function(worker, opts) {
4242
evalType = matches[5],
4343
nodes = parseInt(matches[6]),
4444
elapsedMs = parseInt(matches[7]),
45-
pv = matches[8];
45+
moves = matches[8].split(' ', 10);
4646

4747
// time is negative on safari
4848
if (!elapsedMs || elapsedMs < 0) elapsedMs = (new Date() - work.startedAt)
@@ -59,8 +59,7 @@ module.exports = function(worker, opts) {
5959
if (evalType && multiPv === 1) return;
6060

6161
var pvData = {
62-
best: pv.split(' ', 2)[0],
63-
pv: pv,
62+
moves: moves,
6463
cp: isMate ? undefined : eval,
6564
mate: isMate ? eval : undefined,
6665
depth: depth,
@@ -73,7 +72,6 @@ module.exports = function(worker, opts) {
7372
depth: depth,
7473
knps: nodes / elapsedMs,
7574
nodes: nodes,
76-
best: pvData.best,
7775
cp: pvData.cp,
7876
mate: pvData.mate,
7977
pvs: [pvData],

ui/ceval/src/view.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,10 @@ module.exports = {
230230
}, range(multiPv).map(function(i) {
231231
if (!pvs[i]) return m('div.pv');
232232
else return m('div.pv', threat ? {} : {
233-
'data-uci': pvs[i].best
233+
'data-uci': pvs[i].moves[0]
234234
}, [
235235
multiPv > 1 ? m('strong', defined(pvs[i].mate) ? ('#' + pvs[i].mate) : renderEval(pvs[i].cp)) : null,
236-
m('span', pv2san(instance.variant.key, ctrl.vm.node.fen, threat, pvs[i].pv, pvs[i].mate))
236+
m('span', pv2san(instance.variant.key, ctrl.vm.node.fen, threat, pvs[i].moves, pvs[i].mate))
237237
]);
238238
}));
239239
}

ui/puzzle/src/autoShape.js

+8-9
Original file line numberDiff line numberDiff line change
@@ -19,36 +19,35 @@ module.exports = function(opts) {
1919
var rcolor = color === 'white' ? 'black' : 'white';
2020
if (hovering && hovering.fen === n.fen) shapes = shapes.concat(makeAutoShapesFromUci(color, hovering.uci, 'paleBlue'));
2121
if (opts.vm.showAutoShapes() && opts.vm.showComputer()) {
22-
if (n.eval && n.eval.best)
23-
shapes = shapes.concat(makeAutoShapesFromUci(rcolor, n.eval.best, 'paleGreen'));
22+
if (n.eval) shapes = shapes.concat(makeAutoShapesFromUci(rcolor, n.eval.best, 'paleGreen'));
2423
if (!hovering) {
2524
var nextBest = opts.nextNodeBest();
26-
if (!nextBest && opts.ceval.enabled() && n.ceval && n.ceval.best) nextBest = n.ceval.best;
25+
if (!nextBest && opts.ceval.enabled() && n.ceval) nextBest = n.ceval.moves[0];
2726
if (nextBest) shapes = shapes.concat(makeAutoShapesFromUci(color, nextBest, 'paleBlue'));
2827
if (opts.ceval.enabled() && n.ceval && n.ceval.pvs && n.ceval.pvs[1] && !(opts.vm.threatMode && n.threat && n.threat.pvs && n.threat.pvs[2])) {
2928
n.ceval.pvs.forEach(function(pv) {
30-
if (pv.best === nextBest) return;
29+
if (pv.moves[0] === nextBest) return;
3130
var shift = winningChances.povDiff(color, n.ceval.pvs[0], pv);
3231
if (shift > 0.2 || isNaN(shift) || shift < 0) return;
33-
shapes = shapes.concat(makeAutoShapesFromUci(color, pv.best, 'paleGrey', {
32+
shapes = shapes.concat(makeAutoShapesFromUci(color, pv.moves[0], 'paleGrey', {
3433
lineWidth: Math.round(12 - shift * 50) // 12 to 2
3534
}));
3635
});
3736
}
3837
}
3938
}
40-
if (opts.ceval.enabled() && opts.vm.threatMode && n.threat && n.threat.best) {
39+
if (opts.ceval.enabled() && opts.vm.threatMode && n.threat && n.threat.moves[0]) {
4140
if (n.threat.pvs[1]) {
42-
shapes = shapes.concat(makeAutoShapesFromUci(rcolor, n.threat.best, 'paleRed'));
41+
shapes = shapes.concat(makeAutoShapesFromUci(rcolor, n.threat.moves[0], 'paleRed'));
4342
n.threat.pvs.slice(1).forEach(function(pv) {
4443
var shift = winningChances.povDiff(rcolor, pv, n.threat.pvs[0]);
4544
if (shift > 0.2 || isNaN(shift) || shift < 0) return;
46-
shapes = shapes.concat(makeAutoShapesFromUci(rcolor, pv.best, 'paleRed', {
45+
shapes = shapes.concat(makeAutoShapesFromUci(rcolor, pv.moves[0], 'paleRed', {
4746
lineWidth: Math.round(11 - shift * 45) // 11 to 2
4847
}));
4948
});
5049
} else
51-
shapes = shapes.concat(makeAutoShapesFromUci(rcolor, n.threat.best, 'red'));
50+
shapes = shapes.concat(makeAutoShapesFromUci(rcolor, n.threat.moves[0], 'red'));
5251
}
5352
return shapes;
5453
};

ui/puzzle/src/ctrl.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ module.exports = function(opts, i18n) {
298298

299299
var nextNodeBest = function() {
300300
return treeOps.withMainlineChild(vm.node, function(n) {
301-
return n.eval ? n.eval.best : null;
301+
return n.eval ? n.eval.moves[0] : null;
302302
});
303303
};
304304

@@ -429,7 +429,7 @@ module.exports = function(opts, i18n) {
429429
toggleCeval: toggleCeval,
430430
toggleThreatMode: toggleThreatMode,
431431
playBestMove: function() {
432-
var uci = nextNodeBest() || (vm.node.ceval && vm.node.ceval.best);
432+
var uci = nextNodeBest() || vm.node.ceval;
433433
if (uci) playUci(uci);
434434
}
435435
});

0 commit comments

Comments
 (0)