From c0af6740c18630e279d3e21110f5f79bed07716a Mon Sep 17 00:00:00 2001 From: Calcitem Date: Sat, 14 Nov 2020 23:31:35 +0800 Subject: [PATCH] =?UTF-8?q?flutter:=20=E6=B2=A1=E7=82=B9=E5=87=BB=E5=88=B0?= =?UTF-8?q?=E6=A3=8B=E7=9B=98=E7=82=B9=E4=BD=8D=E4=B8=8A=E5=88=99=E4=B8=8D?= =?UTF-8?q?=E8=90=BD=E5=AD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 顺带: * 人工落子时,黑白交替落子改为只落黑子; * 解决棋盘初始化位置函数找不到的问题。 --- src/ui/flutter/lib/game/battle.dart | 2 +- src/ui/flutter/lib/mill/position.dart | 19 +++++++++++++++++-- src/ui/flutter/lib/routes/battle_page.dart | 9 ++++++--- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/ui/flutter/lib/game/battle.dart b/src/ui/flutter/lib/game/battle.dart index c620f340..5aae5e54 100644 --- a/src/ui/flutter/lib/game/battle.dart +++ b/src/ui/flutter/lib/game/battle.dart @@ -38,7 +38,7 @@ class Battle { } newGame() { - Battle.shared.position.initDefaultPosition(); + Battle.shared.position.init(); _focusIndex = _blurIndex = Move.invalidIndex; } diff --git a/src/ui/flutter/lib/mill/position.dart b/src/ui/flutter/lib/mill/position.dart index 2c03c339..42b47019 100644 --- a/src/ui/flutter/lib/mill/position.dart +++ b/src/ui/flutter/lib/mill/position.dart @@ -94,6 +94,10 @@ class Position { _recorder = MillRecorder(lastCapturedPosition: fen()); } + init() { + Position.init(); + } + Position.boardToGrid() { _grid = List(); for (int sq = 0; sq < _board.length; sq++) { @@ -164,9 +168,20 @@ class Position { return selectPieceSQ(makeSquare(file, rank)); } - void putPiece(var pt, int index) { + bool putPiece(var pt, int index) { + var sq = indexToSquare[index]; + + if (sq == null) { + print("putPiece skip index: $index"); + return false; + } + _grid[index] = pt; - _board[indexToSquare[index]] = pt; + _board[sq] = pt; + + print("putPiece: pt = $pt, index = $index, sq = $sq"); + + return true; } bool putPieceFR(int file, int rank) { diff --git a/src/ui/flutter/lib/routes/battle_page.dart b/src/ui/flutter/lib/routes/battle_page.dart index 74c3f054..aee6dc16 100644 --- a/src/ui/flutter/lib/routes/battle_page.dart +++ b/src/ui/flutter/lib/routes/battle_page.dart @@ -51,7 +51,7 @@ class _BattlePageState extends State { String _status = ''; bool _analysising = false; - static int flag = 0; + //static int flag = 0; @override void initState() { @@ -72,8 +72,11 @@ class _BattlePageState extends State { final position = Battle.shared.position; //position - flag++; - position.putPiece(flag % 2 == 0 ? '@' : 'O', index); + //flag++; + //position.putPiece(flag % 2 == 0 ? '@' : 'O', index); + if (position.putPiece('@', index) == false) { + return; + } // 仅 Position 中的 side 指示一方能动棋 if (position.side != Color.black) return;