Skip to content

Commit

Permalink
Merge pull request #604 from HaonRekcef/parse-pgn-without-moves
Browse files Browse the repository at this point in the history
  • Loading branch information
veloce authored Mar 20, 2024
2 parents a7547e1 + c819be6 commit c1ca21c
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/src/view/analysis/analysis_position_choice_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,19 @@ class _BodyState extends State<_Body> {
final initialPosition = PgnGame.startingPosition(game.headers);
final rule = Rule.fromPgn(game.headers['Variant']);

// require at least 1 valid move
if (game.moves.mainline().isEmpty) return null;
final move = initialPosition.parseSan(game.moves.mainline().first.san);
if (move == null) return null;
final mainlineMoves = game.moves.mainline();
//if there is a first move, require it to be valid, otherwise require a FEN
if ((mainlineMoves.isNotEmpty &&
(initialPosition.parseSan(mainlineMoves.first.san) == null)) ||
(mainlineMoves.isEmpty && game.headers['FEN'] == null)) {
return null;
}

return AnalysisOptions(
isLocalEvaluationAllowed: true,
variant: rule != null ? Variant.fromRule(rule) : Variant.standard,
pgn: textInput!,
initialMoveCursor: 1,
initialMoveCursor: mainlineMoves.isEmpty ? 0 : 1,
orientation: Side.white,
id: standaloneAnalysisId,
);
Expand Down

0 comments on commit c1ca21c

Please sign in to comment.