Merge branch 'master' into study-sticky

* master:
  remove unused WS code
  better default round timer
  better display blurs on partial analysis graph
  delete unused JS
  update scalachess
  Hard code premoves to 0s client time.
  Remove usage of Centis.abs
study-sticky
Thibault Duplessis 2017-06-14 10:56:09 +02:00
commit 8516696356
6 changed files with 39 additions and 75 deletions

View File

@ -8,10 +8,16 @@ import chess.Centis
class BinaryClockHistoryTest extends Specification {
val eps = Centis(4)
val hour = Centis(60 * 60 * 100)
val day = hour * 24
def beLike(comp: Vector[Centis]) = (acts: Vector[Centis]) => {
acts.size must_== comp.size
(comp zip acts) forall {
case (c, a) => a.centis must beCloseTo(c.centis +/- 4)
}
}
"binary clock history" should {
"handle empty vectors" in {
@ -23,8 +29,7 @@ class BinaryClockHistoryTest extends Specification {
val bytes = BinaryFormat.clockHistory.writeSide(Centis(12345), times, false)
val restored = BinaryFormat.clockHistory.readSide(Centis(12345), bytes, false)
restored.size must_== 1
(restored(0) - times(0)).abs should be_<=(eps)
restored must beLike(times)
}
"restorable" in {
@ -34,16 +39,14 @@ class BinaryClockHistoryTest extends Specification {
).map(t => Centis(21000 - 10 * t))
val bytes = BinaryFormat.clockHistory.writeSide(hour * 2, times, false)
val restored = BinaryFormat.clockHistory.readSide(hour * 2, bytes, false)
times.size must_== restored.size
(restored, times).zipped.map(_ - _).forall(_.abs <= eps) should beTrue
restored must beLike(times)
}
"restore correspondence" in {
val times = Vector(118, 204, 80, 191, 75, 230, 48, 258).map(t => day * 2 - Centis(t))
val bytes = BinaryFormat.clockHistory.writeSide(day * 2, times, false)
val restored = BinaryFormat.clockHistory.readSide(day * 2, bytes, false)
times.size must_== restored.size
(restored, times).zipped.map(_ - _).forall(_.abs <= eps) should beTrue
restored must beLike(times)
}
"not drift" in {
@ -54,8 +57,7 @@ class BinaryClockHistoryTest extends Specification {
val binary = BinaryFormat.clockHistory.writeSide(start, restored :+ end, false)
restored = BinaryFormat.clockHistory.readSide(start, binary, false)
}
times.size must_== restored.size
(restored, times).zipped.map(_ - _).forall(_.abs <= eps) should beTrue
restored must beLike(times)
}
}
}

View File

@ -6,8 +6,8 @@ lichess.advantageChart = function(data) {
lichess.loadScript('/assets/javascripts/chart/division.js').done(function() {
lichess.chartCommon('highchart').done(function() {
lichess.advantageChart.update = function(d) {
$elem.highcharts().series[0].setData(makeSerieData(d));
lichess.advantageChart.update = function(d, partial) {
$elem.highcharts().series[0].setData(makeSerieData(d, partial));
};
var $elem = $('#adv_chart');
@ -15,7 +15,7 @@ lichess.advantageChart = function(data) {
var blurs = [ toBlurArray(data.player), toBlurArray(data.opponent) ];
if (data.player.color === 'white') blurs.reverse();
var makeSerieData = function(d) {
var makeSerieData = function(d, partial) {
return d.treeParts.slice(1).map(function(node, i) {
var color = node.ply & 1;
@ -37,7 +37,7 @@ lichess.advantageChart = function(data) {
name: turn + dots + ' ' + node.san,
y: 2 / (1 + Math.exp(-0.004 * cp)) - 1
};
if (blurs[color].shift() === '1') {
if (!partial && blurs[color].shift() === '1') {
point.marker = {
symbol: 'square',
radius: 3,

View File

@ -1,50 +0,0 @@
lichess.coachPageViewChart = function(graphite, $el) {
lichess.loadScript('/assets/javascripts/chart/common.js').done(function() {
lichess.chartCommon('highchart').done(function() {
var disabled = {
enabled: false
};
var noText = {
text: null
};
var data = graphite[0].datapoints.map(function(p) {
return [p[1] * 1000, p[0]];
});
$el.each(function() {
$(this).highcharts({
yAxis: {
title: noText
},
credits: disabled,
legend: disabled,
series: [{
name: 'Pageviews',
type: 'line',
data: data,
color: '#3893E8',
marker: {
radius: 5
},
lineWidth: 4
}],
chart: {
spacing: [10, 0, 10, 0],
},
plotOptions: {},
title: noText,
xAxis: {
type: 'datetime',
title: noText,
labels: disabled,
lineWidth: 0,
tickWidth: 0,
},
yAxis: [{
title: noText,
opposite: true
}]
});
});
});
});
};

View File

@ -19,9 +19,10 @@ module.exports = function(element, cfg) {
},
events: {
analysisProgress: function(d) {
var partial = !d.tree.eval;
if (!lichess.advantageChart) startAdvantageChart();
else if (lichess.advantageChart.update) lichess.advantageChart.update(data);
if (d.tree.eval) $("#adv_chart_loader").remove();
else if (lichess.advantageChart.update) lichess.advantageChart.update(data, partial);
if (!partial) $("#adv_chart_loader").remove();
},
crowd: function(event) {
$watchers.watchers("set", event.watchers);

View File

@ -56,7 +56,9 @@ module.exports = function(opts, redraw) {
this.socket = new socket(opts.socket, this);
var timer = window.performance || Date;
var timerFunction = (window.performance && performance.now() > 10) ? function() {
return performance.now();
} : Date.now;
var onUserMove = function(orig, dest, meta) {
lichess.ab && (!this.keyboardMove || !this.keyboardMove.usedSan) && lichess.ab(this, meta);
@ -169,11 +171,13 @@ module.exports = function(opts, redraw) {
this.actualSendMove = function(type, action, meta) {
meta = meta === undefined ? {} : meta
var socketOpts = {
ackable: true,
// withLag: !!this.clock
ackable: true
}
if (meta.premove) {
socketOpts.millis = 0;
} else if (this.vm.lastMoveMillis !== null) {
socketOpts.millis = timerFunction() - this.vm.lastMoveMillis;
}
var startTime = this.vm.lastMoveMillis;
if (startTime !== null) socketOpts.millis = timer.now() - startTime;
this.socket.send(type, action, socketOpts);
this.vm.justDropped = meta.justDropped;
@ -192,7 +196,12 @@ module.exports = function(opts, redraw) {
if (this.data.pref.submitMove && !meta.premove) {
this.vm.moveToSubmit = move;
redraw();
} else this.actualSendMove('move', move, {justCaptured: meta.captured});
} else {
this.actualSendMove('move', move, {
justCaptured: meta.captured,
premove: meta.premove
})
};
}.bind(this);
@ -207,7 +216,10 @@ module.exports = function(opts, redraw) {
this.vm.dropToSubmit = drop;
redraw();
} else {
this.actualSendMove('drop', drop, {justDropped: role});
this.actualSendMove('drop', drop, {
justDropped: role,
premove: isPredrop
});
}
}.bind(this);
@ -236,7 +248,7 @@ module.exports = function(opts, redraw) {
var d = this.data,
playing = game.isPlayerPlaying(d);
if (playing) this.vm.lastMoveMillis = timer.now();
if (playing) this.vm.lastMoveMillis = timerFunction();
d.game.turns = o.ply;
d.game.player = o.ply % 2 === 0 ? 'white' : 'black';
var playedColor = o.ply % 2 === 0 ? 'black' : 'white';

View File

@ -68,8 +68,7 @@ lichess.StrongSocket = function(url, version, settings) {
o = o || {};
var msg = { t: t };
if (d !== undefined) {
if (o.withLag) d.l = Math.round(averageLag);
if ('millis' in o) d.s = Math.floor(o.millis * 0.1).toString(36);
if (o.millis !== undefined) d.s = Math.round(o.millis * 0.1).toString(36);
msg.d = d;
}
if (o.ackable) ackable.register(t, d);