From f47e9b8c0ec1a2cff6cf4bf20b652438ea010c3e Mon Sep 17 00:00:00 2001 From: Calcitem Date: Sat, 7 Nov 2020 01:17:12 +0800 Subject: [PATCH] =?UTF-8?q?flutter:=20side:=20=E9=87=8D=E5=91=BD=E5=90=8D?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E5=8F=98=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ui/flutter/lib/game/battle.dart | 4 ++-- src/ui/flutter/lib/mill/mill-base.dart | 23 +++++++++++----------- src/ui/flutter/lib/mill/mill-recorder.dart | 2 +- src/ui/flutter/lib/mill/position.dart | 21 ++++++++++---------- src/ui/flutter/lib/routes/battle-page.dart | 4 ++-- 5 files changed, 26 insertions(+), 28 deletions(-) diff --git a/src/ui/flutter/lib/game/battle.dart b/src/ui/flutter/lib/game/battle.dart index f88debd9..05133ea0 100644 --- a/src/ui/flutter/lib/game/battle.dart +++ b/src/ui/flutter/lib/game/battle.dart @@ -47,7 +47,7 @@ class Battle { bool regret({steps = 2}) { // // 轮到自己走棋的时候,才能悔棋 - if (_position.side != Side.White) { + if (_position.side != Side.white) { //Audios.playTone('invalid.mp3'); return false; } @@ -90,7 +90,7 @@ class Battle { BattleResult scanBattleResult() { // - final forPerson = (_position.side == Side.White); + final forPerson = (_position.side == Side.white); if (scanLongCatch()) { // born 'repeat' position by oppo diff --git a/src/ui/flutter/lib/mill/mill-base.dart b/src/ui/flutter/lib/mill/mill-base.dart index f7551256..f5e0f960 100644 --- a/src/ui/flutter/lib/mill/mill-base.dart +++ b/src/ui/flutter/lib/mill/mill-base.dart @@ -3,26 +3,25 @@ enum BattleResult { Pending, Win, Lose, Draw } class Side { // - static const Unknown = '-'; - static const Black = 'b'; - static const White = 'w'; - - static const Ban = 'x'; + static const unknown = '-'; + static const black = 'b'; + static const white = 'w'; + static const ban = 'x'; static String of(String piece) { - if (Black.contains(piece)) return Black; - if (White.contains(piece)) return White; - if (Ban.contains(piece)) return Ban; - return Unknown; + if (black.contains(piece)) return black; + if (white.contains(piece)) return white; + if (ban.contains(piece)) return ban; + return unknown; } static bool sameSide(String p1, String p2) { return of(p1) == of(p2); } - static String oppo(String side) { - if (side == White) return Black; - if (side == Black) return White; + static String opponent(String side) { + if (side == white) return black; + if (side == black) return white; return side; } } diff --git a/src/ui/flutter/lib/mill/mill-recorder.dart b/src/ui/flutter/lib/mill/mill-recorder.dart index 27f34b65..5e61a376 100644 --- a/src/ui/flutter/lib/mill/mill-recorder.dart +++ b/src/ui/flutter/lib/mill/mill-recorder.dart @@ -34,7 +34,7 @@ class MillRecorder { if (fullMove == 0) { fullMove++; - } else if (position.side != Side.Black) { + } else if (position.side != Side.black) { fullMove++; } diff --git a/src/ui/flutter/lib/mill/position.dart b/src/ui/flutter/lib/mill/position.dart index 42106e16..5ece018d 100644 --- a/src/ui/flutter/lib/mill/position.dart +++ b/src/ui/flutter/lib/mill/position.dart @@ -1,12 +1,11 @@ import '../mill/mill-recorder.dart'; - import 'mill-base.dart'; class Position { // BattleResult result = BattleResult.Pending; - String _side; + String _sideToMove; List _board; // 8 * 3 MillRecorder _recorder; @@ -16,7 +15,7 @@ class Position { void initDefaultPosition() { // - _side = Side.Black; + _sideToMove = Side.black; _board = List(40); // SQUARE_NB for (var i = 0; i < 40; i++) { @@ -32,7 +31,7 @@ class Position { other._board.forEach((piece) => _board.add(piece)); - _side = other._side; + _sideToMove = other._sideToMove; _recorder = other._recorder; } @@ -52,7 +51,7 @@ class Position { _board[from] = Piece.Empty; // 交换走棋方 - _side = Side.oppo(_side); + _sideToMove = Side.opponent(_sideToMove); return captured; } @@ -60,7 +59,7 @@ class Position { // 验证移动棋子的着法是否合法 bool validateMove(int from, int to) { // 移动的棋子的选手,应该是当前方 - if (Side.of(_board[from]) != _side) return false; + if (Side.of(_board[from]) != _sideToMove) return false; return true; //(StepValidate.validate(this, Move(from, to))); } @@ -74,7 +73,7 @@ class Position { _board[move.from] = Piece.Empty; // 交换走棋方 - if (turnSide) _side = Side.oppo(_side); + if (turnSide) _sideToMove = Side.opponent(_sideToMove); } bool regret() { @@ -85,7 +84,7 @@ class Position { _board[lastMove.from] = _board[lastMove.to]; _board[lastMove.to] = lastMove.captured; - _side = Side.oppo(_side); + _sideToMove = Side.opponent(_sideToMove); final counterMarks = MillRecorder.fromCounterMarks(lastMove.counterMarks); _recorder.halfMove = counterMarks.halfMove; @@ -102,7 +101,7 @@ class Position { tempPosition._board[move.from] = tempPosition._board[move.to]; tempPosition._board[move.to] = move.captured; - tempPosition._side = Side.oppo(tempPosition._side); + tempPosition._sideToMove = Side.opponent(tempPosition._sideToMove); }); _recorder.lastCapturedPosition = tempPosition.toFen(); @@ -171,9 +170,9 @@ class Position { get manualText => _recorder.buildManualText(); - get side => _side; + get side => _sideToMove; - trunSide() => _side = Side.oppo(_side); + changeSideToMove() => _sideToMove = Side.opponent(_sideToMove); String pieceAt(int index) => _board[index]; diff --git a/src/ui/flutter/lib/routes/battle-page.dart b/src/ui/flutter/lib/routes/battle-page.dart index f862b455..040df1b2 100644 --- a/src/ui/flutter/lib/routes/battle-page.dart +++ b/src/ui/flutter/lib/routes/battle-page.dart @@ -46,13 +46,13 @@ class _BattlePageState extends State { final position = Battle.shared.position; // 仅 Position 中的 side 指示一方能动棋 - if (position.side != Side.White) return; + if (position.side != Side.white) return; final tapedPiece = position.pieceAt(index); // 之前已经有棋子被选中了 if (Battle.shared.focusIndex != Move.InvalidIndex && - Side.of(position.pieceAt(Battle.shared.focusIndex)) == Side.White) { + Side.of(position.pieceAt(Battle.shared.focusIndex)) == Side.white) { // // 当前点击的棋子和之前已经选择的是同一个位置 if (Battle.shared.focusIndex == index) return;