flutter: side: 重命名相关变量

This commit is contained in:
Calcitem 2020-11-07 01:17:12 +08:00
parent bdd0f2a12d
commit f47e9b8c0e
5 changed files with 26 additions and 28 deletions

View File

@ -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

View File

@ -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;
}
}

View File

@ -34,7 +34,7 @@ class MillRecorder {
if (fullMove == 0) {
fullMove++;
} else if (position.side != Side.Black) {
} else if (position.side != Side.black) {
fullMove++;
}

View File

@ -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];

View File

@ -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;