flutter: Change waitResponse times++ to times--

Remove thinkingTime.
Use moveTime.
This commit is contained in:
Calcitem 2021-04-24 11:44:15 +08:00
parent 17c1c95d38
commit 70136ac862
2 changed files with 6 additions and 9 deletions

View File

@ -25,7 +25,6 @@ class Config {
static bool settingsLoaded = false;
static bool toneEnabled = true;
static int thinkingTime = 10000; // TODO: waitResponse
static bool aiMovesFirst = false;
static bool aiIsLazy = false;
static int skillLevel = 20;
@ -72,8 +71,6 @@ class Config {
final settings = await Settings.instance();
Config.toneEnabled = settings['ToneEnabled'] ?? true;
Config.thinkingTime =
settings['ThinkingTime'] ?? 10000; // TODO: waitResponse
Config.aiMovesFirst = settings['AiMovesFirst'] ?? false;
Config.aiIsLazy = settings['AiIsLazy'] ?? false;
Config.skillLevel = settings['SkillLevel'] ?? 20;
@ -139,7 +136,6 @@ class Config {
final settings = await Settings.instance();
settings['ToneEnabled'] = Config.toneEnabled;
settings['ThinkingTime'] = Config.thinkingTime;
settings['AiMovesFirst'] = Config.aiMovesFirst;
settings['AiIsLazy'] = Config.aiIsLazy;
settings['SkillLevel'] = Config.skillLevel;

View File

@ -20,8 +20,8 @@ import 'dart:async';
import 'package:flutter/services.dart';
import 'package:sanmill/common/config.dart';
import 'package:sanmill/mill/types.dart';
import 'package:sanmill/mill/position.dart';
import 'package:sanmill/mill/types.dart';
import 'engine.dart';
@ -30,7 +30,7 @@ class NativeEngine extends AiEngine {
Future<void> startup() async {
await platform.invokeMethod('startup');
await waitResponse(['uciok'], sleep: 1, times: 30);
await waitResponse(['uciok'], sleep: 100, times: 0);
}
Future<void> send(String command) async {
@ -83,8 +83,9 @@ class NativeEngine extends AiEngine {
}
Future<String> waitResponse(List<String> prefixes,
{sleep = 100, times = 100}) async {
if (times <= 0) return '';
{sleep = 1000, times = 0}) async {
// TODO: moveTime * 3
if (times > Config.moveTime * 3) return '';
final response = await read();
@ -100,7 +101,7 @@ class NativeEngine extends AiEngine {
return Future<String>.delayed(
Duration(milliseconds: sleep),
() => waitResponse(prefixes, times: times - 1),
() => waitResponse(prefixes, times: times + 1),
);
}