allow premove in analysis to alleviate network lag

This commit is contained in:
Thibault Duplessis 2015-05-06 23:34:12 +02:00
parent 10319994e5
commit 14da974f1c
3 changed files with 16 additions and 8 deletions

View file

@ -28,7 +28,7 @@ module.exports = function(steps, analysis) {
nextPath.forEach(function(p) { nextPath.forEach(function(p) {
for (i = 0, nb = tree.length; i < nb; i++) { for (i = 0, nb = tree.length; i < nb; i++) {
var step = tree[i]; var step = tree[i];
if (p.ply == step.ply) { if (p.ply === step.ply) {
if (p.variation) { if (p.variation) {
tree = step.variations[p.variation - 1]; tree = step.variations[p.variation - 1];
break; break;
@ -38,11 +38,9 @@ module.exports = function(steps, analysis) {
}); });
if (curStep) { if (curStep) {
curStep.variations = curStep.variations || []; curStep.variations = curStep.variations || [];
if (curStep.san === step.san) return nextPath; if (curStep.san === step.san) return false;;
for (var i = 0; i < curStep.variations.length; i++) { for (var i = 0; i < curStep.variations.length; i++) {
if (curStep.variations[i][0].san === step.san) { if (curStep.variations[i][0].san === step.san) return false;
return treePath.withVariation(nextPath, i + 1);
}
} }
curStep.variations.push([step]); curStep.variations.push([step]);
return treePath.withVariation(nextPath, curStep.variations.length); return treePath.withVariation(nextPath, curStep.variations.length);

View file

@ -1,4 +1,5 @@
var chessground = require('chessground'); var chessground = require('chessground');
var opposite = chessground.util.opposite;
var data = require('./data'); var data = require('./data');
var analyse = require('./analyse'); var analyse = require('./analyse');
var ground = require('./ground'); var ground = require('./ground');
@ -72,7 +73,6 @@ module.exports = function(opts) {
this.vm.cgConfig = config; this.vm.cgConfig = config;
if (!this.chessground) if (!this.chessground)
this.chessground = ground.make(this.data, config, userMove); this.chessground = ground.make(this.data, config, userMove);
this.chessground.stop();
this.chessground.set(config); this.chessground.set(config);
if (opts.onChange) opts.onChange(config.fen, this.vm.path); if (opts.onChange) opts.onChange(config.fen, this.vm.path);
}.bind(this); }.bind(this);
@ -116,11 +116,21 @@ module.exports = function(opts) {
}; };
if (prom) move.promotion = prom; if (prom) move.promotion = prom;
this.socket.sendAnaMove(move); this.socket.sendAnaMove(move);
this.chessground.set({
turnColor: this.chessground.data.movable.color,
movable: {
color: opposite(this.chessground.data.movable.color)
}
});
console.log(this.chessground.data);
}.bind(this); }.bind(this);
this.addStep = function(step, path) { this.addStep = function(step, path) {
this.userJump(this.analyse.addStep(step, treePath.read(path))); var newPath = this.analyse.addStep(step, treePath.read(path));
if (!newPath) return;
this.jump(newPath);
m.redraw(); m.redraw();
this.chessground.playPremove();
}.bind(this); }.bind(this);
this.reset = function() { this.reset = function() {

View file

@ -17,7 +17,7 @@ function makeConfig(data, config, onMove) {
} }
}, },
premovable: { premovable: {
enabled: false enabled: true
}, },
drawable: { drawable: {
enabled: true enabled: true