implement crazyhouse predrop - closes #1488

This commit is contained in:
Thibault Duplessis 2016-01-22 11:53:19 +07:00
parent 3b4c6520c1
commit 01f55d260b
14 changed files with 36 additions and 23 deletions

View file

@ -9,7 +9,7 @@ net {
ip = "5.196.91.160"
asset {
domain = ${net.domain}
version = 813
version = 814
}
}
play {

File diff suppressed because one or more lines are too long

View file

@ -29,7 +29,7 @@
"watchify": "~3.1.1"
},
"dependencies": {
"chessground": "github:ornicar/chessground#v3.3.6",
"chessground": "github:ornicar/chessground#v3.4.1",
"game": "file:../game",
"mithril": "github:ornicar/mithril.js#v1.0.0"
}

View file

@ -29,7 +29,7 @@
"watchify": "~3.1.1"
},
"dependencies": {
"chessground": "github:ornicar/chessground#v3.3.6",
"chessground": "github:ornicar/chessground#v3.4.1",
"lodash": "~3.7.0",
"mithril": "github:ornicar/mithril.js#v1.0.0"
}

View file

@ -29,7 +29,7 @@
"watchify": "~3.1.1"
},
"dependencies": {
"chessground": "github:ornicar/chessground#v3.3.6",
"chessground": "github:ornicar/chessground#v3.4.1",
"mithril": "github:ornicar/mithril.js#v1.0.0"
}
}

View file

@ -29,7 +29,7 @@
"watchify": "~3.1.1"
},
"dependencies": {
"chessground": "github:ornicar/chessground#v3.3.6",
"chessground": "github:ornicar/chessground#v3.4.1",
"chessli.js": "file:../chessli",
"lodash": "~3.7.0",
"merge": "~1.2.0",

View file

@ -29,7 +29,7 @@
"watchify": "~3.1.1"
},
"dependencies": {
"chessground": "github:ornicar/chessground#v3.3.6",
"chessground": "github:ornicar/chessground#v3.4.1",
"chessli.js": "file:../chessli",
"lodash": "~3.7.0",
"merge": "~1.2.0",

View file

@ -29,7 +29,7 @@
"watchify": "~3.1.1"
},
"dependencies": {
"chessground": "github:ornicar/chessground#v3.3.6",
"chessground": "github:ornicar/chessground#v3.4.1",
"game": "file:../game",
"mithril": "github:ornicar/mithril.js#v1.0.0"
}

View file

@ -2,11 +2,11 @@ var game = require('game').game;
module.exports = {
drop: function(chessground, data, piece, pos) {
drop: function(chessground, data, role, key) {
if (!game.isPlayerTurn(data)) return false;
if (piece.role === 'pawn' && (pos[1] === '1' || pos[1] === '8')) return false;
if (role === 'pawn' && (key[1] === '1' || key[1] === '8')) return false;
var dropStr = data.possibleDrops;
@ -14,6 +14,6 @@ module.exports = {
var drops = dropStr.match(/.{2}/g) || [];
return drops.indexOf(pos) !== -1;
return drops.indexOf(key) !== -1;
}
};

View file

@ -58,9 +58,9 @@ module.exports = function(opts) {
this.sendMove(orig, dest, false, meta.premove);
}.bind(this);
var onUserNewPiece = function(piece, pos) {
if (!this.replaying() && crazyValid.drop(this.chessground, this.data, piece, pos))
this.sendNewPiece(piece.role, pos);
var onUserNewPiece = function(role, key) {
if (!this.replaying() && crazyValid.drop(this.chessground, this.data, role, key))
this.sendNewPiece(role, key);
else this.jump(this.vm.ply);
}.bind(this);
@ -73,7 +73,7 @@ module.exports = function(opts) {
} else sound.move();
}.bind(this);
var onNewPiece = function(piece, pos) {
var onNewPiece = function(piece, key) {
sound.move();
}.bind(this);
@ -105,7 +105,7 @@ module.exports = function(opts) {
fen: s.fen,
lastMove: uciToLastMove(s.uci),
check: s.check,
turnColor: this.vm.ply % 2 === 0 ? 'white' : 'black'
turnColor: this.vm.ply % 2 === 0 ? 'white' : 'black'
};
if (this.replaying()) this.chessground.stop();
else config.movable = {
@ -159,10 +159,10 @@ module.exports = function(opts) {
});
}.bind(this);
this.sendNewPiece = function(role, pos) {
this.sendNewPiece = function(role, key) {
var drop = {
role: role,
pos: pos
pos: key
};
if (this.clock) drop.lag = Math.round(lichess.socket.averageLag);
this.resign(false);
@ -259,13 +259,19 @@ module.exports = function(opts) {
// https://github.com/ornicar/lila/issues/343
var premoveDelay = d.game.variant.key === 'atomic' ? 100 : 10;
setTimeout(function() {
if (!this.chessground.playPremove()) showYourMoveNotification();
if (!this.chessground.playPremove() && !playPredrop()) showYourMoveNotification();
}.bind(this), premoveDelay);
}
this.vm.autoScroll && this.vm.autoScroll.now();
onChange();
}.bind(this);
var playPredrop = function() {
return this.chessground.playPredrop(function(drop) {
return crazyValid.drop(this.chessground, this.data, drop.role, drop.key);
}.bind(this));
}.bind(this);
this.reload = function(cfg) {
m.startComputation();
if (this.stepsHash(cfg.steps) !== this.stepsHash(this.data.steps))

View file

@ -50,6 +50,13 @@ function makeConfig(data, ply, flip) {
unset: m.redraw
}
},
predroppable: {
enabled: data.pref.enablePremove && data.game.variant.key === 'crazyhouse',
events: {
set: m.redraw,
unset: m.redraw
}
},
draggable: {
showGhost: data.pref.highlight
},

View file

@ -137,7 +137,7 @@ module.exports = function(ctrl) {
])
]),
m('div.underboard', [
m('div.center', ctrl.chessground.data.premovable.current ? m('div.premove_alert', ctrl.trans('premoveEnabledClickAnywhereToCancel')) : null),
m('div.center', ctrl.chessground.data.premovable.current || ctrl.chessground.data.predroppable.current.key ? m('div.premove_alert', ctrl.trans('premoveEnabledClickAnywhereToCancel')) : null),
blursAndHolds(ctrl)
])
];

View file

@ -28,7 +28,7 @@
"watchify": "~3.1.1"
},
"dependencies": {
"chessground": "github:ornicar/chessground#v3.3.6",
"chessground": "github:ornicar/chessground#v3.4.1",
"game": "file:../game",
"lodash": "~3.7.0",
"mithril": "github:ornicar/mithril.js#v1.0.0"

View file

@ -28,7 +28,7 @@
"watchify": "~3.1.1"
},
"dependencies": {
"chessground": "github:ornicar/chessground#v3.3.6",
"chessground": "github:ornicar/chessground#v3.4.1",
"game": "file:../game",
"lodash": "~3.7.0",
"mithril": "github:ornicar/mithril.js#v1.0.0"