Skip to content

Commit

Permalink
Update dartchess version to get better move parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
370417 committed Jan 18, 2023
1 parent f894540 commit 3bc632b
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lib/src/features/game/model/game_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class GameState with _$GameState {
final List<Position<Chess>> positions = [Chess.initial];
final List<String> sanMoves = [];
for (final m in uciMoves) {
final move = Move.fromUci(m);
final move = Move.fromUci(m)!;
final newPos = positions.last.playToSan(move);
positions.add(newPos.item1);
sanMoves.add(newPos.item2);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/features/game/ui/board/playable_game_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ class _BoardBody extends ConsumerWidget {
sideToMove: gameState?.position.turn.cg ?? game.orientation.cg,
onMove: (cg.Move move, {bool? isPremove}) => ref
.read(gameStateProvider.notifier)
.onUserMove(game.id, Move.fromUci(move.uci)),
.onUserMove(game.id, Move.fromUci(move.uci)!),
),
topPlayer: topPlayer,
bottomPlayer: bottomPlayer,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/features/tv/data/tv_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class TvEvent with _$TvEvent {
return pick('d').letOrThrow((dataPick) => TvEvent.fen(
fen: dataPick('fen').asStringOrThrow(),
lastMove: dataPick('lm')
.letOrThrow((it) => Move.fromUci(it.asStringOrThrow())),
.letOrThrow((it) => Move.fromUci(it.asStringOrThrow())!),
whiteSeconds: dataPick('wc').asIntOrThrow(),
blackSeconds: dataPick('bc').asIntOrThrow(),
));
Expand Down
2 changes: 1 addition & 1 deletion lib/src/utils/json.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ extension Dartchess on Pick {
}
if (value is String) {
try {
return Move.fromUci(value);
return Move.fromUci(value)!;
} catch (_) {
throw PickException(
"value $value at $debugParsingExit can't be casted to Move: invalid UCI string.");
Expand Down
4 changes: 1 addition & 3 deletions lib/src/widgets/non_visual_game_board.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ class NonVisualGameBoard extends StatelessWidget {
if (scanResult != null) {
return scanResult;
}
// TODO: uncomment when parseSan is available
final move =
Move.fromUci(command) /*?? gameState.position.parseSan(command)*/;
final move = Move.fromUci(command) ?? position.parseSan(command);
if (move != null) {
onMove(move);
return null;
Expand Down
4 changes: 2 additions & 2 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ packages:
dependency: "direct main"
description:
path: "."
ref: "68c756354b53c9f210f78b49ee1caa03ab5003bd"
resolved-ref: "68c756354b53c9f210f78b49ee1caa03ab5003bd"
ref: "90ed79af3db095fb40e1a14c7ee85aaccf83b1f3"
resolved-ref: "90ed79af3db095fb40e1a14c7ee85aaccf83b1f3"
url: "https://github.com/lichess-org/dartchess.git"
source: git
version: "0.1.0"
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ dependencies:
dartchess:
git:
url: https://github.com/lichess-org/dartchess.git
ref: 68c756354b53c9f210f78b49ee1caa03ab5003bd
ref: 90ed79af3db095fb40e1a14c7ee85aaccf83b1f3
chessground:
git:
url: https://github.com/lichess-org/flutter-chessground.git
Expand Down
6 changes: 3 additions & 3 deletions test/features/game/ui/board/playable_game_screen_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ class FakeGameClient extends Fake implements http.Client {
final move = request.url.path.substring(request.url.path.length - 4);
moves.add(move);
whiteTime -= 5000;
position = position.play(Move.fromUci(move));
position = position.play(Move.fromUci(move)!);
_sendGameEvent(
'{ "type": "gameState", "moves": "${moves.join(' ')}", "wtime": $whiteTime, "btime": $blackTime, "status": "started" }');

Expand All @@ -362,14 +362,14 @@ class FakeGameClient extends Fake implements http.Client {
case 1:
moves.add('e7e5');
blackTime -= 3000;
position = position.play(Move.fromUci('e7e5'));
position = position.play(Move.fromUci('e7e5')!);
_sendGameEvent(
'{ "type": "gameState", "moves": "${moves.join(' ')}", "wtime": $whiteTime, "btime": $blackTime, "status": "started" }');
break;
case 3:
moves.add('b8c6');
blackTime -= 6000;
position = position.play(Move.fromUci('b8c6'));
position = position.play(Move.fromUci('b8c6')!);
_sendGameEvent(
'{ "type": "gameState", "moves": "${moves.join(' ')}", "wtime": $whiteTime, "btime": $blackTime, "status": "started" }');
break;
Expand Down

0 comments on commit 3bc632b

Please sign in to comment.