remove ui/puzzle and ui/ceval dependency on ui/chess
parent
92a1d0cc9f
commit
d47ca0f1bf
|
@ -25,7 +25,7 @@
|
|||
"chat": "2.0.0",
|
||||
"chess": "2.0.0",
|
||||
"chessground": "^7.6",
|
||||
"chessops": "^0.4.0",
|
||||
"chessops": "^0.4.1",
|
||||
"common": "2.0.0",
|
||||
"game": "2.0.0",
|
||||
"nvui": "2.0.0",
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { opposite } from 'chessground/util';
|
||||
import { variantToRules } from 'chess';
|
||||
import { lichessVariantRules } from 'chessops/compat';
|
||||
import { Position, PositionError } from 'chessops/chess';
|
||||
import { parseFen } from 'chessops/fen';
|
||||
import { Result } from '@badrap/result';
|
||||
|
@ -619,7 +619,7 @@ export default class AnalyseCtrl {
|
|||
|
||||
position(node: Tree.Node): Result<Position, PositionError> {
|
||||
const setup = parseFen(node.fen).unwrap();
|
||||
return setupPosition(variantToRules(this.data.game.variant.key), setup);
|
||||
return setupPosition(lichessVariantRules(this.data.game.variant.key), setup);
|
||||
}
|
||||
|
||||
canUseCeval(): boolean {
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import { h } from 'snabbdom'
|
||||
import { VNode } from 'snabbdom/vnode'
|
||||
import { fixCrazySan, renderEval as normalizeEval } from 'chess';
|
||||
import { fixCrazySan } from 'chess';
|
||||
import { defined } from 'common';
|
||||
import { view as cevalView } from 'ceval';
|
||||
import { view as cevalView, renderEval as normalizeEval } from 'ceval';
|
||||
|
||||
export interface Ctx {
|
||||
withDots?: boolean;
|
||||
|
|
|
@ -23,8 +23,7 @@
|
|||
"typescript": "^3"
|
||||
},
|
||||
"dependencies": {
|
||||
"chess": "2.0.0",
|
||||
"chessops": "^0.4.0",
|
||||
"chessops": "^0.4.1",
|
||||
"common": "2.0.0",
|
||||
"snabbdom": "ornicar/snabbdom#0.7.1-lichess"
|
||||
}
|
||||
|
|
|
@ -3,13 +3,9 @@ import * as view from './view';
|
|||
import * as winningChances from './winningChances';
|
||||
|
||||
export { CevalCtrl, NodeEvals, Eval, Work, CevalOpts } from './types';
|
||||
|
||||
export { isEvalBetter, renderEval } from './util';
|
||||
export { ctrl, view, winningChances };
|
||||
|
||||
export function isEvalBetter(a: Tree.ClientEval, b?: Tree.ClientEval): boolean {
|
||||
return !b || a.depth > b.depth || (a.depth === b.depth && a.nodes > b.nodes);
|
||||
}
|
||||
|
||||
// stop when another tab starts. Listen only once here,
|
||||
// as the ctrl can be instanciated several times.
|
||||
// gotta do the click on the toggle to have it visually change.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { variantToRules } from 'chess';
|
||||
import { lichessVariantRules } from 'chessops/compat';
|
||||
import { WorkerOpts, Work } from './types';
|
||||
|
||||
const EVAL_REGEX = new RegExp(''
|
||||
|
@ -34,7 +34,7 @@ export default class Protocol {
|
|||
else if (this.opts.variant === 'antichess')
|
||||
this.setOption('UCI_Variant', 'giveaway');
|
||||
else if (this.opts.variant !== 'standard')
|
||||
this.setOption('UCI_Variant', variantToRules(this.opts.variant));
|
||||
this.setOption('UCI_Variant', lichessVariantRules(this.opts.variant));
|
||||
}
|
||||
|
||||
private setOption(name: string, value: string | number) {
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
export function isEvalBetter(a: Tree.ClientEval, b?: Tree.ClientEval): boolean {
|
||||
return !b || a.depth > b.depth || (a.depth === b.depth && a.nodes > b.nodes);
|
||||
}
|
||||
|
||||
export function renderEval(e: number): string {
|
||||
e = Math.max(Math.min(Math.round(e / 10) / 10, 99), -99);
|
||||
return (e > 0 ? '+' : '') + e.toFixed(1);
|
||||
}
|
|
@ -1,10 +1,11 @@
|
|||
import { Eval, CevalCtrl, ParentCtrl, NodeEvals } from './types';
|
||||
import { renderEval } from './util';
|
||||
import * as winningChances from './winningChances';
|
||||
import { defined } from 'common';
|
||||
import { renderEval, variantToRules } from 'chess';
|
||||
import { h } from 'snabbdom'
|
||||
import { VNode } from 'snabbdom/vnode'
|
||||
import { opposite, parseUci } from 'chessops/util';
|
||||
import { lichessVariantRules } from 'chessops/compat';
|
||||
import { parseFen } from 'chessops/fen';
|
||||
import { makeSanVariation } from 'chessops/san';
|
||||
import { setupPosition } from 'chessops/variant';
|
||||
|
@ -227,7 +228,7 @@ export function renderPvs(ctrl: ParentCtrl) {
|
|||
} else if (node.ceval) pvs = node.ceval.pvs;
|
||||
else pvs = [];
|
||||
if (threat) setup.turn = opposite(setup.turn);
|
||||
const pos = setupPosition(variantToRules(instance.variant.key), setup);
|
||||
const pos = setupPosition(lichessVariantRules(instance.variant.key), setup);
|
||||
return h('div.pv_box', {
|
||||
attrs: { 'data-fen': node.fen },
|
||||
hook: {
|
||||
|
|
|
@ -10,11 +10,6 @@ export function decomposeUci(uci: Uci): [Key, Key, string] {
|
|||
return [uci.slice(0, 2) as Key, uci.slice(2, 4) as Key, uci.slice(4, 5)];
|
||||
}
|
||||
|
||||
export function renderEval(e: number): string {
|
||||
e = Math.max(Math.min(Math.round(e / 10) / 10, 99), -99);
|
||||
return (e > 0 ? '+' : '') + e.toFixed(1);
|
||||
}
|
||||
|
||||
export interface Dests {
|
||||
[square: string]: Key[];
|
||||
}
|
||||
|
@ -57,20 +52,3 @@ export const altCastles = {
|
|||
e8a8: 'e8c8',
|
||||
e8h8: 'e8g8'
|
||||
};
|
||||
|
||||
export function variantToRules(variant: VariantKey): 'chess' | 'antichess' | 'kingofthehill' | '3check' | 'atomic' | 'horde' | 'racingkings' | 'crazyhouse' {
|
||||
switch (variant) {
|
||||
case 'standard':
|
||||
case 'chess960':
|
||||
case 'fromPosition':
|
||||
return 'chess';
|
||||
case 'threeCheck':
|
||||
return '3check';
|
||||
case 'kingOfTheHill':
|
||||
return 'kingofthehill';
|
||||
case 'racingKings':
|
||||
return 'racingkings';
|
||||
default:
|
||||
return variant;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"chessground": "^7.6",
|
||||
"chessops": "^0.4.0",
|
||||
"chessops": "^0.4.1",
|
||||
"snabbdom": "ornicar/snabbdom#0.7.1-lichess",
|
||||
"common": "2.0.0"
|
||||
}
|
||||
|
|
|
@ -19,9 +19,8 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"ceval": "2.0.0",
|
||||
"chess": "2.0.0",
|
||||
"chessground": "^7.6",
|
||||
"chessops": "^0.4.0",
|
||||
"chessops": "^0.4.1",
|
||||
"common": "2.0.0",
|
||||
"snabbdom": "ornicar/snabbdom#0.7.1-lichess",
|
||||
"tree": "2.0.0"
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
import { winningChances } from 'ceval';
|
||||
import { decomposeUci } from 'chess';
|
||||
import { DrawShape } from 'chessground/draw';
|
||||
import { Vm } from './interfaces';
|
||||
import { Api as CgApi } from 'chessground/api';
|
||||
|
@ -15,10 +14,9 @@ interface Opts {
|
|||
}
|
||||
|
||||
function makeAutoShapesFromUci(uci: Uci, brush: string, modifiers?: any): DrawShape[] {
|
||||
const move = decomposeUci(uci);
|
||||
return [{
|
||||
orig: move[0],
|
||||
dest: move[1],
|
||||
orig: uci.slice(0, 2) as Key,
|
||||
dest: uci.slice(2, 4) as Key,
|
||||
brush: brush,
|
||||
modifiers: modifiers
|
||||
}];
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import { build as treeBuild, ops as treeOps, path as treePath, TreeWrapper } from 'tree';
|
||||
import { ctrl as cevalCtrl, CevalCtrl } from 'ceval';
|
||||
import { decomposeUci, sanToRole } from 'chess';
|
||||
import keyboard from './keyboard';
|
||||
import moveTestBuild from './moveTest';
|
||||
import mergeSolution from './solution';
|
||||
|
@ -12,14 +11,14 @@ import throttle from 'common/throttle';
|
|||
import * as xhr from './xhr';
|
||||
import * as speech from './speech';
|
||||
import { sound } from './sound';
|
||||
import { parseSquare, makeSquare, makeUci } from 'chessops/util';
|
||||
import { Role, Move } from 'chessops/types';
|
||||
import { parseSquare, parseUci, makeSquare, makeUci } from 'chessops/util';
|
||||
import { parseFen, makeFen } from 'chessops/fen';
|
||||
import { makeSanAndPlay } from 'chessops/san';
|
||||
import { Chess } from 'chessops/chess';
|
||||
import { chessgroundDests, scalachessId } from 'chessops/compat';
|
||||
import { Config as CgConfig } from 'chessground/config';
|
||||
import { Api as CgApi } from 'chessground/api';
|
||||
import * as cg from 'chessground/types';
|
||||
import { Redraw, Vm, Controller, PuzzleOpts, PuzzleData, PuzzleRound, PuzzleVote, MoveTest } from './interfaces';
|
||||
|
||||
export default function(opts: PuzzleOpts, redraw: Redraw): Controller {
|
||||
|
@ -129,19 +128,27 @@ export default function(opts: PuzzleOpts, redraw: Redraw): Controller {
|
|||
|
||||
function userMove(orig: Key, dest: Key): void {
|
||||
vm.justPlayed = orig;
|
||||
if (!promotion.start(orig, dest, sendMove)) sendMove(orig, dest);
|
||||
if (!promotion.start(orig, dest, playUserMove)) playUserMove(orig, dest);
|
||||
}
|
||||
|
||||
function sendMove(orig: Key, dest: Key, promotion?: cg.Role): void {
|
||||
sendMoveAt(vm.path, position(), orig, dest, promotion);
|
||||
function playUci(uci: Uci): void {
|
||||
sendMove(parseUci(uci)!);
|
||||
}
|
||||
|
||||
function sendMoveAt(path: Tree.Path, pos: Chess, orig: Key, dest: Key, promotion?: cg.Role): void {
|
||||
const move = pos.normalizeMove({
|
||||
function playUserMove(orig: Key, dest: Key, promotion?: Role): void {
|
||||
sendMove({
|
||||
from: parseSquare(orig)!,
|
||||
to: parseSquare(dest)!,
|
||||
promotion,
|
||||
});
|
||||
}
|
||||
|
||||
function sendMove(move: Move): void {
|
||||
sendMoveAt(vm.path, position(), move);
|
||||
}
|
||||
|
||||
function sendMoveAt(path: Tree.Path, pos: Chess, move: Move): void {
|
||||
move = pos.normalizeMove(move);
|
||||
const san = makeSanAndPlay(pos, move);
|
||||
const check = pos.isCheck() ? pos.board.kingOf(pos.turn) : undefined;
|
||||
addNode({
|
||||
|
@ -218,7 +225,7 @@ export default function(opts: PuzzleOpts, redraw: Redraw): Controller {
|
|||
vm.lastFeedback = 'good';
|
||||
setTimeout(() => {
|
||||
const pos = Chess.fromSetup(parseFen(progress.fen).unwrap()).unwrap();
|
||||
sendMoveAt(progress.path, pos, progress.orig, progress.dest, progress.promotion);
|
||||
sendMoveAt(progress.path, pos, progress.move);
|
||||
}, 500);
|
||||
}
|
||||
}
|
||||
|
@ -308,12 +315,6 @@ export default function(opts: PuzzleOpts, redraw: Redraw): Controller {
|
|||
});
|
||||
}
|
||||
|
||||
function playUci(uci: string): void {
|
||||
const move = decomposeUci(uci);
|
||||
if (!move[2]) sendMove(move[0], move[1])
|
||||
else sendMove(move[0], move[1], sanToRole[move[2].toUpperCase()]);
|
||||
}
|
||||
|
||||
function getCeval() {
|
||||
return ceval;
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ import { TreeWrapper } from 'tree';
|
|||
import { VNode } from 'snabbdom/vnode'
|
||||
import { Api as CgApi } from 'chessground/api';
|
||||
import { Config as CgConfig } from 'chessground/config';
|
||||
import { Role } from 'chessground/types';
|
||||
import { Role, Move } from 'chessops/types';
|
||||
|
||||
export type MaybeVNode = VNode | string | null | undefined;
|
||||
export type MaybeVNodes = MaybeVNode[];
|
||||
|
@ -142,9 +142,7 @@ export interface Promotion {
|
|||
export type Lines = { [uci: string]: Lines } | 'fail' | 'win';
|
||||
|
||||
export interface MoveTest {
|
||||
orig: Key;
|
||||
dest: Key;
|
||||
promotion?: Role;
|
||||
move: Move,
|
||||
fen: Fen;
|
||||
path: Tree.Path;
|
||||
}
|
||||
|
|
|
@ -1,26 +1,31 @@
|
|||
import { path as pathOps } from 'tree';
|
||||
import { decomposeUci, sanToRole, altCastles } from 'chess';
|
||||
import { parseUci } from 'chessops/util';
|
||||
import { Vm, Puzzle, MoveTest } from './interfaces';
|
||||
|
||||
const altCastles = {
|
||||
e1a1: 'e1c1',
|
||||
e1h1: 'e1g1',
|
||||
e8a8: 'e8c8',
|
||||
e8h8: 'e8g8'
|
||||
};
|
||||
|
||||
export default function(vm: Vm, puzzle: Puzzle): () => undefined | 'fail' | 'win' | MoveTest {
|
||||
|
||||
return function(): undefined | 'fail' | 'win' | MoveTest {
|
||||
|
||||
if (vm.mode === 'view') return;
|
||||
if (!pathOps.contains(vm.path, vm.initialPath)) return;
|
||||
|
||||
var playedByColor = vm.node.ply % 2 === 1 ? 'white' : 'black';
|
||||
const playedByColor = vm.node.ply % 2 === 1 ? 'white' : 'black';
|
||||
if (playedByColor !== puzzle.color) return;
|
||||
|
||||
var nodes = vm.nodeList.slice(pathOps.size(vm.initialPath) + 1).map(function(node) {
|
||||
const nodes = vm.nodeList.slice(pathOps.size(vm.initialPath) + 1).map(function(node) {
|
||||
return {
|
||||
uci: node.uci,
|
||||
castle: node.san!.startsWith('O-O')
|
||||
};
|
||||
});
|
||||
|
||||
var progress = puzzle.lines;
|
||||
for (var i in nodes) {
|
||||
let progress = puzzle.lines;
|
||||
for (let i in nodes) {
|
||||
if (progress[nodes[i].uci!]) progress = progress[nodes[i].uci!];
|
||||
else if (nodes[i].castle) progress = progress[altCastles[nodes[i].uci!]] || 'fail';
|
||||
else progress = 'fail';
|
||||
|
@ -32,26 +37,18 @@ export default function(vm: Vm, puzzle: Puzzle): () => undefined | 'fail' | 'win
|
|||
}
|
||||
|
||||
var nextKey = Object.keys(progress)[0]
|
||||
if (progress[nextKey] === 'win') {
|
||||
vm.node.puzzle = 'win';
|
||||
return 'win';
|
||||
}
|
||||
if (progress[nextKey] === 'win') {
|
||||
vm.node.puzzle = 'win';
|
||||
return 'win';
|
||||
}
|
||||
|
||||
// from here we have a next move
|
||||
// from here we have a next move
|
||||
vm.node.puzzle = 'good';
|
||||
|
||||
vm.node.puzzle = 'good';
|
||||
|
||||
var opponentUci = decomposeUci(nextKey);
|
||||
var promotion = opponentUci[2] ? sanToRole[opponentUci[2].toUpperCase()] : null;
|
||||
|
||||
const move: MoveTest = {
|
||||
orig: opponentUci[0],
|
||||
dest: opponentUci[1],
|
||||
return {
|
||||
move: parseUci(nextKey)!,
|
||||
fen: vm.node.fen,
|
||||
path: vm.path
|
||||
};
|
||||
if (promotion) move.promotion = promotion;
|
||||
|
||||
return move;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ import { h } from 'snabbdom'
|
|||
import { VNode } from 'snabbdom/vnode'
|
||||
import { defined } from 'common';
|
||||
import throttle from 'common/throttle';
|
||||
import { renderEval as normalizeEval } from 'chess';
|
||||
import { renderEval as normalizeEval } from 'ceval';
|
||||
import { path as treePath } from 'tree';
|
||||
import { Controller, MaybeVNode, MaybeVNodes } from '../interfaces';
|
||||
|
||||
|
|
|
@ -804,10 +804,10 @@ chessground@^7.6:
|
|||
resolved "https://registry.yarnpkg.com/chessground/-/chessground-7.6.12.tgz#f2ee79eca4baf15aa6061c912bab6cd7b7b1ae7b"
|
||||
integrity sha512-23Esfh6wxiyPkkC2cFfzOrU1zABXJPofPAUpu2lFGsTCiVwgNNXlC76G7FoDdA3OBi4Mud5wATzikkyLrCQssQ==
|
||||
|
||||
chessops@^0.4.0:
|
||||
version "0.4.0"
|
||||
resolved "https://registry.yarnpkg.com/chessops/-/chessops-0.4.0.tgz#13019b60e098a84c7f5e0d4e5922ca939c6dc13c"
|
||||
integrity sha512-jMtOOQvytmnm4HNp3To06c4TSYUgfkmj1H+7MziNG4VnnSWF3S5/hgHjx70nkC7Ym0/QYq8zGNwNy2mOvWxOzA==
|
||||
chessops@^0.4.1:
|
||||
version "0.4.1"
|
||||
resolved "https://registry.yarnpkg.com/chessops/-/chessops-0.4.1.tgz#1afa2f513203623c7f483602d1f7e7dac3ce0ef6"
|
||||
integrity sha512-ck84Ar9G497X8mff6PmYPM3q/nXFvmjBUr537dOV9VtY7jqvYtKKJx8us05D+T4kzTLc6sJ0xroWYyTRs9A57A==
|
||||
dependencies:
|
||||
"@badrap/result" "^0.2.6"
|
||||
|
||||
|
|
Loading…
Reference in New Issue