flutter: side: 重命名相关变量
This commit is contained in:
parent
bdd0f2a12d
commit
f47e9b8c0e
|
@ -47,7 +47,7 @@ class Battle {
|
||||||
bool regret({steps = 2}) {
|
bool regret({steps = 2}) {
|
||||||
//
|
//
|
||||||
// 轮到自己走棋的时候,才能悔棋
|
// 轮到自己走棋的时候,才能悔棋
|
||||||
if (_position.side != Side.White) {
|
if (_position.side != Side.white) {
|
||||||
//Audios.playTone('invalid.mp3');
|
//Audios.playTone('invalid.mp3');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -90,7 +90,7 @@ class Battle {
|
||||||
|
|
||||||
BattleResult scanBattleResult() {
|
BattleResult scanBattleResult() {
|
||||||
//
|
//
|
||||||
final forPerson = (_position.side == Side.White);
|
final forPerson = (_position.side == Side.white);
|
||||||
|
|
||||||
if (scanLongCatch()) {
|
if (scanLongCatch()) {
|
||||||
// born 'repeat' position by oppo
|
// born 'repeat' position by oppo
|
||||||
|
|
|
@ -3,26 +3,25 @@ enum BattleResult { Pending, Win, Lose, Draw }
|
||||||
|
|
||||||
class Side {
|
class Side {
|
||||||
//
|
//
|
||||||
static const Unknown = '-';
|
static const unknown = '-';
|
||||||
static const Black = 'b';
|
static const black = 'b';
|
||||||
static const White = 'w';
|
static const white = 'w';
|
||||||
|
static const ban = 'x';
|
||||||
static const Ban = 'x';
|
|
||||||
|
|
||||||
static String of(String piece) {
|
static String of(String piece) {
|
||||||
if (Black.contains(piece)) return Black;
|
if (black.contains(piece)) return black;
|
||||||
if (White.contains(piece)) return White;
|
if (white.contains(piece)) return white;
|
||||||
if (Ban.contains(piece)) return Ban;
|
if (ban.contains(piece)) return ban;
|
||||||
return Unknown;
|
return unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool sameSide(String p1, String p2) {
|
static bool sameSide(String p1, String p2) {
|
||||||
return of(p1) == of(p2);
|
return of(p1) == of(p2);
|
||||||
}
|
}
|
||||||
|
|
||||||
static String oppo(String side) {
|
static String opponent(String side) {
|
||||||
if (side == White) return Black;
|
if (side == white) return black;
|
||||||
if (side == Black) return White;
|
if (side == black) return white;
|
||||||
return side;
|
return side;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ class MillRecorder {
|
||||||
|
|
||||||
if (fullMove == 0) {
|
if (fullMove == 0) {
|
||||||
fullMove++;
|
fullMove++;
|
||||||
} else if (position.side != Side.Black) {
|
} else if (position.side != Side.black) {
|
||||||
fullMove++;
|
fullMove++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
import '../mill/mill-recorder.dart';
|
import '../mill/mill-recorder.dart';
|
||||||
|
|
||||||
import 'mill-base.dart';
|
import 'mill-base.dart';
|
||||||
|
|
||||||
class Position {
|
class Position {
|
||||||
//
|
//
|
||||||
BattleResult result = BattleResult.Pending;
|
BattleResult result = BattleResult.Pending;
|
||||||
|
|
||||||
String _side;
|
String _sideToMove;
|
||||||
List<String> _board; // 8 * 3
|
List<String> _board; // 8 * 3
|
||||||
MillRecorder _recorder;
|
MillRecorder _recorder;
|
||||||
|
|
||||||
|
@ -16,7 +15,7 @@ class Position {
|
||||||
|
|
||||||
void initDefaultPosition() {
|
void initDefaultPosition() {
|
||||||
//
|
//
|
||||||
_side = Side.Black;
|
_sideToMove = Side.black;
|
||||||
_board = List<String>(40); // SQUARE_NB
|
_board = List<String>(40); // SQUARE_NB
|
||||||
|
|
||||||
for (var i = 0; i < 40; i++) {
|
for (var i = 0; i < 40; i++) {
|
||||||
|
@ -32,7 +31,7 @@ class Position {
|
||||||
|
|
||||||
other._board.forEach((piece) => _board.add(piece));
|
other._board.forEach((piece) => _board.add(piece));
|
||||||
|
|
||||||
_side = other._side;
|
_sideToMove = other._sideToMove;
|
||||||
|
|
||||||
_recorder = other._recorder;
|
_recorder = other._recorder;
|
||||||
}
|
}
|
||||||
|
@ -52,7 +51,7 @@ class Position {
|
||||||
_board[from] = Piece.Empty;
|
_board[from] = Piece.Empty;
|
||||||
|
|
||||||
// 交换走棋方
|
// 交换走棋方
|
||||||
_side = Side.oppo(_side);
|
_sideToMove = Side.opponent(_sideToMove);
|
||||||
|
|
||||||
return captured;
|
return captured;
|
||||||
}
|
}
|
||||||
|
@ -60,7 +59,7 @@ class Position {
|
||||||
// 验证移动棋子的着法是否合法
|
// 验证移动棋子的着法是否合法
|
||||||
bool validateMove(int from, int to) {
|
bool validateMove(int from, int to) {
|
||||||
// 移动的棋子的选手,应该是当前方
|
// 移动的棋子的选手,应该是当前方
|
||||||
if (Side.of(_board[from]) != _side) return false;
|
if (Side.of(_board[from]) != _sideToMove) return false;
|
||||||
return true;
|
return true;
|
||||||
//(StepValidate.validate(this, Move(from, to)));
|
//(StepValidate.validate(this, Move(from, to)));
|
||||||
}
|
}
|
||||||
|
@ -74,7 +73,7 @@ class Position {
|
||||||
_board[move.from] = Piece.Empty;
|
_board[move.from] = Piece.Empty;
|
||||||
|
|
||||||
// 交换走棋方
|
// 交换走棋方
|
||||||
if (turnSide) _side = Side.oppo(_side);
|
if (turnSide) _sideToMove = Side.opponent(_sideToMove);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool regret() {
|
bool regret() {
|
||||||
|
@ -85,7 +84,7 @@ class Position {
|
||||||
_board[lastMove.from] = _board[lastMove.to];
|
_board[lastMove.from] = _board[lastMove.to];
|
||||||
_board[lastMove.to] = lastMove.captured;
|
_board[lastMove.to] = lastMove.captured;
|
||||||
|
|
||||||
_side = Side.oppo(_side);
|
_sideToMove = Side.opponent(_sideToMove);
|
||||||
|
|
||||||
final counterMarks = MillRecorder.fromCounterMarks(lastMove.counterMarks);
|
final counterMarks = MillRecorder.fromCounterMarks(lastMove.counterMarks);
|
||||||
_recorder.halfMove = counterMarks.halfMove;
|
_recorder.halfMove = counterMarks.halfMove;
|
||||||
|
@ -102,7 +101,7 @@ class Position {
|
||||||
tempPosition._board[move.from] = tempPosition._board[move.to];
|
tempPosition._board[move.from] = tempPosition._board[move.to];
|
||||||
tempPosition._board[move.to] = move.captured;
|
tempPosition._board[move.to] = move.captured;
|
||||||
|
|
||||||
tempPosition._side = Side.oppo(tempPosition._side);
|
tempPosition._sideToMove = Side.opponent(tempPosition._sideToMove);
|
||||||
});
|
});
|
||||||
|
|
||||||
_recorder.lastCapturedPosition = tempPosition.toFen();
|
_recorder.lastCapturedPosition = tempPosition.toFen();
|
||||||
|
@ -171,9 +170,9 @@ class Position {
|
||||||
|
|
||||||
get manualText => _recorder.buildManualText();
|
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];
|
String pieceAt(int index) => _board[index];
|
||||||
|
|
||||||
|
|
|
@ -46,13 +46,13 @@ class _BattlePageState extends State<BattlePage> {
|
||||||
final position = Battle.shared.position;
|
final position = Battle.shared.position;
|
||||||
|
|
||||||
// 仅 Position 中的 side 指示一方能动棋
|
// 仅 Position 中的 side 指示一方能动棋
|
||||||
if (position.side != Side.White) return;
|
if (position.side != Side.white) return;
|
||||||
|
|
||||||
final tapedPiece = position.pieceAt(index);
|
final tapedPiece = position.pieceAt(index);
|
||||||
|
|
||||||
// 之前已经有棋子被选中了
|
// 之前已经有棋子被选中了
|
||||||
if (Battle.shared.focusIndex != Move.InvalidIndex &&
|
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;
|
if (Battle.shared.focusIndex == index) return;
|
||||||
|
|
Loading…
Reference in New Issue