Skip to content

Comments

Computer from position#2591

Merged
veloce merged 3 commits intomainfrom
computer_from_position
Jan 30, 2026
Merged

Computer from position#2591
veloce merged 3 commits intomainfrom
computer_from_position

Conversation

@veloce
Copy link
Contributor

@veloce veloce commented Jan 30, 2026

Allow to start an offline computer game from any position.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR allows starting an offline computer game from an arbitrary position (via FEN), including from the analysis screen, and updates the new game dialog UX (side picker + mini-board preview) and controller logic to honor custom starting positions.

Changes:

  • Extend OfflineComputerGameScreen and OfflineComputerGameController to accept an optional initialFen, initialize the game from that position, and correctly decide whether the engine or player moves first based on the FEN turn.
  • Update the new game dialog UI to use an adaptive side picker and, when a custom FEN is provided, to show a mini StaticChessboard preview oriented to the chosen side.
  • Add an action in the analysis bottom sheet to “continue from here” into an offline computer game, and add comprehensive widget tests covering custom-start-position behavior and the new side picker helper.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
lib/src/view/offline_computer/offline_computer_game_screen.dart Adds initialFen support, shows the new game dialog immediately for custom positions, displays a mini preview board, switches side selection to a picker button, and forwards initialFen into game startup.
lib/src/model/offline_computer/offline_computer_game_controller.dart Extends startNewGame/OfflineComputerGameState.initial to accept initialFen, initialize the Chess position and GameMeta (variant, initial FEN) from it, and trigger engine moves based on whose turn it actually is.
lib/src/view/analysis/analysis_screen.dart Imports OfflineComputerGameScreen and adds a bottom sheet action that launches a computer game from the current analysis FEN.
test/view/offline_computer/offline_computer_game_screen_test.dart Refactors side selection in tests via a selectSide helper, and adds tests for mini-board visibility, game state from custom FENs, engine vs. player first-move logic, and variant/initial FEN metadata.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

),
if (analysisState.isComputerAnalysisAllowed)
BottomSheetAction(
makeLabel: (context) => const Text('Continue from here'),
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

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

This new bottom sheet action label is hard-coded as an English string instead of using the localized strings (e.g. context.l10n), whereas the neighboring actions like boardEditor and studyShareAndExport are localized. To keep the UI consistent and translatable, please replace this const Text('Continue from here') with a localized string from the existing l10n resources (or add one if needed).

Copilot uses AI. Check for mistakes.
Comment on lines +1134 to +1136
await tester.tap(find.text('White'));
case Side.black:
await tester.tap(find.text('Black'));
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

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

The switch (side) statement here has no break, return, or continue between the cases, so when side is Side.white the code will also execute the Side.black branch, tapping both options in the picker. This will either fail to compile (because Dart disallows fall-through between non-empty cases) or, if adjusted to compile, will end up selecting Black when White was requested; please add the appropriate control-flow (break/return) so only the intended side is tapped.

Suggested change
await tester.tap(find.text('White'));
case Side.black:
await tester.tap(find.text('Black'));
await tester.tap(find.text('White'));
break;
case Side.black:
await tester.tap(find.text('Black'));
break;

Copilot uses AI. Check for mistakes.
@veloce veloce merged commit 2c99802 into main Jan 30, 2026
1 check passed
@veloce veloce deleted the computer_from_position branch January 30, 2026 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant