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

Ply limit alert and prevent premoves in stalemates / insufficient material positions #16679

Closed
wants to merge 10 commits into from
10 changes: 7 additions & 3 deletions ui/analyse/src/ctrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the point of analysis premoves again? Since we can move all pieces.

I suppose it's only useful in specific applications like "learn from your mistakes" where only one side is playable. That would be a better thing to check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ornicar I think the main point is when the connection to the server is poor. E.g., if you open a study board and turn off wifi, the next move should be a premove.

};
this.cgConfig = config;
return config;
Expand Down Expand Up @@ -574,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.');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a weird assumption to make and one that would probably backfire. Can we use the ply number instead?

else if (this.study) this.study.onPremoveSet();
};

addNode(node: Tree.Node, path: Tree.Path) {
Expand Down Expand Up @@ -740,6 +742,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();
}
Expand Down
Loading