flutter: side: 重命名相关变量
This commit is contained in:
parent
bdd0f2a12d
commit
f47e9b8c0e
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ class MillRecorder {
|
|||
|
||||
if (fullMove == 0) {
|
||||
fullMove++;
|
||||
} else if (position.side != Side.Black) {
|
||||
} else if (position.side != Side.black) {
|
||||
fullMove++;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
import '../mill/mill-recorder.dart';
|
||||
|
||||
import 'mill-base.dart';
|
||||
|
||||
class Position {
|
||||
//
|
||||
BattleResult result = BattleResult.Pending;
|
||||
|
||||
String _side;
|
||||
String _sideToMove;
|
||||
List<String> _board; // 8 * 3
|
||||
MillRecorder _recorder;
|
||||
|
||||
|
@ -16,7 +15,7 @@ class Position {
|
|||
|
||||
void initDefaultPosition() {
|
||||
//
|
||||
_side = Side.Black;
|
||||
_sideToMove = Side.black;
|
||||
_board = List<String>(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];
|
||||
|
||||
|
|
|
@ -46,13 +46,13 @@ class _BattlePageState extends State<BattlePage> {
|
|||
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;
|
||||
|
|
Loading…
Reference in New Issue