Skip to content

Commit

Permalink
follow the updated restriction which isolate can send. (#1746)
Browse files Browse the repository at this point in the history
* follow the updated restriction which isolate can send.

* fix

* fix

* workaround ?

* fix

* fix
  • Loading branch information
sensuikan1973 authored Mar 4, 2024
1 parent 6827cb5 commit 45f6d03
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 22 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/flutter_ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,20 @@ jobs:
- os: windows
runner_machine: windows-latest
setup_for_flutter_desktop_script: .github/scripts/windows/install_additional_requirements_for_flutter.sh
# workaround for https://github.com/sensuikan1973/pedax/pull/1746#issuecomment-1975666851
widget_test_command: flutter test --verbose --coverage --coverage-path=./coverage/lcov.widget_test.info --concurrency 1
integration_test_command: flutter test integration_test --device-id windows --verbose --coverage --coverage-path=./coverage/lcov.integration_test.info
- os: macos
# Why isn't this macos-latest ? -> workaround for https://github.com/sensuikan1973/pedax/pull/1443
# https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners
runner_machine: macos-13
setup_for_flutter_desktop_script: .github/scripts/macos/install_additional_requirements_for_flutter.sh
widget_test_command: flutter test --verbose --coverage --coverage-path=./coverage/lcov.widget_test.info --concurrency 1
integration_test_command: flutter test integration_test --device-id macos --verbose --coverage --coverage-path=./coverage/lcov.integration_test.info
- os: ubuntu
runner_machine: ubuntu-latest
setup_for_flutter_desktop_script: .github/scripts/linux/install_additional_requirements_for_flutter.sh
widget_test_command: flutter test --verbose --coverage --coverage-path=./coverage/lcov.widget_test.info --concurrency 1
integration_test_command: |
touch ./coverage/lcov.integration_test.info
timeout 240 xvfb-run -a \
Expand All @@ -89,7 +93,7 @@ jobs:

# https://docs.flutter.dev/testing#widget-tests
- name: widget test
run: flutter test --verbose --coverage --coverage-path=./coverage/lcov.widget_test.info --concurrency 1
run: ${{ matrix.widget_test_command }}
# https://docs.codecov.com/docs/merging-reports#multiple-languages
- uses: codecov/codecov-action@v3
with: # ref: https://github.com/codecov/codecov-action/blob/v3.1.0/.github/workflows/main.yml
Expand Down
7 changes: 4 additions & 3 deletions lib/engine/api/count_bestpath.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ class CountBestpathRequest implements RequestSchema {
required this.movesAtRequest,
required this.playerLowerLimit,
required this.opponentLowerLimit,
required this.logger,
required this.logLevel,
});

final String movesAtRequest;
final int playerLowerLimit;
final int opponentLowerLimit;
final Logger logger;
final Level logLevel;
}

