Skip to content

Commit

Permalink
implement crazyhouse analysis!
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Jan 19, 2016
1 parent ec34acd commit 910a4ca
Show file tree
Hide file tree
Showing 25 changed files with 396 additions and 40 deletions.
2 changes: 1 addition & 1 deletion conf/base.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ net {
ip = "5.196.91.160"
asset {
domain = ${net.domain}
version = 800
version = 801
}
}
play {
Expand Down
2 changes: 1 addition & 1 deletion modules/chess
Submodule chess updated from 8704c6 to 8a22e8
2 changes: 2 additions & 0 deletions modules/round/src/main/StepBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ object StepBuilder {
fen = Forsyth >> g,
check = g.situation.check,
dests = None,
drops = None,
crazyData = g.situation.board.crazyData)
}
JsArray(a.fold[Seq[Step]](steps) {
Expand Down Expand Up @@ -88,6 +89,7 @@ object StepBuilder {
fen = Forsyth >> g,
check = g.situation.check,
dests = None,
drops = None,
crazyData = g.situation.board.crazyData)
}
}
Expand Down
46 changes: 46 additions & 0 deletions modules/socket/src/main/AnaDrop.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package lila.socket

import chess.format.Uci
import lila.common.PimpedJson._
import play.api.libs.json.JsObject

case class AnaDrop(
role: chess.Role,
pos: chess.Pos,
variant: chess.variant.Variant,
fen: String,
path: String) {

def step: Valid[Step] =
chess.Game(variant.some, fen.some).drop(role, pos) map {
case (game, drop) =>
val movable = !game.situation.end
Step(
ply = game.turns,
move = game.pgnMoves.lastOption.map { san =>
Step.Move(Uci(drop), san)
},
fen = chess.format.Forsyth >> game,
check = game.situation.check,
dests = Some(movable ?? game.situation.destinations),
drops = movable.fold(game.situation.drops, Some(Nil)),
crazyData = game.situation.board.crazyData)
}
}

object AnaDrop {

def parse(o: JsObject) = for {
d o obj "d"
role d str "role" flatMap chess.Role.allByName.get
pos d str "pos" flatMap chess.Pos.posAt
variant = chess.variant.Variant orDefault ~d.str("variant")
fen d str "fen"
path d str "path"
} yield AnaDrop(
role = role,
pos = pos,
variant = variant,
fen = fen,
path = path)
}
21 changes: 12 additions & 9 deletions modules/socket/src/main/AnaMove.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@ case class AnaMove(

def step: Valid[Step] =
chess.Game(variant.some, fen.some)(orig, dest, promotion) map {
case (game, move) => Step(
ply = game.turns,
move = game.pgnMoves.lastOption.map { san =>
Step.Move(Uci(move), san)
},
fen = chess.format.Forsyth >> game,
check = game.situation.check,
dests = Some(!game.situation.end ?? game.situation.destinations),
crazyData = game.situation.board.crazyData)
case (game, move) =>
val movable = !game.situation.end
Step(
ply = game.turns,
move = game.pgnMoves.lastOption.map { san =>
Step.Move(Uci(move), san)
},
fen = chess.format.Forsyth >> game,
check = game.situation.check,
dests = Some(movable ?? game.situation.destinations),
drops = movable.fold(game.situation.drops, Some(Nil)),
crazyData = game.situation.board.crazyData)
}
}

