Skip to content

Commit

Permalink
Merge branch 'master' of github.com:lichess-org/lila
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Feb 5, 2025
2 parents d0a6f0a + 3be42dc commit ab00e25
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 16 deletions.
2 changes: 1 addition & 1 deletion translation/source/study.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
<string name="automatic">Automatic</string>
<plurals name="pasteYourPgnTextHereUpToNbGames">
<item quantity="one">Paste your PGN text here, up to %s game</item>
<item quantity="other">Paste your PGN text here, up to %s games</item>
<item quantity="other">Paste your PGN text here. Each game is a new chapter. The study can have up to %s chapters</item>
</plurals>
<string name="urlOfTheGame">URL of the games, one per line</string>
<string name="loadAGameFromXOrY">Load games from %1$s or %2$s</string>
Expand Down
2 changes: 1 addition & 1 deletion ui/@types/lichess/i18n.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4827,7 +4827,7 @@ interface I18n {
open: string;
/** Orientation */
orientation: string;
/** Paste your PGN text here, up to %s games */
/** Paste your PGN text here. Each game is a new chapter. The study can have up to %s chapters */
pasteYourPgnTextHereUpToNbGames: I18nPlural;
/** %s per page */
perPage: I18nFormat;
Expand Down
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: 1 addition & 1 deletion ui/analyse/src/study/chapterNewForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const fieldValue = (e: Event, id: string) =>
((e.target as HTMLElement).querySelector('#chapter-' + id) as HTMLInputElement)?.value;

export class StudyChapterNewForm {
readonly multiPgnMax = 32;
readonly multiPgnMax = 64;
variants: Variant[] = [];
isOpen = toggle(false);
initial = toggle(false);
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;
17 changes: 10 additions & 7 deletions ui/puzzle/src/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import { winningChances } from 'ceval';
import * as licon from 'common/licon';
import { type StoredProp, storedIntProp } from 'common/storage';
import { domDialog } from 'common/dialog';
import { plyToTurn } from 'chess';
import { plyToTurn, pieceCount } from 'chess';

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

export default class Report {
// if local eval suspect multiple solutions, report the puzzle, once at most
Expand All @@ -15,8 +18,6 @@ export default class Report {
// number of evals that have triggered the `winningChances.hasMultipleSolutions` method
// this is used to reduce the number of fps due to fluke eval
private evalsWithMultipleSolutions = 0;
// bump when logic is changed, to distinguish cached clients from new ones
private version = 9;

constructor() {
this.tsHideReportDialog = storedIntProp('puzzle.report.hide.ts', 0);
Expand All @@ -37,10 +38,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 Expand Up @@ -68,7 +71,7 @@ export default class Report {
this.reported = true;
const engine = ctrl.ceval.engines.active;
const engineName = engine?.short || engine.name;
const reason = `(v${this.version}, ${engineName}) after move ${plyToTurn(node.ply)}. ${node.san}, at depth ${ev.depth}, multiple solutions:\n\n${ev.pvs.map(pv => `${pvEvalToStr(pv)}: ${pv.moves.join(' ')}`).join('\n\n')}`;
const reason = `(v${version}, ${engineName}) after move ${plyToTurn(node.ply)}. ${node.san}, at depth ${ev.depth}, multiple solutions:\n\n${ev.pvs.map(pv => `${pvEvalToStr(pv)}: ${pv.moves.join(' ')}`).join('\n\n')}`;
this.reportDialog(ctrl.data.puzzle.id, reason);
}
}
Expand Down
5 changes: 4 additions & 1 deletion ui/puzzle/src/xhr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,13 @@ export const voteTheme = (puzzleId: string, theme: ThemeKey, vote: boolean | und
body: defined(vote) ? xhrForm({ vote }) : undefined,
});

// should be kept in sync with `PuzzleForm.report` in scala
const maxReportLength = 2000;

export const report = (puzzleId: string, reason: string): Promise<void> =>
xhrJson(`/training/${puzzleId}/report`, {
method: 'POST',
body: xhrForm({ reason: reason }),
body: xhrForm({ reason: reason.slice(0, maxReportLength) }),
});

export const setZen = throttlePromiseDelay(
Expand Down

0 comments on commit ab00e25

Please sign in to comment.