more progress on analysis exploration

This commit is contained in:
Thibault Duplessis 2014-11-23 20:18:15 +01:00
parent 49172a941d
commit f0d535bded
3 changed files with 31 additions and 24 deletions

View file

@ -1,3 +1,5 @@
var treePath = require('./path');
module.exports = function(game, analysis) {
var makeTree = function(sans, fromPly) {
@ -30,7 +32,7 @@ module.exports = function(game, analysis) {
path.forEach(function(step) {
for (i = 0, nb = tree.length; i < nb; i++) {
var move = tree[i];
if (step.ply === move.ply && step.variation) {
if (step.ply == move.ply && step.variation) {
tree = move.variations[step.variation - 1];
break;
} else if (step.ply >= move.ply) moves.push(move.san);
@ -41,23 +43,39 @@ module.exports = function(game, analysis) {
}.bind(this);
this.explore = function(path, san) {
var nextPath = treePath.withPly(path, treePath.currentPly(path) + 1);
var moves = this.moveList(nextPath);
if (moves[moves.length - 1] == san) return nextPath;
var tree = this.tree;
var curMove = null;
path.forEach(function(step) {
for (i = 0, nb = tree.length; i < nb; i++) {
var move = tree[i];
if (step.ply === move.ply && step.variation) {
if (step.ply == move.ply && step.variation) {
tree = move.variations[step.variation - 1];
break;
} else if (step.ply == move.ply) curMove = move;
else if (step.ply < move.ply) break;
}
});
curMove.variations = [[{
ply: curMove.ply + 1,
san: san,
comments: [],
variations: []
}]];
if (curMove) {
curMove.variations = [[{
ply: curMove.ply,
san: san,
comments: [],
variations: []
}]];
return treePath.withPly(treePath.withVariation(path, 1), curMove.ply);
} else {
var newPly = treePath.currentPly(path);
tree.push({
ply: newPly,
san: san,
comments: [],
variations: []
});
return treePath.withPly(path, newPly);
}
}.bind(this);
}

View file

@ -103,14 +103,14 @@ module.exports = function(cfg, router, i18n, onChange) {
}.bind(this);
this.onMove = function(orig, dest) {
console.log(this.analyse.tree);
var chess = new Chess(
this.vm.situation.fen,
this.data.game.variant.key == 'chess960' ? 1 : 0
);
var m = chess.move({from: orig, to: dest});
if (!m) return;
this.analyse.explore(this.vm.path, m.san);
var move = chess.move({from: orig, to: dest});
if (!move) return;
this.jump(this.analyse.explore(this.vm.path, move.san));
m.redraw();
}.bind(this);
this.router = router;

View file

@ -183,18 +183,7 @@ function renderAnalyse(ctrl) {
function visualBoard(ctrl) {
return m('div.lichess_board_wrap',
m('div.lichess_board.' + ctrl.data.game.variant.key, {
config: function(el, isUpdate) {
if (!isUpdate) el.addEventListener('wheel', function(e) {
if (e.deltaY > 0) control.next(ctrl);
else if (e.deltaY < 0) control.prev(ctrl);
m.redraw();
e.preventDefault();
return false;
});
}
},
chessground.view(ctrl.chessground)));
m('div.lichess_board.' + ctrl.data.game.variant.key, chessground.view(ctrl.chessground)));
}
function blindBoard(ctrl) {