Expand Down
13 changes: 13 additions & 0 deletions modules/socket/src/main/Handler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ object Handler {
}
}
}
case ("anaDrop", o) => AnaRateLimit(uid) {
AnaDrop parse o foreach { anaDrop =>
anaDrop.step match {
case scalaz.Success(step) =>
member push lila.socket.Socket.makeMessage("step", Json.obj(
"step" -> step.toJson,
"path" -> anaDrop.path
))
case scalaz.Failure(err) =>
member push lila.socket.Socket.makeMessage("stepFailure", err.toString)
}
}
}
case ("anaDests", o) => AnaRateLimit(uid) {
AnaDests parse o match {
case Some(req) =>
Expand Down
4 changes: 4 additions & 0 deletions modules/socket/src/main/Step.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ case class Step(
check: Boolean,
// None when not computed yet
dests: Option[Map[Pos, List[Pos]]],
drops: Option[List[Pos]],
eval: Option[Step.Eval] = None,
nag: Option[String] = None,
comments: List[String] = Nil,
Expand Down Expand Up @@ -70,6 +71,9 @@ object Step {
case (orig, dests) => s"${orig.piotr}${dests.map(_.piotr).mkString}"
}.mkString(" ")
}) _ compose
add("drops", drops.map { drops =>
JsString(drops.map(_.key).mkString)
}) _ compose
add("crazy", crazyData)
)(Json.obj(
"ply" -> ply,
Expand Down
3 changes: 3 additions & 0 deletions public/stylesheets/analyse.css
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ div.gauge_displayed div.lichess_game div.lichess_ground {
.ceval_displayed .lichess_ground .replay {
height: calc(100% - 40px - 41px);
}
.crazy .lichess_ground .replay {
height: calc(100% - 40px - 150px);
}
.lichess_ground .action_menu {
border-color: transparent;
}
Expand Down
4 changes: 2 additions & 2 deletions public/stylesheets/board.css
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ div.table {
margin-left: 0;
border-radius: 3px 0 0 3px;
}
.lichess_ground .pocket.bottom .role:hover {
.lichess_ground .pocket.usable .role:hover {
background: #999;
}
.lichess_ground .pocket .no-square {
Expand All @@ -641,7 +641,7 @@ div.table {
.is3d .lichess_ground .pocket .no-square {
height: 58.102px;
}
.lichess_ground .pocket.bottom piece {
.lichess_ground .pocket.usable piece {
cursor: pointer;
}
div.table.spectator {
Expand Down
130 changes: 130 additions & 0 deletions ui/analyse/npm-debug.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
0 info it worked if it ends with ok
1 verbose cli [ '/usr/bin/node', '/usr/bin/npm', 'i' ]
2 info using [email protected]
3 info using [email protected]
4 silly loadCurrentTree Starting
5 silly install loadCurrentTree
6 silly install readLocalPackageData
7 silly install normalizeTree
8 silly loadCurrentTree Finishing
9 silly loadIdealTree Starting
10 silly install loadIdealTree
11 silly cloneCurrentTree Starting
12 silly install cloneCurrentTreeToIdealTree
13 silly cloneCurrentTree Finishing
14 silly loadShrinkwrap Starting
15 silly install loadShrinkwrap
16 silly loadShrinkwrap Finishing
17 silly loadAllDepsIntoIdealTree Starting
18 silly install loadAllDepsIntoIdealTree
19 silly fetchOtherPackageData chessground@github:ornicar/chessground#v3.3.2
20 silly cache add args [ 'chessground@github:ornicar/chessground#v3.3.2', null ]
21 verbose cache add spec chessground@github:ornicar/chessground#v3.3.2
22 silly cache add parsed spec Result {
22 silly cache add raw: 'chessground@github:ornicar/chessground#v3.3.2',
22 silly cache add scope: null,
22 silly cache add name: 'chessground',
22 silly cache add rawSpec: 'github:ornicar/chessground#v3.3.2',
22 silly cache add spec: 'github:ornicar/chessground#v3.3.2',
22 silly cache add type: 'hosted',
22 silly cache add hosted:
22 silly cache add { type: 'github',
22 silly cache add ssh: '[email protected]:ornicar/chessground.git#v3.3.2',
22 silly cache add sshUrl: 'git+ssh:https://[email protected]/ornicar/chessground.git#v3.3.2',
22 silly cache add httpsUrl: 'git+https://github.com/ornicar/chessground.git#v3.3.2',
22 silly cache add gitUrl: 'git:https://github.com/ornicar/chessground.git#v3.3.2',
22 silly cache add shortcut: 'github:ornicar/chessground#v3.3.2',
22 silly cache add directUrl: 'https://raw.githubusercontent.com/ornicar/chessground/v3.3.2/package.json' } }
23 verbose addRemoteGit caching github:ornicar/chessground#v3.3.2
24 verbose addRemoteGit ornicar/chessground#v3.3.2 is a repository hosted by github
25 silly tryGitProto attempting to clone git:https://github.com/ornicar/chessground.git#v3.3.2
26 silly tryClone cloning ornicar/chessground#v3.3.2 via git:https://github.com/ornicar/chessground.git#v3.3.2
27 verbose tryClone git-github-com-ornicar-chessground-git-v3-3-2-32da808f not in flight; caching
28 info git [ 'config', '--get', 'remote.origin.url' ]
29 silly validateExistingRemote ornicar/chessground#v3.3.2 remote.origin.url: git:https://github.com/ornicar/chessground.git
30 verbose validateExistingRemote ornicar/chessground#v3.3.2 is updating existing cached remote /home/thib/.npm/_git-remotes/git-github-com-ornicar-chessground-git-v3-3-2-32da808f
31 info git [ 'fetch', '-a', 'origin' ]
32 error git fetch -a origin (git:https://github.com/ornicar/chessground.git) fatal: Unable to look up github.com (port 9418) (Name or service not known)
33 silly tryHTTPS attempting to clone git+https://github.com/ornicar/chessground.git#v3.3.2
34 silly tryClone cloning ornicar/chessground#v3.3.2 via git+https://github.com/ornicar/chessground.git#v3.3.2
35 verbose tryClone git-https-github-com-ornicar-chessground-git-v3-3-2-576cb6bb not in flight; caching
36 info git [ 'clone',
36 info git '--template=/home/thib/.npm/_git-remotes/_templates',
36 info git '--mirror',
36 info git 'https://github.com/ornicar/chessground.git',
36 info git '/home/thib/.npm/_git-remotes/git-https-github-com-ornicar-chessground-git-v3-3-2-576cb6bb' ]
37 verbose git clone --template=/home/thib/.npm/_git-remotes/_templates --mirror https://github.com/ornicar/chessground.git /home/thib/.npm/_git-remotes/git-https-github-com-ornicar-chessground-git-v3-3-2-576cb6bb: Cloning into bare repository '/home/thib/.npm/_git-remotes/git-https-github-com-ornicar-chessground-git-v3-3-2-576cb6bb'...
37 verbose git clone --template=/home/thib/.npm/_git-remotes/_templates --mirror https://github.com/ornicar/chessground.git /home/thib/.npm/_git-remotes/git-https-github-com-ornicar-chessground-git-v3-3-2-576cb6bb: fatal: unable to access 'https://github.com/ornicar/chessground.git/': Could not resolve host: github.com
38 silly trySSH attempting to clone [email protected]:ornicar/chessground.git#v3.3.2
39 silly tryClone cloning ornicar/chessground#v3.3.2 via [email protected]:ornicar/chessground.git#v3.3.2
40 verbose tryClone git-github-com-ornicar-chessground-git-v3-3-2-74389233 not in flight; caching
41 info git [ 'clone',
41 info git '--template=/home/thib/.npm/_git-remotes/_templates',
41 info git '--mirror',
41 info git '[email protected]:ornicar/chessground.git',
41 info git '/home/thib/.npm/_git-remotes/git-github-com-ornicar-chessground-git-v3-3-2-74389233' ]
42 error git clone --template=/home/thib/.npm/_git-remotes/_templates --mirror [email protected]:ornicar/chessground.git /home/thib/.npm/_git-remotes/git-github-com-ornicar-chessground-git-v3-3-2-74389233: Cloning into bare repository '/home/thib/.npm/_git-remotes/git-github-com-ornicar-chessground-git-v3-3-2-74389233'...
42 error git clone --template=/home/thib/.npm/_git-remotes/_templates --mirror [email protected]:ornicar/chessground.git /home/thib/.npm/_git-remotes/git-github-com-ornicar-chessground-git-v3-3-2-74389233: ssh: Could not resolve hostname github.com: Name or service not known
42 error git clone --template=/home/thib/.npm/_git-remotes/_templates --mirror [email protected]:ornicar/chessground.git /home/thib/.npm/_git-remotes/git-github-com-ornicar-chessground-git-v3-3-2-74389233: fatal: Could not read from remote repository.
42 error git clone --template=/home/thib/.npm/_git-remotes/_templates --mirror [email protected]:ornicar/chessground.git /home/thib/.npm/_git-remotes/git-github-com-ornicar-chessground-git-v3-3-2-74389233:
42 error git clone --template=/home/thib/.npm/_git-remotes/_templates --mirror [email protected]:ornicar/chessground.git /home/thib/.npm/_git-remotes/git-github-com-ornicar-chessground-git-v3-3-2-74389233: Please make sure you have the correct access rights
42 error git clone --template=/home/thib/.npm/_git-remotes/_templates --mirror [email protected]:ornicar/chessground.git /home/thib/.npm/_git-remotes/git-github-com-ornicar-chessground-git-v3-3-2-74389233: and the repository exists.
43 silly fetchPackageMetaData Error: Command failed: git clone --template=/home/thib/.npm/_git-remotes/_templates --mirror [email protected]:ornicar/chessground.git /home/thib/.npm/_git-remotes/git-github-com-ornicar-chessground-git-v3-3-2-74389233
43 silly fetchPackageMetaData Cloning into bare repository '/home/thib/.npm/_git-remotes/git-github-com-ornicar-chessground-git-v3-3-2-74389233'...
43 silly fetchPackageMetaData ssh: Could not resolve hostname github.com: Name or service not known
43 silly fetchPackageMetaData fatal: Could not read from remote repository.
43 silly fetchPackageMetaData
43 silly fetchPackageMetaData Please make sure you have the correct access rights
43 silly fetchPackageMetaData and the repository exists.
43 silly fetchPackageMetaData
43 silly fetchPackageMetaData at ChildProcess.exithandler (child_process.js:213:12)
43 silly fetchPackageMetaData at emitTwo (events.js:87:13)
43 silly fetchPackageMetaData at ChildProcess.emit (events.js:172:7)
43 silly fetchPackageMetaData at maybeClose (internal/child_process.js:818:16)
43 silly fetchPackageMetaData at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
43 silly fetchPackageMetaData error for chessground@github:ornicar/chessground#v3.3.2 { [Error: Command failed: git clone --template=/home/thib/.npm/_git-remotes/_templates --mirror [email protected]:ornicar/chessground.git /home/thib/.npm/_git-remotes/git-github-com-ornicar-chessground-git-v3-3-2-74389233
43 silly fetchPackageMetaData Cloning into bare repository '/home/thib/.npm/_git-remotes/git-github-com-ornicar-chessground-git-v3-3-2-74389233'...
43 silly fetchPackageMetaData ssh: Could not resolve hostname github.com: Name or service not known
43 silly fetchPackageMetaData fatal: Could not read from remote repository.
43 silly fetchPackageMetaData
43 silly fetchPackageMetaData Please make sure you have the correct access rights
43 silly fetchPackageMetaData and the repository exists.
43 silly fetchPackageMetaData ]
43 silly fetchPackageMetaData killed: false,
43 silly fetchPackageMetaData code: 128,
43 silly fetchPackageMetaData signal: null,
43 silly fetchPackageMetaData cmd: 'git clone --template=/home/thib/.npm/_git-remotes/_templates --mirror [email protected]:ornicar/chessground.git /home/thib/.npm/_git-remotes/git-github-com-ornicar-chessground-git-v3-3-2-74389233' }
44 silly rollbackFailedOptional Starting
45 silly rollbackFailedOptional Finishing
46 silly runTopLevelLifecycles Starting
47 silly runTopLevelLifecycles Finishing
48 silly install printInstalled
49 verbose stack Error: Command failed: git clone --template=/home/thib/.npm/_git-remotes/_templates --mirror [email protected]:ornicar/chessground.git /home/thib/.npm/_git-remotes/git-github-com-ornicar-chessground-git-v3-3-2-74389233
49 verbose stack Cloning into bare repository '/home/thib/.npm/_git-remotes/git-github-com-ornicar-chessground-git-v3-3-2-74389233'...
49 verbose stack ssh: Could not resolve hostname github.com: Name or service not known
49 verbose stack fatal: Could not read from remote repository.
49 verbose stack
49 verbose stack Please make sure you have the correct access rights
49 verbose stack and the repository exists.
49 verbose stack
49 verbose stack at ChildProcess.exithandler (child_process.js:213:12)
49 verbose stack at emitTwo (events.js:87:13)
49 verbose stack at ChildProcess.emit (events.js:172:7)
49 verbose stack at maybeClose (internal/child_process.js:818:16)
49 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
50 verbose cwd /home/thib/lila/ui/analyse
51 error Linux 4.0.1-1-ARCH
52 error argv "/usr/bin/node" "/usr/bin/npm" "i"
53 error node v5.3.0
54 error npm v3.5.2
55 error code 128
56 error Command failed: git clone --template=/home/thib/.npm/_git-remotes/_templates --mirror [email protected]:ornicar/chessground.git /home/thib/.npm/_git-remotes/git-github-com-ornicar-chessground-git-v3-3-2-74389233
56 error Cloning into bare repository '/home/thib/.npm/_git-remotes/git-github-com-ornicar-chessground-git-v3-3-2-74389233'...
56 error ssh: Could not resolve hostname github.com: Name or service not known
56 error fatal: Could not read from remote repository.
56 error
56 error Please make sure you have the correct access rights
56 error and the repository exists.
57 error If you need help, you may report this error at:
57 error <https://github.com/npm/npm/issues>
58 verbose exit [ 1, true ]
2 changes: 1 addition & 1 deletion ui/analyse/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"watchify": "~3.1.1"
},
"dependencies": {
"chessground": "github:ornicar/chessground#v3.1.0",
"chessground": "github:ornicar/chessground#v3.3.2",
"game": "file:../game",
"mithril": "github:ornicar/mithril.js#v1.0.0"
}
Expand Down
48 changes: 48 additions & 0 deletions ui/analyse/src/crazy/crazyDrag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
var util = require('chessground').util;
var drag = require('chessground').drag;
var game = require('game').game;

module.exports = function(ctrl, color, e) {
if (e.button !== 0) return; // only left click
if (ctrl.chessground.data.movable.color !== color) return;
var node = e.target.parentNode.parentNode;
var role = node.getAttribute('data-role'),
color = node.getAttribute('data-color');
if (!role || !color) return;
e.stopPropagation();
e.preventDefault();
var key;
for (var i in util.allKeys) {
if (!ctrl.chessground.data.pieces[util.allKeys[i]]) {
key = util.allKeys[i];
break;
}
}
if (!key) return;
var coords = util.key2pos(ctrl.chessground.data.orientation === 'white' ? key : util.invertKey(key));
var piece = {
role: role,
color: color
};
var obj = {};
obj[key] = piece;
ctrl.chessground.setPieces(obj);
var bounds = ctrl.chessground.data.bounds();
var squareBounds = ctrl.vm.element.querySelector('square').getBoundingClientRect();
var rel = [
(coords[0] - 1) * squareBounds.width + bounds.left, (8 - coords[1]) * squareBounds.height + bounds.top
];
ctrl.chessground.data.draggable.current = {
orig: key,
piece: piece.color + piece.role,
rel: rel,
epos: [e.clientX, e.clientY],
pos: [e.clientX - rel[0], e.clientY - rel[1]],
dec: [-squareBounds.width / 2, -squareBounds.height / 2],
bounds: bounds,
started: true,
newPiece: true
};
console.log(ctrl.chessground.data.draggable.current);
drag.processDrag(ctrl.chessground.data);
}
17 changes: 17 additions & 0 deletions ui/analyse/src/crazy/crazyValid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
var game = require('game').game;

module.exports = {

drop: function(chessground, possibleDrops, piece, pos) {

if (piece.color !== chessground.data.movable.color) return false;

if (piece.role === 'pawn' && (pos[1] === '1' || pos[1] === '8')) return false;

if (typeof possibleDrops === 'undefined' || possibleDrops === null) return true;

var drops = possibleDrops.match(/.{2}/g) || [];

return drops.indexOf(pos) !== -1;
}
};
Loading

0 comments on commit 910a4ca

Please sign in to comment.