Skip to content

Commit

Permalink
Puzzle report: do not check positions with 7 pieces or fewer since th…
Browse files Browse the repository at this point in the history
…e tablebase is better for those
  • Loading branch information
kraktus committed Feb 5, 2025
1 parent 42ada5c commit 3bde370
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
6 changes: 1 addition & 5 deletions ui/analyse/src/explorer/explorerCtrl.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { type Prop, prop, defined } from 'common';
import { storedBooleanProp } from 'common/storage';
import { pieceCount } from 'chess';
import { defer } from 'common/defer';
import { fenColor } from 'common/miniBoard';
import { debounce } from 'common/timing';
Expand All @@ -15,11 +16,6 @@ import { clearLastShow } from './explorerView';

export const MAX_DEPTH = 50;

function pieceCount(fen: FEN) {
const parts = fen.split(/\s/);
return parts[0].split(/[nbrqkp]/i).length - 1;
}

function tablebasePieces(variant: VariantKey) {
switch (variant) {
case 'standard':
Expand Down
2 changes: 2 additions & 0 deletions ui/chess/src/chess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ export const readDrops = (line?: string | null): Key[] | null =>
export const fenToEpd = (fen: FEN): string => fen.split(' ').slice(0, 4).join(' ');

export const plyToTurn = (ply: number): number => Math.floor((ply - 1) / 2) + 1;

export const pieceCount = (fen: FEN): number => fen.split(/\s/)[0].split(/[nbrqkp]/i).length - 1;
11 changes: 7 additions & 4 deletions ui/puzzle/src/report.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { report as xhrReport } from './xhr';
import type PuzzleCtrl from './ctrl';
import { pieceCount } from 'chess';
import type { PuzzleId, ThemeKey } from './interfaces';
import { winningChances } from 'ceval';
import * as licon from 'common/licon';
Expand All @@ -8,7 +9,7 @@ import { domDialog } from 'common/dialog';
import { plyToTurn } from 'chess';

Check failure on line 9 in ui/puzzle/src/report.ts

View workflow job for this annotation

GitHub Actions / lint

'chess' import is duplicated

// bump when logic is changed, to distinguish cached clients from new ones
const version = 9;
const version = 10;

export default class Report {
// if local eval suspect multiple solutions, report the puzzle, once at most
Expand Down Expand Up @@ -38,10 +39,12 @@ export default class Report {
threatMode ||
// the `mate` key theme is not sent, as it is considered redubant with `mateInX`
ctrl.data.puzzle.themes.some((t: ThemeKey) => t.toLowerCase().includes('mate')) ||
// if the user has chosen to hide the dialog less than a week ago
this.tsHideReportDialog() > Date.now() - 1000 * 3600 * 24 * 7 ||
// positions with 7 pieces or less can be checked with the tablebase
pieceCount(ev.fen) <= 7 ||
// dynamic import from web worker feature is shared by all stockfish 16+ WASMs
!ctrl.ceval.engines.active?.requires?.includes('dynamicImportFromWorker')
!ctrl.ceval.engines.active?.requires?.includes('dynamicImportFromWorker') ||
// if the user has chosen to hide the dialog less than a week ago
this.tsHideReportDialog() > Date.now() - 1000 * 3600 * 24 * 7
)
return;
const node = ctrl.node;
Expand Down

0 comments on commit 3bde370

Please sign in to comment.