parent
fc796a7a27
commit
a8416d8eff
|
@ -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<void> 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;
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,5 +64,13 @@
|
|||
"leaderBoard": "排行榜",
|
||||
"whoMovesFirst": "谁先行",
|
||||
"human": "人类",
|
||||
"ai": "机器"
|
||||
"ai": "机器",
|
||||
"isAutoRestart": "棋局结束时自动重新开局",
|
||||
"isAutoChangeFirstMove": "开局时自动交换先后手",
|
||||
"resignIfMostLose": "机器明显劣势时自动认输",
|
||||
"randomMoveEnabled": "机器随机走子",
|
||||
"learnEndgame": "残局库自学习",
|
||||
"idsEnabled": "迭代加深",
|
||||
"depthExtension": "深度扩展",
|
||||
"openingBook": "使用开局库"
|
||||
}
|
|
@ -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<GamePage> {
|
|||
|
||||
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<GamePage> {
|
|||
} else {
|
||||
changeStatus('Error: ${response.type}');
|
||||
}
|
||||
|
||||
if (Config.isAutoRestart == true &&
|
||||
Game.shared.position.winner != Color.nobody) {
|
||||
Game.shared.newGame();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -108,6 +108,70 @@ class _SettingsPageState extends State<SettingsPage> {
|
|||
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<SettingsPage> {
|
|||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(S.of(context).isAutoRestart, style: headerStyle),
|
||||
Card(
|
||||
color: UIColors.boardBackgroundColor,
|
||||
margin: const EdgeInsets.symmetric(vertical: 10),
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
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,
|
||||
|
|
Loading…
Reference in New Issue