From 7165c3a6a8a6a6dc35229212e8cb451d97864d0c Mon Sep 17 00:00:00 2001 From: johndoknjas Date: Fri, 27 Dec 2024 09:02:55 -0800 Subject: [PATCH 1/6] Alert the user when no more moves allowed in a chapter. --- ui/analyse/src/study/studyCtrl.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ui/analyse/src/study/studyCtrl.ts b/ui/analyse/src/study/studyCtrl.ts index dd815038cd49d..51933f92576fa 100644 --- a/ui/analyse/src/study/studyCtrl.ts +++ b/ui/analyse/src/study/studyCtrl.ts @@ -582,7 +582,11 @@ export default class StudyCtrl { }; explorerGame = (gameId: string, insert: boolean) => this.makeChange('explorerGame', this.withPosition({ gameId, insert })); - onPremoveSet = () => this.gamebookPlay?.onPremoveSet(); + onPremoveSet = () => { + if (this.currentNode().dests === '') + alert("No more moves allowed - either the game is over, or you've reached the chapter move limit."); + else this.gamebookPlay?.onPremoveSet(); + }; baseUrl = () => { const current = location.href; const studyIdOffset = current.indexOf(`/${this.data.id}`); From 985511a4906200ddb33199f28c7cbf2bcdbb90c1 Mon Sep 17 00:00:00 2001 From: johndoknjas Date: Fri, 27 Dec 2024 19:31:30 -0800 Subject: [PATCH 2/6] Have different alerts depending on the reason for no more moves. --- ui/analyse/src/study/studyCtrl.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ui/analyse/src/study/studyCtrl.ts b/ui/analyse/src/study/studyCtrl.ts index bef1a6aef4f3c..4ec0223484a8b 100644 --- a/ui/analyse/src/study/studyCtrl.ts +++ b/ui/analyse/src/study/studyCtrl.ts @@ -592,9 +592,14 @@ export default class StudyCtrl { explorerGame = (gameId: string, insert: boolean) => this.makeChange('explorerGame', this.withPosition({ gameId, insert })); onPremoveSet = () => { - if (this.currentNode().dests === '') - alert("No more moves allowed - either the game is over, or you've reached the chapter move limit."); - else this.gamebookPlay?.onPremoveSet(); + if (this.currentNode().dests !== '') { + this.gamebookPlay?.onPremoveSet(); + return; + } + const pos = this.ctrl.position(this.currentNode()).unwrap(); + if (pos.isStalemate()) alert('Stalemate - no more moves allowed.'); + else if (pos.isInsufficientMaterial()) alert('Insufficient mating material - no more moves allowed.'); + else alert("You've reached the ply limit for this chapter."); }; baseUrl = () => { const current = location.href; From 463a8503cadd213bf395ab6ae57dab4a6e34e2bf Mon Sep 17 00:00:00 2001 From: johndoknjas Date: Sat, 28 Dec 2024 21:36:45 -0800 Subject: [PATCH 3/6] Do not allow the user to make premoves when the game is over. --- ui/analyse/src/ctrl.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ui/analyse/src/ctrl.ts b/ui/analyse/src/ctrl.ts index bd791711b24b5..9b38a584a7971 100644 --- a/ui/analyse/src/ctrl.ts +++ b/ui/analyse/src/ctrl.ts @@ -353,7 +353,8 @@ export default class AnalyseCtrl { config.movable!.color = color; } config.premovable = { - enabled: config.movable!.color && config.turnColor !== config.movable!.color, + enabled: + config.movable!.color && config.turnColor !== config.movable!.color && !this.currPosition().isEnd(), }; this.cgConfig = config; return config; @@ -740,6 +741,8 @@ export default class AnalyseCtrl { return setupPosition(lichessRules(this.data.game.variant.key), setup); } + currPosition = () => this.position(this.node).unwrap(); + canUseCeval(): boolean { return !this.node.threefold && !this.outcome(); } From ce815f8ec39f24fd68afb69fa4cd3db8df00cec6 Mon Sep 17 00:00:00 2001 From: johndoknjas Date: Sat, 28 Dec 2024 21:44:19 -0800 Subject: [PATCH 4/6] Update code to no longer handle stalemate and insufficient material cases, since now prevented entirely. --- ui/analyse/src/study/studyCtrl.ts | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/ui/analyse/src/study/studyCtrl.ts b/ui/analyse/src/study/studyCtrl.ts index 398ce79c7e3a8..7f4131989a86e 100644 --- a/ui/analyse/src/study/studyCtrl.ts +++ b/ui/analyse/src/study/studyCtrl.ts @@ -595,14 +595,8 @@ export default class StudyCtrl { explorerGame = (gameId: string, insert: boolean) => this.makeChange('explorerGame', this.withPosition({ gameId, insert })); onPremoveSet = () => { - if (this.currentNode().dests !== '') { - this.gamebookPlay?.onPremoveSet(); - return; - } - const pos = this.ctrl.position(this.currentNode()).unwrap(); - if (pos.isStalemate()) alert('Stalemate - no more moves allowed.'); - else if (pos.isInsufficientMaterial()) alert('Insufficient mating material - no more moves allowed.'); - else alert("You've reached the ply limit for this chapter."); + if (this.currentNode().dests === '') alert('Too many moves for a lichess board.'); + else this.gamebookPlay?.onPremoveSet(); }; baseUrl = () => { const current = location.href; From 86fe0a66142fbe27e96df9c40a88e8feac7571e1 Mon Sep 17 00:00:00 2001 From: johndoknjas Date: Sat, 28 Dec 2024 22:52:21 -0800 Subject: [PATCH 5/6] Give the ply limit alert on all types of analysis boards, not just study ones. --- ui/analyse/src/ctrl.ts | 3 ++- ui/analyse/src/study/studyCtrl.ts | 5 +---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/ui/analyse/src/ctrl.ts b/ui/analyse/src/ctrl.ts index 9b38a584a7971..3cb0f2ca7a1a3 100644 --- a/ui/analyse/src/ctrl.ts +++ b/ui/analyse/src/ctrl.ts @@ -575,7 +575,8 @@ export default class AnalyseCtrl { } onPremoveSet = () => { - if (this.study) this.study.onPremoveSet(); + if (this.node.dests === '') alert('Too many moves for a lichess board.'); + else if (this.study) this.study.onPremoveSet(); }; addNode(node: Tree.Node, path: Tree.Path) { diff --git a/ui/analyse/src/study/studyCtrl.ts b/ui/analyse/src/study/studyCtrl.ts index 7f4131989a86e..7a728e42d766f 100644 --- a/ui/analyse/src/study/studyCtrl.ts +++ b/ui/analyse/src/study/studyCtrl.ts @@ -594,10 +594,7 @@ export default class StudyCtrl { }; explorerGame = (gameId: string, insert: boolean) => this.makeChange('explorerGame', this.withPosition({ gameId, insert })); - onPremoveSet = () => { - if (this.currentNode().dests === '') alert('Too many moves for a lichess board.'); - else this.gamebookPlay?.onPremoveSet(); - }; + onPremoveSet = () => this.gamebookPlay?.onPremoveSet(); baseUrl = () => { const current = location.href; const studyIdOffset = current.indexOf(`/${this.data.id}`); From 48778965cd4dbfddd760e7e73fdae033a30a026b Mon Sep 17 00:00:00 2001 From: johndoknjas Date: Sat, 28 Dec 2024 23:03:31 -0800 Subject: [PATCH 6/6] Use the lichess custom alert. --- ui/analyse/src/ctrl.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/analyse/src/ctrl.ts b/ui/analyse/src/ctrl.ts index 3cb0f2ca7a1a3..3bf2b2ee4ed36 100644 --- a/ui/analyse/src/ctrl.ts +++ b/ui/analyse/src/ctrl.ts @@ -45,7 +45,7 @@ import ForecastCtrl from './forecast/forecastCtrl'; import { type ArrowKey, type KeyboardMove, ctrl as makeKeyboardMove } from 'keyboardMove'; import * as control from './control'; import type { PgnError } from 'chessops/pgn'; -import { confirm } from 'common/dialog'; +import { confirm, alert } from 'common/dialog'; import api from './api'; export default class AnalyseCtrl {