flutter: 实现双人对战和机器对战

This commit is contained in:
Calcitem 2020-11-30 00:21:04 +08:00
parent 0e0540ecf5
commit e9a4d80918
2 changed files with 36 additions and 8 deletions

View File

@ -18,6 +18,7 @@
*/
import 'package:sanmill/common/config.dart';
import 'package:sanmill/engine/engine.dart';
import 'package:sanmill/mill/types.dart';
import 'mill.dart';
@ -38,21 +39,44 @@ class Game {
Map<String, bool> isSearching = {Color.black: false, Color.white: false};
EngineType engineType;
bool aiIsSearching() {
return isSearching[Color.black] == true || isSearching[Color.white] == true;
}
void setWhoIsAi(EngineType type) {
engineType = type;
switch (type) {
case EngineType.humanVsAi:
if (Config.whoMovesFirst == PlayerType.human) {
isAi[Color.black] = false;
isAi[Color.white] = true;
} else if (Config.whoMovesFirst == PlayerType.AI) {
isAi[Color.black] = true;
isAi[Color.white] = false;
}
break;
case EngineType.humanVsHuman:
isAi[Color.black] = false;
isAi[Color.white] = false;
break;
case EngineType.aiVsAi:
isAi[Color.black] = true;
isAi[Color.white] = true;
break;
case EngineType.humanVsCloud:
break;
default:
break;
}
}
void start() {
position.reset();
// TDOO
if (Config.whoMovesFirst == PlayerType.human) {
isAi[Color.black] = false;
isAi[Color.white] = true;
} else {
isAi[Color.black] = true;
isAi[Color.white] = false;
}
setWhoIsAi(engineType);
}
bool hasAnimation;

View File

@ -53,6 +53,10 @@ class _GamePageState extends State<GamePage> {
@override
void initState() {
print("engineType = ${widget.engineType}");
Game.shared.setWhoIsAi(widget.engineType);
super.initState();
Game.shared.init();
widget.engine.startup();