progress on pgn4web replacement
This commit is contained in:
parent
a7b2f29d99
commit
45c766acb7
|
@ -102,7 +102,7 @@ object Featured {
|
||||||
|
|
||||||
private type Heuristic = Game => Float
|
private type Heuristic = Game => Float
|
||||||
private val heuristicBox = box(0 to 1) _
|
private val heuristicBox = box(0 to 1) _
|
||||||
private val ratingBox = box(1000 to 2600) _
|
private val ratingBox = box(1000 to 2700) _
|
||||||
private val turnBox = box(1 to 25) _
|
private val turnBox = box(1 to 25) _
|
||||||
|
|
||||||
private val heuristics: List[(Heuristic, Float)] = List(
|
private val heuristics: List[(Heuristic, Float)] = List(
|
||||||
|
@ -111,7 +111,7 @@ object Featured {
|
||||||
progressHeuristic -> 0.7f)
|
progressHeuristic -> 0.7f)
|
||||||
|
|
||||||
private[tv] def ratingHeuristic(color: Color): Heuristic = game =>
|
private[tv] def ratingHeuristic(color: Color): Heuristic = game =>
|
||||||
ratingBox(game.player(color).rating | 1100)
|
ratingBox(game.player(color).rating | 1400)
|
||||||
|
|
||||||
private[tv] def progressHeuristic: Heuristic = game =>
|
private[tv] def progressHeuristic: Heuristic = game =>
|
||||||
1 - turnBox(game.turns)
|
1 - turnBox(game.turns)
|
||||||
|
|
|
@ -171,6 +171,9 @@ div.game_control .jumps {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
padding: 2px 5px;
|
padding: 2px 5px;
|
||||||
}
|
}
|
||||||
|
.lichess_ground .replay .turn .move.empty {
|
||||||
|
opacity: 0.5;
|
||||||
|
}
|
||||||
.lichess_ground .replay a.move {
|
.lichess_ground .replay a.move {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
transition: background-color 0.13s;
|
transition: background-color 0.13s;
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 15a3d5ea63dbc83515c57184fdef3681d2856502
|
Subproject commit f9f5a9e9d90b1ff72beb45d9ef60e68054d4b3fb
|
|
@ -1,9 +1,5 @@
|
||||||
module.exports = function(game, analysis) {
|
module.exports = function(game, analysis) {
|
||||||
|
|
||||||
var plyToTurn = function(ply) {
|
|
||||||
return Math.floor((ply - 1) / 2) + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
var makeTree = function(sans, fromPly) {
|
var makeTree = function(sans, fromPly) {
|
||||||
return sans.map(function(san, i) {
|
return sans.map(function(san, i) {
|
||||||
return {
|
return {
|
||||||
|
@ -34,8 +30,8 @@ module.exports = function(game, analysis) {
|
||||||
path.forEach(function(step) {
|
path.forEach(function(step) {
|
||||||
for (i = 0, nb = tree.length; i < nb; i++) {
|
for (i = 0, nb = tree.length; i < nb; i++) {
|
||||||
var move = tree[i];
|
var move = tree[i];
|
||||||
if (step.ply === move.ply && (step.variation || step.variation === 0)) {
|
if (step.ply === move.ply && step.variation) {
|
||||||
tree = move.variations[step.variation];
|
tree = move.variations[step.variation - 1];
|
||||||
break;
|
break;
|
||||||
} else if (step.ply >= move.ply) moves.push(move.san);
|
} else if (step.ply >= move.ply) moves.push(move.san);
|
||||||
else break;
|
else break;
|
||||||
|
|
|
@ -4,6 +4,7 @@ var data = require('./data');
|
||||||
var analyse = require('./analyse');
|
var analyse = require('./analyse');
|
||||||
var ground = require('./ground');
|
var ground = require('./ground');
|
||||||
var keyboard = require('./keyboard');
|
var keyboard = require('./keyboard');
|
||||||
|
var treePath = require('./path');
|
||||||
|
|
||||||
module.exports = function(cfg, router, i18n, onChange) {
|
module.exports = function(cfg, router, i18n, onChange) {
|
||||||
|
|
||||||
|
@ -12,10 +13,8 @@ module.exports = function(cfg, router, i18n, onChange) {
|
||||||
|
|
||||||
this.vm = {
|
this.vm = {
|
||||||
flip: false,
|
flip: false,
|
||||||
path: [{
|
path: treePath.default,
|
||||||
ply: 1,
|
pathStr: treePath.write(treePath.default),
|
||||||
variation: null
|
|
||||||
}],
|
|
||||||
situation: null,
|
situation: null,
|
||||||
continue: false
|
continue: false
|
||||||
};
|
};
|
||||||
|
@ -24,7 +23,7 @@ module.exports = function(cfg, router, i18n, onChange) {
|
||||||
var showGround = function() {
|
var showGround = function() {
|
||||||
var moves = this.analyse.moveList(this.vm.path);
|
var moves = this.analyse.moveList(this.vm.path);
|
||||||
var nbMoves = moves.length;
|
var nbMoves = moves.length;
|
||||||
var ply, move, cached, fen, hash, h, lm;
|
var ply, move, cached, fen, hash = '', h, lm;
|
||||||
for (ply = 1; ply <= nbMoves; ply++) {
|
for (ply = 1; ply <= nbMoves; ply++) {
|
||||||
move = moves[ply - 1];
|
move = moves[ply - 1];
|
||||||
h += move;
|
h += move;
|
||||||
|
@ -55,9 +54,11 @@ module.exports = function(cfg, router, i18n, onChange) {
|
||||||
onChange(this.vm.situation.fen, this.vm.ply);
|
onChange(this.vm.situation.fen, this.vm.ply);
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
|
|
||||||
this.jump = function(ply) {
|
this.jump = function(path) {
|
||||||
if (this.vm.path.ply == ply || ply < 1 || ply > this.data.game.moves.length) return;
|
// if (this.vm.path.ply == ply || ply < 1 || ply > this.data.game.moves.length) return;
|
||||||
this.vm.path.ply = ply;
|
this.vm.path = path;
|
||||||
|
this.vm.pathStr = treePath.write(path);
|
||||||
|
console.log(this.vm.path, this.vm.pathStr);
|
||||||
showGround();
|
showGround();
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
|
|
||||||
|
|
41
ui/analyse/src/path.js
Normal file
41
ui/analyse/src/path.js
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
module.exports = {
|
||||||
|
|
||||||
|
default: [{
|
||||||
|
ply: 1,
|
||||||
|
variation: null
|
||||||
|
}],
|
||||||
|
|
||||||
|
read: function(str) {
|
||||||
|
return str.split(',').map(function(step) {
|
||||||
|
var s = step.split(':');
|
||||||
|
return {
|
||||||
|
ply: parseInt(s[0]),
|
||||||
|
variation: s[1] ? parseInt(s[1]) : null
|
||||||
|
};
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
write: function(path) {
|
||||||
|
return path.map(function(step) {
|
||||||
|
return step.variation ? step.ply + ':' + step.variation : step.ply;
|
||||||
|
}).join(',');
|
||||||
|
},
|
||||||
|
|
||||||
|
setPly: function(path, ply) {
|
||||||
|
path[path.length -1].ply = ply;
|
||||||
|
},
|
||||||
|
|
||||||
|
withVariation: function(path, index) {
|
||||||
|
var p2 = path.slice(0);
|
||||||
|
var last = p2.length - 1;
|
||||||
|
p2[last] = {
|
||||||
|
ply: p2[last].ply - 1,
|
||||||
|
variation: index
|
||||||
|
};
|
||||||
|
p2.push({
|
||||||
|
ply: null,
|
||||||
|
variation: null
|
||||||
|
});
|
||||||
|
return p2;
|
||||||
|
}
|
||||||
|
};
|
|
@ -5,6 +5,7 @@ var game = require('game').game;
|
||||||
var partial = require('chessground').util.partial;
|
var partial = require('chessground').util.partial;
|
||||||
var renderStatus = require('game').view.status;
|
var renderStatus = require('game').view.status;
|
||||||
var mod = require('game').view.mod;
|
var mod = require('game').view.mod;
|
||||||
|
var treePath = require('./path');
|
||||||
|
|
||||||
function renderEval(e) {
|
function renderEval(e) {
|
||||||
e = Math.round(e / 10) / 10;
|
e = Math.round(e / 10) / 10;
|
||||||
|
@ -18,13 +19,15 @@ function autoScroll(movelist) {
|
||||||
|
|
||||||
var emptyMove = m('em.move.empty', '...');
|
var emptyMove = m('em.move.empty', '...');
|
||||||
|
|
||||||
function renderMove(ctrl, move) {
|
function renderMove(ctrl, move, path) {
|
||||||
if (!move) return emptyMove;
|
if (!move) return emptyMove;
|
||||||
|
treePath.setPly(path, move.ply);
|
||||||
|
var pathStr = treePath.write(path);
|
||||||
return {
|
return {
|
||||||
tag: 'a',
|
tag: 'a',
|
||||||
attrs: {
|
attrs: {
|
||||||
class: 'move' + (move.ply === ctrl.vm.ply ? ' active' : ''),
|
class: 'move' + (pathStr === ctrl.vm.pathStr ? ' active' : ''),
|
||||||
'data-ply': move.ply
|
'data-path': pathStr
|
||||||
},
|
},
|
||||||
children: [
|
children: [
|
||||||
move.san,
|
move.san,
|
||||||
|
@ -34,37 +37,54 @@ function renderMove(ctrl, move) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderVariation(ctrl, variation) {
|
function plyToTurn(ply) {
|
||||||
return m('div.variation', variation.map(function(turn) {
|
return Math.floor((ply - 1) / 2) + 1;
|
||||||
return renderVariationTurn(ctrl, turn);
|
}
|
||||||
|
|
||||||
|
function renderVariation(ctrl, variation, path) {
|
||||||
|
var turns = [];
|
||||||
|
if (variation[0].ply % 2 === 0) {
|
||||||
|
var move = variation.shift();
|
||||||
|
turns.push({
|
||||||
|
turn: plyToTurn(move.ply),
|
||||||
|
black: move
|
||||||
|
});
|
||||||
|
}
|
||||||
|
for (i = 0, nb = variation.length; i < nb; i += 2) turns.push({
|
||||||
|
turn: plyToTurn(variation[i].ply),
|
||||||
|
white: variation[i],
|
||||||
|
black: variation[i + 1]
|
||||||
|
});
|
||||||
|
return m('div.variation', turns.map(function(turn) {
|
||||||
|
return renderVariationTurn(ctrl, turn, path);
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderVariationTurn(ctrl, turn) {
|
function renderVariationTurn(ctrl, turn, path) {
|
||||||
var wMove = turn.white ? renderMove(ctrl, turn.white) : null;
|
var wMove = turn.white ? renderMove(ctrl, turn.white, path) : null;
|
||||||
var bMove = turn.black ? renderMove(ctrl, turn.black) : null;
|
var bMove = turn.black ? renderMove(ctrl, turn.black, path) : null;
|
||||||
if (turn.white) return [turn.turn + '.', wMove, (turn.black ? [m.trust(' '), bMove] : ''), ' '];
|
if (turn.white) return [turn.turn + '.', wMove, (turn.black ? [m.trust(' '), bMove] : ''), ' '];
|
||||||
return [turn.turn + '...', bMove, ' '];
|
return [turn.turn + '...', bMove, ' '];
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderMeta(ctrl, move) {
|
function renderMeta(ctrl, move, path) {
|
||||||
if (!move || !move.comments.length || !move.variations.length) return;
|
if (!move || !move.comments.length || !move.variations.length) return;
|
||||||
return [
|
return [
|
||||||
move.comments.length ? move.comments.map(function(comment) {
|
move.comments.length ? move.comments.map(function(comment) {
|
||||||
return m('div.comment', comment);
|
return m('div.comment', comment);
|
||||||
}) : null,
|
}) : null,
|
||||||
move.variations.length ? move.variations.map(function(variation) {
|
move.variations.length ? move.variations.map(function(variation, i) {
|
||||||
return renderVariation(ctrl, variation);
|
return renderVariation(ctrl, variation, treePath.withVariation(path, i + 1));
|
||||||
}) : null,
|
}) : null,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderTurn(ctrl, turn) {
|
function renderTurn(ctrl, turn, path) {
|
||||||
var index = m('div.index', turn.turn);
|
var index = m('div.index', turn.turn);
|
||||||
var wMove = turn.white ? renderMove(ctrl, turn.white) : null;
|
var wMove = turn.white ? renderMove(ctrl, turn.white, path) : null;
|
||||||
var bMove = turn.black ? renderMove(ctrl, turn.black) : null;
|
var bMove = turn.black ? renderMove(ctrl, turn.black, path) : null;
|
||||||
var wMeta = renderMeta(ctrl, turn.white);
|
var wMeta = renderMeta(ctrl, turn.white, path);
|
||||||
var bMeta = renderMeta(ctrl, turn.black);
|
var bMeta = renderMeta(ctrl, turn.black, path);
|
||||||
if (turn.white) {
|
if (turn.white) {
|
||||||
if (wMeta) return [
|
if (wMeta) return [
|
||||||
m('div.turn', [index, wMove, emptyMove]),
|
m('div.turn', [index, wMove, emptyMove]),
|
||||||
|
@ -92,8 +112,9 @@ function renderTree(ctrl, tree) {
|
||||||
white: tree[i],
|
white: tree[i],
|
||||||
black: tree[i + 1]
|
black: tree[i + 1]
|
||||||
});
|
});
|
||||||
|
var path = treePath.default;
|
||||||
return turns.map(function(turn) {
|
return turns.map(function(turn) {
|
||||||
return renderTurn(ctrl, turn);
|
return renderTurn(ctrl, turn, path);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,9 +141,9 @@ function renderAnalyse(ctrl) {
|
||||||
}
|
}
|
||||||
return m('div.analyse', {
|
return m('div.analyse', {
|
||||||
onclick: function(e) {
|
onclick: function(e) {
|
||||||
var ply = e.target.getAttribute('data-ply') || e.target.parentNode.getAttribute('data-ply');
|
var path = e.target.getAttribute('data-path') || e.target.parentNode.getAttribute('data-path');
|
||||||
if (ply) {
|
if (path) {
|
||||||
ctrl.jump(parseInt(ply));
|
ctrl.jump(treePath.read(path));
|
||||||
m.redraw();
|
m.redraw();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue