progress on pgn4web replacement

pull/132/head
Thibault Duplessis 2014-11-03 21:32:58 +01:00
parent a7b2f29d99
commit 45c766acb7
7 changed files with 100 additions and 38 deletions

View File

@ -102,7 +102,7 @@ object Featured {
private type Heuristic = Game => Float
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 heuristics: List[(Heuristic, Float)] = List(
@ -111,7 +111,7 @@ object Featured {
progressHeuristic -> 0.7f)
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 =>
1 - turnBox(game.turns)

View File

@ -171,6 +171,9 @@ div.game_control .jumps {
display: inline-block;
padding: 2px 5px;
}
.lichess_ground .replay .turn .move.empty {
opacity: 0.5;
}
.lichess_ground .replay a.move {
cursor: pointer;
transition: background-color 0.13s;

@ -1 +1 @@
Subproject commit 15a3d5ea63dbc83515c57184fdef3681d2856502
Subproject commit f9f5a9e9d90b1ff72beb45d9ef60e68054d4b3fb

View File

@ -1,9 +1,5 @@
module.exports = function(game, analysis) {
var plyToTurn = function(ply) {
return Math.floor((ply - 1) / 2) + 1;
}
var makeTree = function(sans, fromPly) {
return sans.map(function(san, i) {
return {
@ -34,8 +30,8 @@ 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 || step.variation === 0)) {
tree = move.variations[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);
else break;

View File

@ -4,6 +4,7 @@ var data = require('./data');
var analyse = require('./analyse');
var ground = require('./ground');
var keyboard = require('./keyboard');
var treePath = require('./path');
module.exports = function(cfg, router, i18n, onChange) {
@ -12,10 +13,8 @@ module.exports = function(cfg, router, i18n, onChange) {
this.vm = {
flip: false,
path: [{
ply: 1,
variation: null
}],
path: treePath.default,
pathStr: treePath.write(treePath.default),
situation: null,
continue: false
};
@ -24,7 +23,7 @@ module.exports = function(cfg, router, i18n, onChange) {
var showGround = function() {
var moves = this.analyse.moveList(this.vm.path);
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++) {
move = moves[ply - 1];
h += move;
@ -55,9 +54,11 @@ module.exports = function(cfg, router, i18n, onChange) {
onChange(this.vm.situation.fen, this.vm.ply);
}.bind(this);
this.jump = function(ply) {
if (this.vm.path.ply == ply || ply < 1 || ply > this.data.game.moves.length) return;
this.vm.path.ply = ply;
this.jump = function(path) {
// if (this.vm.path.ply == ply || ply < 1 || ply > this.data.game.moves.length) return;
this.vm.path = path;
this.vm.pathStr = treePath.write(path);
console.log(this.vm.path, this.vm.pathStr);
showGround();
}.bind(this);

View 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;
}
};

View File

@ -5,6 +5,7 @@ var game = require('game').game;
var partial = require('chessground').util.partial;
var renderStatus = require('game').view.status;
var mod = require('game').view.mod;
var treePath = require('./path');
function renderEval(e) {
e = Math.round(e / 10) / 10;
@ -18,13 +19,15 @@ function autoScroll(movelist) {
var emptyMove = m('em.move.empty', '...');
function renderMove(ctrl, move) {
function renderMove(ctrl, move, path) {
if (!move) return emptyMove;
treePath.setPly(path, move.ply);
var pathStr = treePath.write(path);
return {
tag: 'a',
attrs: {
class: 'move' + (move.ply === ctrl.vm.ply ? ' active' : ''),
'data-ply': move.ply
class: 'move' + (pathStr === ctrl.vm.pathStr ? ' active' : ''),
'data-path': pathStr
},
children: [
move.san,
@ -34,37 +37,54 @@ function renderMove(ctrl, move) {
};
}
function renderVariation(ctrl, variation) {
return m('div.variation', variation.map(function(turn) {
return renderVariationTurn(ctrl, turn);
function plyToTurn(ply) {
return Math.floor((ply - 1) / 2) + 1;
}
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) {
var wMove = turn.white ? renderMove(ctrl, turn.white) : null;
var bMove = turn.black ? renderMove(ctrl, turn.black) : null;
function renderVariationTurn(ctrl, turn, path) {
var wMove = turn.white ? renderMove(ctrl, turn.white, path) : null;
var bMove = turn.black ? renderMove(ctrl, turn.black, path) : null;
if (turn.white) return [turn.turn + '.', wMove, (turn.black ? [m.trust('&nbsp;'), bMove] : ''), ' '];
return [turn.turn + '...', bMove, ' '];
}
function renderMeta(ctrl, move) {
function renderMeta(ctrl, move, path) {
if (!move || !move.comments.length || !move.variations.length) return;
return [
move.comments.length ? move.comments.map(function(comment) {
return m('div.comment', comment);
}) : null,
move.variations.length ? move.variations.map(function(variation) {
return renderVariation(ctrl, variation);
move.variations.length ? move.variations.map(function(variation, i) {
return renderVariation(ctrl, variation, treePath.withVariation(path, i + 1));
}) : null,
];
}
function renderTurn(ctrl, turn) {
function renderTurn(ctrl, turn, path) {
var index = m('div.index', turn.turn);
var wMove = turn.white ? renderMove(ctrl, turn.white) : null;
var bMove = turn.black ? renderMove(ctrl, turn.black) : null;
var wMeta = renderMeta(ctrl, turn.white);
var bMeta = renderMeta(ctrl, turn.black);
var wMove = turn.white ? renderMove(ctrl, turn.white, path) : null;
var bMove = turn.black ? renderMove(ctrl, turn.black, path) : null;
var wMeta = renderMeta(ctrl, turn.white, path);
var bMeta = renderMeta(ctrl, turn.black, path);
if (turn.white) {
if (wMeta) return [
m('div.turn', [index, wMove, emptyMove]),
@ -92,8 +112,9 @@ function renderTree(ctrl, tree) {
white: tree[i],
black: tree[i + 1]
});
var path = treePath.default;
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', {
onclick: function(e) {
var ply = e.target.getAttribute('data-ply') || e.target.parentNode.getAttribute('data-ply');
if (ply) {
ctrl.jump(parseInt(ply));
var path = e.target.getAttribute('data-path') || e.target.parentNode.getAttribute('data-path');
if (path) {
ctrl.jump(treePath.read(path));
m.redraw();
}
}