more puzzle WIP
This commit is contained in:
parent
2157223d5f
commit
e7701a1370
|
@ -10,7 +10,7 @@ object TreeBuilder {
|
|||
private type Ply = Int
|
||||
|
||||
def apply(game: Game, plies: Int): tree.Root = {
|
||||
chess.Replay.gameMoveWhileValid(game.pgnMoves.pp take plies.pp pp, Forsyth.initial, game.variant) match {
|
||||
chess.Replay.gameMoveWhileValid(game.pgnMoves take plies, Forsyth.initial, game.variant) match {
|
||||
case (init, games, error) =>
|
||||
error foreach logChessError(game.id)
|
||||
val fen = Forsyth >> init
|
||||
|
|
|
@ -25,7 +25,8 @@ module.exports = function(opts, i18n) {
|
|||
initialPath: null,
|
||||
initialNode: null,
|
||||
canViewSolution: false,
|
||||
keepGoing: false
|
||||
keepGoing: false,
|
||||
lastFeedback: 'init'
|
||||
};
|
||||
|
||||
var data = opts.data;
|
||||
|
@ -69,6 +70,9 @@ module.exports = function(opts, i18n) {
|
|||
fen: node.fen,
|
||||
turnColor: color,
|
||||
movable: movable,
|
||||
premovable: {
|
||||
enabled: false
|
||||
},
|
||||
check: node.check,
|
||||
lastMove: uciToLastMove(node.uci)
|
||||
};
|
||||
|
@ -77,9 +81,11 @@ module.exports = function(opts, i18n) {
|
|||
// can't use when in check because it highlights the wrong king
|
||||
config.turnColor = opposite(color);
|
||||
config.movable.color = color;
|
||||
config.premovable.enabled = true;
|
||||
} else if (vm.mode !== 'view' && color !== data.puzzle.color) { // && !node.check) {
|
||||
config.turnColor = color;
|
||||
config.movable.color = data.puzzle.color;
|
||||
config.premovable.enabled = true;
|
||||
}
|
||||
console.log(dests, config);
|
||||
vm.cgConfig = config;
|
||||
|
@ -141,13 +147,17 @@ module.exports = function(opts, i18n) {
|
|||
m.redraw();
|
||||
};
|
||||
|
||||
var reorderChildren = function(path) {
|
||||
tree.nodeAtPath(path).children.sort(function(c1, c2) {
|
||||
var reorderChildren = function(path, recursive) {
|
||||
var node = tree.nodeAtPath(path);
|
||||
node.children.sort(function(c1, c2) {
|
||||
if (c1.puzzle === 'fail') return 1;
|
||||
if (c1.puzzle === 'retry') return 1;
|
||||
if (c1.puzzle === 'good') return -1;
|
||||
return 0;
|
||||
});
|
||||
if (recursive) node.children.forEach(function(child) {
|
||||
reorderChildren(path + child.id, true);
|
||||
});
|
||||
};
|
||||
|
||||
var revertUserMove = function() {
|
||||
|
@ -160,17 +170,25 @@ module.exports = function(opts, i18n) {
|
|||
|
||||
var applyProgress = function(progress) {
|
||||
if (progress === 'fail') {
|
||||
vm.lastFeedback = 'fail';
|
||||
revertUserMove();
|
||||
if (vm.mode === 'play') {
|
||||
vm.canViewSolution = true;
|
||||
vm.mode = 'try';
|
||||
}
|
||||
}
|
||||
if (progress === 'retry') {
|
||||
else if (progress === 'retry') {
|
||||
vm.lastFeedback = 'retry';
|
||||
revertUserMove();
|
||||
}
|
||||
if (progress && progress.orig) {
|
||||
console.log(tree);
|
||||
else if (progress === 'win') {
|
||||
vm.lastFeedback = 'win';
|
||||
vm.mode = 'view';
|
||||
showGround(); // to disable premoves
|
||||
}
|
||||
else if (progress && progress.orig) {
|
||||
vm.lastFeedback = 'good';
|
||||
// console.log(tree);
|
||||
vm.keepGoing = true;
|
||||
setTimeout(function() {
|
||||
socket.sendAnaMove(progress);
|
||||
|
@ -252,7 +270,9 @@ module.exports = function(opts, i18n) {
|
|||
|
||||
var viewSolution = function() {
|
||||
vm.mode = 'view';
|
||||
mergeSolution(tree, vm.initialNode, data.puzzle.branch);
|
||||
mergeSolution(tree, vm.initialNode, data.puzzle.branch, data.puzzle.color);
|
||||
reorderChildren(vm.initialPath, true);
|
||||
vm.autoScrollRequested = true;
|
||||
m.redraw();
|
||||
};
|
||||
|
||||
|
|
|
@ -37,14 +37,27 @@ function good(ctrl) {
|
|||
]);
|
||||
}
|
||||
|
||||
function retry(ctrl) {
|
||||
return m('div.feedback.retry', [
|
||||
m('div.player', [
|
||||
m('div.icon', '!'),
|
||||
m('div.instruction', [
|
||||
m('strong', ctrl.trans.noarg('goodMove')),
|
||||
m('em', ctrl.trans.noarg('butYouCanDoBetter'))
|
||||
])
|
||||
]),
|
||||
ctrl.vm.canViewSolution ? viewSolution(ctrl) : null
|
||||
]);
|
||||
}
|
||||
|
||||
function view(ctrl) {
|
||||
return m('div.feedback.view', [
|
||||
'view'
|
||||
]);
|
||||
}
|
||||
|
||||
function failed(ctrl) {
|
||||
return m('div.feedback.try', [
|
||||
function fail(ctrl) {
|
||||
return m('div.feedback.fail', [
|
||||
m('div.player', [
|
||||
m('div.icon', '✗'),
|
||||
m('div.instruction', [
|
||||
|
@ -56,14 +69,23 @@ function failed(ctrl) {
|
|||
]);
|
||||
}
|
||||
|
||||
function win(ctrl) {
|
||||
return m('div.feedback.win', [
|
||||
m('div.player', [
|
||||
m('div.icon', '✓'),
|
||||
m('div.instruction', [
|
||||
m('strong', ctrl.trans.noarg('victory'))
|
||||
])
|
||||
]),
|
||||
'Show next button'
|
||||
]);
|
||||
}
|
||||
|
||||
module.exports = function(ctrl) {
|
||||
|
||||
if (ctrl.vm.mode === 'play') {
|
||||
if (ctrl.vm.initialNode.children.filter(function(node) {
|
||||
return node.puzzle === 'good';
|
||||
}).length) return good(ctrl);
|
||||
return initial(ctrl);
|
||||
}
|
||||
if (ctrl.vm.mode === 'try') return failed(ctrl);
|
||||
if (ctrl.vm.mode === 'view') return view(ctrl);
|
||||
if (ctrl.vm.lastFeedback === 'init') return initial(ctrl);
|
||||
if (ctrl.vm.lastFeedback === 'good') return good(ctrl);
|
||||
if (ctrl.vm.lastFeedback === 'retry') return retry(ctrl);
|
||||
if (ctrl.vm.lastFeedback === 'fail') return fail(ctrl);
|
||||
if (ctrl.vm.lastFeedback === 'win') return win(ctrl);
|
||||
};
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
var treeOps = require('tree').ops;
|
||||
|
||||
module.exports = function(tree, initialNode, solution) {
|
||||
module.exports = function(tree, initialNode, solution, color) {
|
||||
|
||||
tree.ops.updateAll(solution, function(node) {
|
||||
node.puzzle = 'good';
|
||||
if (color === 'white' ^ (node.ply % 2 === 0)) node.puzzle = 'good';
|
||||
});
|
||||
|
||||
var solutionNode = treeOps.childById(initialNode, solution.id);
|
||||
|
|
|
@ -116,11 +116,6 @@ module.exports = function(ctrl) {
|
|||
]),
|
||||
m('div.underboard', [
|
||||
m('div.center', [
|
||||
ctrl.vm.mode,
|
||||
(ctrl.vm.mode !== 'view' && ctrl.vm.keepGoing) ? m('div.comment.great', [
|
||||
m('h3.text[data-icon=E]', m('strong', ctrl.trans.noarg('bestMove'))),
|
||||
m('span', ctrl.trans.noarg('keepGoing'))
|
||||
]) : null
|
||||
])
|
||||
])
|
||||
];
|
||||
|
|
Loading…
Reference in a new issue