Skip to content

Commit

Permalink
Merge pull request #636 from lichess-org/stockfish16.1
Browse files Browse the repository at this point in the history
Stockfish16.1
  • Loading branch information
veloce authored Apr 17, 2024
2 parents d8b63a1 + 2524ed7 commit 852383c
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 24 deletions.
4 changes: 2 additions & 2 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ PODS:
- sqflite (0.0.3):
- Flutter
- FlutterMacOS
- stockfish (1.4.0):
- stockfish (1.5.0):
- Flutter
- system_info_plus (0.0.1):
- Flutter
Expand Down Expand Up @@ -250,7 +250,7 @@ SPEC CHECKSUMS:
shared_preferences_foundation: b4c3b4cddf1c21f02770737f147a3f5da9d39695
soundpool: c7f4422ca206e77f8900ed3c4ee6a6ff5a0e38a9
sqflite: 673a0e54cc04b7d6dba8d24fb8095b31c3a99eec
stockfish: 614d240ac2cd05a462dad552c7b5937bb14604fd
stockfish: 819bf4544d1e76a01da13af56324c69b3bf7928f
system_info_plus: 5393c8da281d899950d751713575fbf91c7709aa
url_launcher_ios: 6116280ddcfe98ab8820085d8d76ae7449447586
wakelock_plus: 78ec7c5b202cab7761af8e2b2b3d0671be6c4ae1
Expand Down
56 changes: 40 additions & 16 deletions lib/src/model/engine/evaluation_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ class EvaluationService {
cores: defaultEngineCores,
);

static const _defaultState =
(engineName: 'Stockfish', state: EngineState.initial, eval: null);

final ValueNotifier<EngineEvaluationState> _state =
ValueNotifier(_defaultState);
ValueListenable<EngineEvaluationState> get state => _state;

/// Initialize the engine with the given context and options.
///
/// An optional [engineFactory] can be provided, it defaults to Stockfish.
Expand All @@ -64,12 +71,14 @@ class EvaluationService {
debugPrint('Engine state: ${_engine?.state.value}');
if (_engine?.state.value == EngineState.initial ||
_engine?.state.value == EngineState.disposed) {
ref.read(engineEvaluationProvider.notifier).reset();
_state.value = _defaultState;
}
if (_engine?.state != null) {
ref
.read(engineEvaluationProvider.notifier)
.setEngineState(_engine!.state.value);
_state.value = (
engineName: _engine!.name,
state: _engine!.state.value,
eval: _state.value.eval
);
}
});
}
Expand Down Expand Up @@ -129,7 +138,11 @@ class EvaluationService {
final cachedEval =
work.steps.isEmpty ? initialPositionEval : work.evalCache;
if (cachedEval != null && cachedEval.depth >= kMaxEngineDepth) {
ref.read(engineEvaluationProvider.notifier).setEval(cachedEval);
_state.value = (
engineName: _state.value.engineName,
state: _state.value.state,
eval: cachedEval,
);
return null;
}

Expand All @@ -141,7 +154,11 @@ class EvaluationService {
evalStream.forEach((t) {
final (work, eval) = t;
if (shouldEmit(work)) {
ref.read(engineEvaluationProvider.notifier).setEval(eval);
_state.value = (
engineName: _state.value.engineName,
state: _state.value.state,
eval: eval,
);
}
});

Expand All @@ -167,26 +184,33 @@ EvaluationService evaluationService(EvaluationServiceRef ref) {
return service;
}

typedef EngineEvaluationState = ({EngineState state, ClientEval? eval});
typedef EngineEvaluationState = ({
String engineName,
EngineState state,
ClientEval? eval
});

/// A provider that holds the state of the engine and the current evaluation.
@riverpod
class EngineEvaluation extends _$EngineEvaluation {
@override
EngineEvaluationState build() {
return (state: EngineState.initial, eval: null);
}
final listenable = ref.watch(evaluationServiceProvider).state;

void setEngineState(EngineState engineState) {
state = (state: engineState, eval: state.eval);
}
listenable.addListener(_listener);

ref.onDispose(() {
listenable.removeListener(_listener);
});

void setEval(ClientEval eval) {
state = (state: state.state, eval: eval);
return listenable.value;
}

void reset() {
state = (state: EngineState.initial, eval: null);
void _listener() {
final newState = ref.read(evaluationServiceProvider).state.value;
if (state != newState) {
state = newState;
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/src/view/analysis/analysis_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ class _StockfishInfo extends ConsumerWidget {

@override
Widget build(BuildContext context, WidgetRef ref) {
final (eval: eval, state: engineState) =
final (engineName: engineName, eval: eval, state: engineState) =
ref.watch(engineEvaluationProvider);

final currentEval = eval ?? currentNode.eval;
Expand All @@ -829,7 +829,7 @@ class _StockfishInfo extends ConsumerWidget {
width: 44,
height: 44,
),
title: const Text('Stockfish 16'),
title: Text(engineName),
subtitle: Text(
context.l10n.depthX(
'$depth/$maxDepth$knps',
Expand Down
6 changes: 3 additions & 3 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1271,11 +1271,11 @@ packages:
dependency: "direct main"
description:
path: "."
ref: dc160c6ae339e4aa0b64ce50980a1b5ca5597d42
resolved-ref: dc160c6ae339e4aa0b64ce50980a1b5ca5597d42
ref: f7abbbd5e330fbc278f75bb49f61c66bb681e8fa
resolved-ref: f7abbbd5e330fbc278f75bb49f61c66bb681e8fa
url: "https://github.com/lichess-org/dart-stockfish.git"
source: git
version: "1.4.0"
version: "1.5.0"
stream_channel:
dependency: "direct dev"
description:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ dependencies:
stockfish:
git:
url: https://github.com/lichess-org/dart-stockfish.git
ref: dc160c6ae339e4aa0b64ce50980a1b5ca5597d42
ref: f7abbbd5e330fbc278f75bb49f61c66bb681e8fa
stream_transform: ^2.1.0
system_info_plus: ^0.0.5
timeago: ^3.6.0
Expand Down

0 comments on commit 852383c

Please sign in to comment.