@immutable
Expand All @@ -43,10 +43,11 @@ Stream<CountBestpathResponse> executeCountBestpath(
final CountBestpathRequest request,
) async* {
final rootBookMoveListWithPosition = edax.edaxGetBookMoveWithPositionByMoves(request.movesAtRequest);
final logger = Logger(level: request.logLevel);
for (final move in rootBookMoveListWithPosition.moveList) {
final currentMoves = edax.edaxGetMoves();
if (currentMoves != request.movesAtRequest) {
request.logger.d(
logger.d(
'count bestpath process is aborted.\ncurrentMoves "$currentMoves" is not equal to movesAtRequest "${request.movesAtRequest}"',
);
edax.edaxBookStopCountBestpath();
Expand Down
13 changes: 7 additions & 6 deletions lib/engine/api/hint_one_by_one.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ class HintOneByOneRequest implements RequestSchema {
required this.level,
required this.stepByStep,
required this.movesAtRequest,
required this.logger,
required this.logLevel,
});

final int level;
final bool stepByStep;
final String movesAtRequest;
final Logger logger;
final Level logLevel;
}

@immutable
Expand Down Expand Up @@ -47,23 +47,24 @@ Stream<HintOneByOneResponse> executeHintOneByOne(
) async* {
final levelList = request.stepByStep ? generateLevelList3Steps(request.level) : [request.level];
const levelOption = LevelOption();
final logger = Logger(level: request.logLevel);
for (final level in levelList) {
edax.edaxStop();
request.logger.d('stopped edax search');
logger.d('stopped edax search');
edax
..edaxSetOption(levelOption.nativeName, level.toString())
..edaxHintPrepare();
request.logger.d('prepared getting hint one by one.\nlevel: $level.\nmoves at request: ${request.movesAtRequest}');
logger.d('prepared getting hint one by one.\nlevel: $level.\nmoves at request: ${request.movesAtRequest}');
while (true) {
final currentMoves = edax.edaxGetMoves();
if (currentMoves != request.movesAtRequest) {
request.logger.d(
logger.d(
'hint process is aborted.\ncurrentMoves "$currentMoves" is not equal to movesAtRequest "${request.movesAtRequest}"',
);
return;
}

request.logger.d('will call edaxHintNextNoMultiPvDepth');
logger.d('will call edaxHintNextNoMultiPvDepth');
final hint = edax.edaxHintNextNoMultiPvDepth();
if (hint.isNoMove) break;
yield HintOneByOneResponse(request: request, hint: hint, level: level, isLastStep: level == levelList.last);
Expand Down
7 changes: 4 additions & 3 deletions lib/engine/api/setboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ class SetboardRequest implements RequestSchema {
const SetboardRequest({
required this.currentColor,
required this.replacementTargets,
required this.logger,
required this.logLevel,
});

final int currentColor;
final List<SquareReplacement> replacementTargets;
final Logger logger;
final Level logLevel;
}

@immutable
Expand Down Expand Up @@ -55,7 +55,8 @@ SetboardResponse executeSetboard(final LibEdax edax, final SetboardRequest reque
final currentColorChar = request.currentColor == TurnColor.black ? ColorChar.black : ColorChar.white;
boardStr = boardStr.replaceFirst(RegExp('.'), currentColorChar, 64);

request.logger.d('setboard $boardStr');
final logger = Logger(level: request.logLevel);
logger.d('setboard $boardStr');
edax.edaxSetboard(boardStr);

return SetboardResponse(
Expand Down
10 changes: 5 additions & 5 deletions lib/engine/edax_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,26 @@ import 'api/undo.dart';
// NOTE: top level function for `isolate.spawn`.
@doNotStore
Future<void> startEdaxServer(final StartEdaxServerParams params) async {
final server = EdaxServer(dllPath: params.dllPath, logger: params.logger);
final server = EdaxServer(dllPath: params.dllPath, logLevel: params.logLevel);
await server.start(params.parentSendPort, params.initLibedaxParameters);
}

@immutable
class StartEdaxServerParams {
const StartEdaxServerParams(this.parentSendPort, this.dllPath, this.initLibedaxParameters, this.logger);
const StartEdaxServerParams(this.parentSendPort, this.dllPath, this.initLibedaxParameters, this.logLevel);
final SendPort parentSendPort;
final String dllPath;
final List<String> initLibedaxParameters;
final Logger logger;
final Level logLevel;
}

@doNotStore
class EdaxServer {
EdaxServer({
required final String dllPath,
required final Logger logger,
required final Level logLevel,
}) : _dllPath = dllPath,
_logger = logger;
_logger = Logger(level: logLevel);

final String _dllPath;
final Logger _logger;
Expand Down
8 changes: 4 additions & 4 deletions lib/models/board_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class BoardNotifier extends ValueNotifier<BoardState> {
}) async {
await Isolate.spawn(
startEdaxServer,
StartEdaxServerParams(_receivePort.sendPort, libedaxPath, initLibedaxParams, _logger),
StartEdaxServerParams(_receivePort.sendPort, libedaxPath, initLibedaxParams, Logger.level),
);
_receiveStream = _receivePort.asBroadcastStream();
_edaxServerPort = await _receiveStream.first as SendPort;
Expand Down Expand Up @@ -95,7 +95,7 @@ class BoardNotifier extends ValueNotifier<BoardState> {
SetboardRequest(
currentColor: value.arrangeTargetColor,
replacementTargets: arrangeTargetChar,
logger: _logger,
logLevel: Logger.level,
),
);
}
Expand Down Expand Up @@ -149,7 +149,7 @@ class BoardNotifier extends ValueNotifier<BoardState> {
level: value.level,
stepByStep: value.hintStepByStep,
movesAtRequest: movesAtRequest,
logger: _logger,
logLevel: Logger.level,
),
);
}
Expand All @@ -169,7 +169,7 @@ class BoardNotifier extends ValueNotifier<BoardState> {
movesAtRequest: movesAtRequest,
playerLowerLimit: await _bestpathCountPlayerLowerLimitOption.val,
opponentLowerLimit: await _bestpathCountOpponentLowerLimitOption.val,
logger: _logger,
logLevel: Logger.level,
),
);
}
Expand Down

0 comments on commit 45f6d03

Please sign in to comment.