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}) { 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

View File

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

View File

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

View File

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

View File

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