Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tablebase robustness for practice #4531

Merged
merged 3 commits into from
Aug 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ui/@types/lichess/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ declare namespace Tree {
threat?: ClientEval;
ceval?: ClientEval;
eval?: ServerEval;
tbhit?: TablebaseHit;
tbhit: TablebaseHit | undefined | null;
opening?: Opening;
glyphs?: Glyph[];
clock?: Clock;
Expand Down
25 changes: 10 additions & 15 deletions ui/analyse/src/explorer/explorerCtrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,26 @@ function pieceCount(fen: Fen) {
return parts[0].split(/[nbrqkp]/i).length - 1;
}

export function tablebaseGuaranteed(variant: VariantKey, fen: Fen) {
function tablebasePieces(variant: VariantKey) {
switch (variant) {
case 'standard':
case 'fromPosition':
case 'chess960':
return 7;
case 'atomic':
case 'antichess':
return pieceCount(fen) <= 6;
return 6;
default:
return false;
return 0;
}
}

export function tablebaseGuaranteed(variant: VariantKey, fen: Fen) {
return pieceCount(fen) <= tablebasePieces(variant);
}

function tablebaseRelevant(variant: VariantKey, fen: Fen) {
const count = pieceCount(fen);
switch (variant) {
case 'standard':
case 'fromPosition':
case 'chess960':
return count <= 8;
case 'atomic':
case 'antichess':
return count <= 7;
default:
return false;
}
return pieceCount(fen) - 1 <= tablebasePieces(variant);
}

export default function(root: AnalyseCtrl, opts, allow: boolean): ExplorerCtrl {
Expand Down Expand Up @@ -154,6 +148,7 @@ export default function(root: AnalyseCtrl, opts, allow: boolean): ExplorerCtrl {
fetchTablebaseHit(fen: Fen): JQueryPromise<SimpleTablebaseHit> {
return xhr.tablebase(opts.tablebaseEndpoint, effectiveVariant, fen).then((res: TablebaseData) => {
const move = res.moves[0];
if (move && move.dtz == null) throw 'unknown tablebase position';
return {
fen: fen,
best: move && move.uci,
Expand Down
9 changes: 6 additions & 3 deletions ui/analyse/src/practice/practiceCtrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { detectThreefold } from '../nodeFinder';
import { tablebaseGuaranteed } from '../explorer/explorerCtrl';
import AnalyseCtrl from '../ctrl';
import { Redraw } from '../interfaces';
import { prop, Prop } from 'common';
import { defined, prop, Prop } from 'common';

export interface Comment {
prev: Tree.Node;
Expand Down Expand Up @@ -81,7 +81,7 @@ export function make(root: AnalyseCtrl, playableDepth: () => number): PracticeCt
e8h8: 'e8g8'
};

function tbhitToEval(hit: Tree.TablebaseHit | undefined) {
function tbhitToEval(hit: Tree.TablebaseHit | undefined | null) {
return hit && (
hit.winner ? {
mate: hit.winner === 'white' ? 10 : -10
Expand Down Expand Up @@ -136,7 +136,7 @@ export function make(root: AnalyseCtrl, playableDepth: () => number): PracticeCt
comment(null);
return root.redraw();
}
if (tablebaseGuaranteed(variant, node.fen) && !node.tbhit) return;
if (tablebaseGuaranteed(variant, node.fen) && !defined(node.tbhit)) return;
ensureCevalRunning();
if (isMyTurn()) {
const h = hinting();
Expand Down Expand Up @@ -172,6 +172,9 @@ export function make(root: AnalyseCtrl, playableDepth: () => number): PracticeCt
if (tablebaseGuaranteed(variant, root.node.fen)) root.explorer.fetchTablebaseHit(root.node.fen).then(hit => {
if (hit && root.node.fen === hit.fen) root.node.tbhit = hit;
checkCeval();
}, () => {
if (!defined(root.node.tbhit)) root.node.tbhit = null;
checkCeval();
});
else checkCeval();
}
Expand Down