flutter: invalidIndex 等部分变量改名
This commit is contained in:
parent
a78f1cd9f5
commit
f6710e800e
|
@ -55,7 +55,7 @@ class BoardWidget extends StatelessWidget {
|
||||||
onTapUp: (d) {
|
onTapUp: (d) {
|
||||||
//
|
//
|
||||||
final gridWidth = (width - padding * 2);
|
final gridWidth = (width - padding * 2);
|
||||||
final squareWidth = gridWidth / 6;
|
final squareWidth = gridWidth / 7;
|
||||||
|
|
||||||
final dx = d.localPosition.dx, dy = d.localPosition.dy;
|
final dx = d.localPosition.dx, dy = d.localPosition.dy;
|
||||||
final row = (dy - padding - digitsHeight) ~/ squareWidth;
|
final row = (dy - padding - digitsHeight) ~/ squareWidth;
|
||||||
|
|
|
@ -22,8 +22,8 @@ class PiecesPainter extends PainterBase {
|
||||||
PiecesPainter({
|
PiecesPainter({
|
||||||
@required double width,
|
@required double width,
|
||||||
@required this.position,
|
@required this.position,
|
||||||
this.focusIndex = Move.InvalidIndex,
|
this.focusIndex = Move.invalidIndex,
|
||||||
this.blurIndex = Move.InvalidIndex,
|
this.blurIndex = Move.invalidIndex,
|
||||||
}) : super(width: width) {
|
}) : super(width: width) {
|
||||||
//
|
//
|
||||||
pieceSide = squareWidth * 0.9; // 棋子大小
|
pieceSide = squareWidth * 0.9; // 棋子大小
|
||||||
|
@ -62,11 +62,12 @@ class PiecesPainter extends PainterBase {
|
||||||
double pieceSide,
|
double pieceSide,
|
||||||
double offsetX,
|
double offsetX,
|
||||||
double offsetY,
|
double offsetY,
|
||||||
int focusIndex = Move.InvalidIndex,
|
int focusIndex = Move.invalidIndex,
|
||||||
int blurIndex = Move.InvalidIndex,
|
int blurIndex = Move.invalidIndex,
|
||||||
}) {
|
}) {
|
||||||
//
|
//
|
||||||
final left = offsetX, top = offsetY;
|
final left = offsetX;
|
||||||
|
final top = offsetY;
|
||||||
|
|
||||||
final shadowPath = Path();
|
final shadowPath = Path();
|
||||||
final piecesToDraw = <PiecePaintStub>[];
|
final piecesToDraw = <PiecePaintStub>[];
|
||||||
|
@ -76,10 +77,9 @@ class PiecesPainter extends PainterBase {
|
||||||
//
|
//
|
||||||
for (var column = 0; column < 7; column++) {
|
for (var column = 0; column < 7; column++) {
|
||||||
//
|
//
|
||||||
//final piece = position.pieceAt(row * 7 + column);
|
|
||||||
final piece = position.pieceAt(row * 7 + column); // 改为9则全空
|
final piece = position.pieceAt(row * 7 + column); // 改为9则全空
|
||||||
|
|
||||||
if (piece == Piece.Empty) continue;
|
if (piece == Piece.noPiece) continue;
|
||||||
|
|
||||||
var pos = Offset(left + squareSide * column, top + squareSide * row);
|
var pos = Offset(left + squareSide * column, top + squareSide * row);
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ class PiecesPainter extends PainterBase {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
final textStyle = TextStyle(
|
final textStyle = TextStyle(
|
||||||
color: ColorConsts.PieceTextColor,
|
color: ColorConst.PieceTextColor,
|
||||||
fontSize: pieceSide * 0.8,
|
fontSize: pieceSide * 0.8,
|
||||||
height: 1.0,
|
height: 1.0,
|
||||||
);
|
);
|
||||||
|
@ -116,7 +116,7 @@ class PiecesPainter extends PainterBase {
|
||||||
paint.color = Piece.isWhite(pps.piece)
|
paint.color = Piece.isWhite(pps.piece)
|
||||||
? ColorConst.whitePieceColor
|
? ColorConst.whitePieceColor
|
||||||
: ColorConst.blackPieceColor;
|
: ColorConst.blackPieceColor;
|
||||||
//paint.color = ColorConsts.WhitePieceColor;
|
//paint.color = ColorConst.WhitePieceColor;
|
||||||
|
|
||||||
canvas.drawCircle(pps.pos, pieceSide * 0.8 / 2, paint); // 决定棋子外圈有宽
|
canvas.drawCircle(pps.pos, pieceSide * 0.8 / 2, paint); // 决定棋子外圈有宽
|
||||||
/*
|
/*
|
||||||
|
@ -140,7 +140,7 @@ class PiecesPainter extends PainterBase {
|
||||||
|
|
||||||
// draw focus and blur position
|
// draw focus and blur position
|
||||||
|
|
||||||
if (focusIndex != Move.InvalidIndex) {
|
if (focusIndex != Move.invalidIndex) {
|
||||||
//
|
//
|
||||||
final int row = focusIndex ~/ 7, column = focusIndex % 7;
|
final int row = focusIndex ~/ 7, column = focusIndex % 7;
|
||||||
|
|
||||||
|
@ -155,7 +155,7 @@ class PiecesPainter extends PainterBase {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (blurIndex != Move.InvalidIndex) {
|
if (blurIndex != Move.invalidIndex) {
|
||||||
//
|
//
|
||||||
final row = blurIndex ~/ 7, column = blurIndex % 7;
|
final row = blurIndex ~/ 7, column = blurIndex % 7;
|
||||||
|
|
||||||
|
|
|
@ -15,17 +15,17 @@ class Battle {
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
_position = Position.defaultPosition();
|
_position = Position.defaultPosition();
|
||||||
_focusIndex = _blurIndex = Move.InvalidIndex;
|
_focusIndex = _blurIndex = Move.invalidIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
newGame() {
|
newGame() {
|
||||||
Battle.shared.position.initDefaultPosition();
|
Battle.shared.position.initDefaultPosition();
|
||||||
_focusIndex = _blurIndex = Move.InvalidIndex;
|
_focusIndex = _blurIndex = Move.invalidIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
select(int pos) {
|
select(int pos) {
|
||||||
_focusIndex = pos;
|
_focusIndex = pos;
|
||||||
_blurIndex = Move.InvalidIndex;
|
_blurIndex = Move.invalidIndex;
|
||||||
//Audios.playTone('click.mp3');
|
//Audios.playTone('click.mp3');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ class Battle {
|
||||||
//
|
//
|
||||||
} else {
|
} else {
|
||||||
//
|
//
|
||||||
_blurIndex = _focusIndex = Move.InvalidIndex;
|
_blurIndex = _focusIndex = Move.invalidIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
regreted = true;
|
regreted = true;
|
||||||
|
@ -85,7 +85,7 @@ class Battle {
|
||||||
}
|
}
|
||||||
|
|
||||||
clear() {
|
clear() {
|
||||||
_blurIndex = _focusIndex = Move.InvalidIndex;
|
_blurIndex = _focusIndex = Move.invalidIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
BattleResult scanBattleResult() {
|
BattleResult scanBattleResult() {
|
||||||
|
|
|
@ -28,18 +28,18 @@ class Side {
|
||||||
|
|
||||||
class Piece {
|
class Piece {
|
||||||
//
|
//
|
||||||
static const Empty = ' ';
|
static const noPiece = ' ';
|
||||||
//
|
//
|
||||||
static const BlackStone = 'b';
|
static const blackStone = 'b';
|
||||||
static const WhiteStone = 'w';
|
static const whiteStone = 'w';
|
||||||
static const Ban = 'x';
|
static const ban = 'x';
|
||||||
|
|
||||||
static const Names = {
|
static const Names = {
|
||||||
Empty: '',
|
noPiece: '',
|
||||||
//
|
//
|
||||||
BlackStone: 'b',
|
blackStone: 'b',
|
||||||
WhiteStone: 'w',
|
whiteStone: 'w',
|
||||||
Ban: 'x',
|
ban: 'x',
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool isBlack(String c) => 'b'.contains(c);
|
static bool isBlack(String c) => 'b'.contains(c);
|
||||||
|
@ -49,7 +49,7 @@ class Piece {
|
||||||
|
|
||||||
class Move {
|
class Move {
|
||||||
// TODO
|
// TODO
|
||||||
static const InvalidIndex = -1;
|
static const invalidIndex = -1;
|
||||||
|
|
||||||
// List<String>(90) 中的索引
|
// List<String>(90) 中的索引
|
||||||
int from, to;
|
int from, to;
|
||||||
|
@ -67,7 +67,7 @@ class Move {
|
||||||
String counterMarks;
|
String counterMarks;
|
||||||
|
|
||||||
Move(this.from, this.to,
|
Move(this.from, this.to,
|
||||||
{this.captured = Piece.Empty, this.counterMarks = '0 0'}) {
|
{this.captured = Piece.noPiece, this.counterMarks = '0 0'}) {
|
||||||
//
|
//
|
||||||
fx = from % 9;
|
fx = from % 9;
|
||||||
fy = from ~/ 9;
|
fy = from ~/ 9;
|
||||||
|
@ -104,7 +104,7 @@ class Move {
|
||||||
from = fx + fy * 9;
|
from = fx + fy * 9;
|
||||||
to = tx + ty * 9;
|
to = tx + ty * 9;
|
||||||
|
|
||||||
captured = Piece.Empty;
|
captured = Piece.noPiece;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool validateEngineStep(String step) {
|
static bool validateEngineStep(String step) {
|
||||||
|
|
|
@ -26,7 +26,7 @@ class MillRecorder {
|
||||||
}
|
}
|
||||||
void stepIn(Move move, Position position) {
|
void stepIn(Move move, Position position) {
|
||||||
//
|
//
|
||||||
if (move.captured != Piece.Empty) {
|
if (move.captured != Piece.noPiece) {
|
||||||
halfMove = 0;
|
halfMove = 0;
|
||||||
} else {
|
} else {
|
||||||
halfMove++;
|
halfMove++;
|
||||||
|
@ -40,7 +40,7 @@ class MillRecorder {
|
||||||
|
|
||||||
_history.add(move);
|
_history.add(move);
|
||||||
|
|
||||||
if (move.captured != Piece.Empty) {
|
if (move.captured != Piece.noPiece) {
|
||||||
lastCapturedPosition = position.toFen();
|
lastCapturedPosition = position.toFen();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ class MillRecorder {
|
||||||
List<Move> moves = [];
|
List<Move> moves = [];
|
||||||
|
|
||||||
for (var i = _history.length - 1; i >= 0; i--) {
|
for (var i = _history.length - 1; i >= 0; i--) {
|
||||||
if (_history[i].captured != Piece.Empty) break;
|
if (_history[i].captured != Piece.noPiece) break;
|
||||||
moves.add(_history[i]);
|
moves.add(_history[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ class Position {
|
||||||
_board = List<String>(64); // 7 * 7
|
_board = List<String>(64); // 7 * 7
|
||||||
|
|
||||||
for (var i = 0; i < 64; i++) {
|
for (var i = 0; i < 64; i++) {
|
||||||
_board[i] ??= Piece.Empty;
|
_board[i] ??= Piece.noPiece;
|
||||||
}
|
}
|
||||||
|
|
||||||
_recorder = MillRecorder(lastCapturedPosition: toFen());
|
_recorder = MillRecorder(lastCapturedPosition: toFen());
|
||||||
|
@ -48,7 +48,7 @@ class Position {
|
||||||
|
|
||||||
// 修改棋盘
|
// 修改棋盘
|
||||||
_board[to] = _board[from];
|
_board[to] = _board[from];
|
||||||
_board[from] = Piece.Empty;
|
_board[from] = Piece.noPiece;
|
||||||
|
|
||||||
// 交换走棋方
|
// 交换走棋方
|
||||||
_sideToMove = Side.opponent(_sideToMove);
|
_sideToMove = Side.opponent(_sideToMove);
|
||||||
|
@ -70,7 +70,7 @@ class Position {
|
||||||
//
|
//
|
||||||
// 修改棋盘
|
// 修改棋盘
|
||||||
_board[move.to] = _board[move.from];
|
_board[move.to] = _board[move.from];
|
||||||
_board[move.from] = Piece.Empty;
|
_board[move.from] = Piece.noPiece;
|
||||||
|
|
||||||
// 交换走棋方
|
// 交换走棋方
|
||||||
if (turnSide) _sideToMove = Side.opponent(_sideToMove);
|
if (turnSide) _sideToMove = Side.opponent(_sideToMove);
|
||||||
|
@ -90,7 +90,7 @@ class Position {
|
||||||
_recorder.halfMove = counterMarks.halfMove;
|
_recorder.halfMove = counterMarks.halfMove;
|
||||||
_recorder.fullMove = counterMarks.fullMove;
|
_recorder.fullMove = counterMarks.fullMove;
|
||||||
|
|
||||||
if (lastMove.captured != Piece.Empty) {
|
if (lastMove.captured != Piece.noPiece) {
|
||||||
//
|
//
|
||||||
// 查找上一个吃子局面(或开局),NativeEngine 需要
|
// 查找上一个吃子局面(或开局),NativeEngine 需要
|
||||||
final tempPosition = Position.clone(this);
|
final tempPosition = Position.clone(this);
|
||||||
|
@ -124,7 +124,7 @@ class Position {
|
||||||
//
|
//
|
||||||
final piece = pieceAt((file - 1) * 8 + rank + 8);
|
final piece = pieceAt((file - 1) * 8 + rank + 8);
|
||||||
|
|
||||||
if (piece == Piece.Empty) {
|
if (piece == Piece.noPiece) {
|
||||||
//
|
//
|
||||||
emptyCounter++;
|
emptyCounter++;
|
||||||
//
|
//
|
||||||
|
@ -157,7 +157,7 @@ class Position {
|
||||||
var steps = '', posAfterLastCaptured = 0;
|
var steps = '', posAfterLastCaptured = 0;
|
||||||
|
|
||||||
for (var i = _recorder.stepsCount - 1; i >= 0; i--) {
|
for (var i = _recorder.stepsCount - 1; i >= 0; i--) {
|
||||||
if (_recorder.stepAt(i).captured != Piece.Empty) break;
|
if (_recorder.stepAt(i).captured != Piece.noPiece) break;
|
||||||
posAfterLastCaptured = i;
|
posAfterLastCaptured = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ class _BattlePageState extends State<BattlePage> {
|
||||||
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) {
|
||||||
//
|
//
|
||||||
// 当前点击的棋子和之前已经选择的是同一个位置
|
// 当前点击的棋子和之前已经选择的是同一个位置
|
||||||
|
@ -86,7 +86,7 @@ class _BattlePageState extends State<BattlePage> {
|
||||||
//
|
//
|
||||||
} else {
|
} else {
|
||||||
// 之前未选择棋子,现在点击就是选择棋子
|
// 之前未选择棋子,现在点击就是选择棋子
|
||||||
if (tapedPiece != Piece.Empty) Battle.shared.select(index);
|
if (tapedPiece != Piece.noPiece) Battle.shared.select(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
setState(() {});
|
setState(() {});
|
||||||
|
|
Loading…
Reference in New Issue