From e9a4d809184f833082dda40d11dd15d32a57c39e Mon Sep 17 00:00:00 2001 From: Calcitem Date: Mon, 30 Nov 2020 00:21:04 +0800 Subject: [PATCH] =?UTF-8?q?flutter:=20=E5=AE=9E=E7=8E=B0=E5=8F=8C=E4=BA=BA?= =?UTF-8?q?=E5=AF=B9=E6=88=98=E5=92=8C=E6=9C=BA=E5=99=A8=E5=AF=B9=E6=88=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ui/flutter/lib/mill/game.dart | 40 ++++++++++++++++++----- src/ui/flutter/lib/widgets/game_page.dart | 4 +++ 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/ui/flutter/lib/mill/game.dart b/src/ui/flutter/lib/mill/game.dart index 2cb15a5e..115611fd 100644 --- a/src/ui/flutter/lib/mill/game.dart +++ b/src/ui/flutter/lib/mill/game.dart @@ -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 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; diff --git a/src/ui/flutter/lib/widgets/game_page.dart b/src/ui/flutter/lib/widgets/game_page.dart index 1f6080f6..128b63ae 100644 --- a/src/ui/flutter/lib/widgets/game_page.dart +++ b/src/ui/flutter/lib/widgets/game_page.dart @@ -53,6 +53,10 @@ class _GamePageState extends State { @override void initState() { + print("engineType = ${widget.engineType}"); + + Game.shared.setWhoIsAi(widget.engineType); + super.initState(); Game.shared.init(); widget.engine.startup();