From a8416d8eff87ac76620d3995395ae8499ed894d4 Mon Sep 17 00:00:00 2001 From: Calcitem Date: Wed, 2 Dec 2020 01:08:23 +0800 Subject: [PATCH] =?UTF-8?q?flutter:=20=E6=94=AF=E6=8C=81AI=E5=AF=B9?= =?UTF-8?q?=E6=88=98=E6=97=B6=E6=A3=8B=E5=B1=80=E7=BB=93=E6=9D=9F=E6=97=B6?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E9=87=8D=E6=96=B0=E5=BC=80=E5=B1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 顺带增加其他一些配置项但暂未实现控制逻辑。 --- src/ui/flutter/lib/common/config.dart | 27 +++++++ src/ui/flutter/lib/l10n/intl_en.arb | 32 ++++++++ src/ui/flutter/lib/l10n/intl_zh.arb | 10 ++- src/ui/flutter/lib/widgets/game_page.dart | 9 ++- src/ui/flutter/lib/widgets/settings_page.dart | 80 +++++++++++++++++++ 5 files changed, 156 insertions(+), 2 deletions(-) diff --git a/src/ui/flutter/lib/common/config.dart b/src/ui/flutter/lib/common/config.dart index c6a99e15..cd01487c 100644 --- a/src/ui/flutter/lib/common/config.dart +++ b/src/ui/flutter/lib/common/config.dart @@ -27,6 +27,15 @@ class Config { static int thinkingTime = 5000; static PlayerType whoMovesFirst = PlayerType.human; + static bool isAutoRestart = false; + static bool isAutoChangeFirstMove = false; + static bool resignIfMostLose = false; + static bool randomMoveEnabled = true; + static bool learnEndgame = false; + static bool idsEnabled = false; + static bool depthExtension = true; + static bool openingBook = false; + static Future loadProfile() async { final profile = await Profile.shared(); @@ -35,6 +44,15 @@ class Config { Config.thinkingTime = profile['thinking-time'] ?? 5000; Config.whoMovesFirst = profile['who-moves-first'] ?? PlayerType.human; + Config.isAutoRestart = profile['isAutoRestart'] ?? false; + Config.isAutoChangeFirstMove = profile['isAutoChangeFirstMove'] ?? false; + Config.resignIfMostLose = profile['resignIfMostLose'] ?? false; + Config.randomMoveEnabled = profile['randomMoveEnabled'] ?? false; + Config.learnEndgame = profile['learnEndgame'] ?? false; + Config.idsEnabled = profile['idsEnabled'] ?? false; + Config.depthExtension = profile['depthExtension'] ?? false; + Config.openingBook = profile['openingBook'] ?? false; + return true; } @@ -46,6 +64,15 @@ class Config { profile['thinking-time'] = Config.thinkingTime; profile['who-moves-first'] = Config.whoMovesFirst; + profile['isAutoRestart'] = Config.isAutoRestart; + profile['isAutoChangeFirstMove'] = Config.isAutoChangeFirstMove; + profile['resignIfMostLose'] = Config.resignIfMostLose; + profile['randomMoveEnabled'] = Config.randomMoveEnabled; + profile['learnEndgame'] = Config.learnEndgame; + profile['idsEnabled'] = Config.idsEnabled; + profile['depthExtension'] = Config.depthExtension; + profile['openingBook'] = Config.openingBook; + profile.commit(); return true; diff --git a/src/ui/flutter/lib/l10n/intl_en.arb b/src/ui/flutter/lib/l10n/intl_en.arb index ed434418..fef5382d 100644 --- a/src/ui/flutter/lib/l10n/intl_en.arb +++ b/src/ui/flutter/lib/l10n/intl_en.arb @@ -262,5 +262,37 @@ "ai": "AI", "@ai": { "description": "AI" + }, + "isAutoRestart": "Auto Restart Game", + "@isAutoRestart": { + "description": "Auto Restart Game" + }, + "isAutoChangeFirstMove": "Auto Change First Move", + "@isAutoChangeFirstMove": { + "description": "Auto Change First Move" + }, + "resignIfMostLose": "AI Resign if Most Lose", + "@resignIfMostLose": { + "description": "AI Resign if Most Lose" + }, + "randomMoveEnabled": "AI Random Move", + "@randomMoveEnabled": { + "description": "AI Random Move" + }, + "learnEndgame": "Learn Endgame", + "@learnEndgame": { + "description": "Learn Endgame" + }, + "idsEnabled": "IDS", + "@idsEnabled": { + "description": "IDS" + }, + "depthExtension": "Depth Extension", + "@depthExtension": { + "description": "Depth Extension" + }, + "openingBook": "Opening Book", + "@openingBook": { + "description": "Opening Book" } } diff --git a/src/ui/flutter/lib/l10n/intl_zh.arb b/src/ui/flutter/lib/l10n/intl_zh.arb index 562c2930..3a8351a0 100644 --- a/src/ui/flutter/lib/l10n/intl_zh.arb +++ b/src/ui/flutter/lib/l10n/intl_zh.arb @@ -64,5 +64,13 @@ "leaderBoard": "排行榜", "whoMovesFirst": "谁先行", "human": "人类", - "ai": "机器" + "ai": "机器", + "isAutoRestart": "棋局结束时自动重新开局", + "isAutoChangeFirstMove": "开局时自动交换先后手", + "resignIfMostLose": "机器明显劣势时自动认输", + "randomMoveEnabled": "机器随机走子", + "learnEndgame": "残局库自学习", + "idsEnabled": "迭代加深", + "depthExtension": "深度扩展", + "openingBook": "使用开局库" } \ No newline at end of file diff --git a/src/ui/flutter/lib/widgets/game_page.dart b/src/ui/flutter/lib/widgets/game_page.dart index 128b63ae..f5826afc 100644 --- a/src/ui/flutter/lib/widgets/game_page.dart +++ b/src/ui/flutter/lib/widgets/game_page.dart @@ -18,6 +18,7 @@ */ import 'package:flutter/material.dart'; +import 'package:sanmill/common/config.dart'; import 'package:sanmill/engine/analyze.dart'; import 'package:sanmill/engine/engine.dart'; import 'package:sanmill/engine/native_engine.dart'; @@ -193,7 +194,8 @@ class _GamePageState extends State { engineToGo() async { // TODO - while (Game.shared.position.winner == Color.nobody && + while ((Config.isAutoRestart == true || + Game.shared.position.winner == Color.nobody) && Game.shared.isAiToMove()) { changeStatus(S.of(context).thinking); @@ -209,6 +211,11 @@ class _GamePageState extends State { } else { changeStatus('Error: ${response.type}'); } + + if (Config.isAutoRestart == true && + Game.shared.position.winner != Color.nobody) { + Game.shared.newGame(); + } } } diff --git a/src/ui/flutter/lib/widgets/settings_page.dart b/src/ui/flutter/lib/widgets/settings_page.dart index 06fd43ed..69730f46 100644 --- a/src/ui/flutter/lib/widgets/settings_page.dart +++ b/src/ui/flutter/lib/widgets/settings_page.dart @@ -108,6 +108,70 @@ class _SettingsPageState extends State { Config.save(); } + switchIsAutoRestart(bool value) async { + setState(() { + Config.isAutoRestart = value; + }); + + Config.save(); + } + + switchIsAutoChangeFirstMove(bool value) async { + setState(() { + Config.isAutoChangeFirstMove = value; + }); + + Config.save(); + } + + switchResignIfMostLose(bool value) async { + setState(() { + Config.resignIfMostLose = value; + }); + + Config.save(); + } + + switchRandomMoveEnabled(bool value) async { + setState(() { + Config.randomMoveEnabled = value; + }); + + Config.save(); + } + + switchLearnEndgame(bool value) async { + setState(() { + Config.learnEndgame = value; + }); + + Config.save(); + } + + switchIdsEnabled(bool value) async { + setState(() { + Config.idsEnabled = value; + }); + + Config.save(); + } + + switchDepthExtension(bool value) async { + setState(() { + Config.depthExtension = value; + }); + + Config.save(); + } + + switchOpeningBook(bool value) async { + setState(() { + Config.openingBook = value; + }); + + Config.save(); + } + switchMusic(bool value) async { // setState(() { @@ -340,6 +404,22 @@ class _SettingsPageState extends State { ), ), const SizedBox(height: 16), + Text(S.of(context).isAutoRestart, style: headerStyle), + Card( + color: UIColors.boardBackgroundColor, + margin: const EdgeInsets.symmetric(vertical: 10), + child: Column( + children: [ + SwitchListTile( + activeColor: UIColors.primaryColor, + value: Config.isAutoRestart, + title: Text(S.of(context).isAutoRestart, style: itemStyle), + onChanged: switchIsAutoRestart, + ), + ], + ), + ), + const SizedBox(height: 16), Text(S.of(context).leaderBoard, style: headerStyle), Card( color: UIColors.boardBackgroundColor,