flutter: us 和 them 随着 _sideToMove 的变动而赋值

This commit is contained in:
Calcitem 2020-11-15 22:35:27 +08:00
parent 427816753e
commit 75e9787ab0
2 changed files with 19 additions and 21 deletions

View File

@ -61,9 +61,9 @@ class Position {
StateInfo st;
String us;
String them;
String winner;
String us = Color.black;
String them = Color.white;
String winner = Color.nobody;
GameOverReason gameOverReason = GameOverReason.noReason;
Phase phase = Phase.none;
@ -137,6 +137,8 @@ class Position {
void setSideToMove(String color) {
_sideToMove = color;
us = _sideToMove;
them = Color.opponent(us);
}
String movedPiece(int move) {
@ -201,11 +203,11 @@ class Position {
Position.init() {
for (var i = 0; i < _grid.length; i++) {
_grid[i] ??= Piece.noPiece;
_grid[i] = Piece.noPiece;
}
for (var i = 0; i < board.length; i++) {
board[i] ??= Piece.noPiece;
board[i] = Piece.noPiece;
}
phase = Phase.placing;
@ -1570,20 +1572,6 @@ class Position {
//(StepValidate.validate(this, Move(from, to)));
}
//
//
void moveTest(Move move, {turnSide = false}) {
// TODO
//
_grid[move.to] = _grid[move.from];
_grid[move.from] = Piece.noPiece;
board[move.to] = board[move.from];
board[move.from] = Piece.noPiece;
//
if (turnSide) _sideToMove = Color.opponent(_sideToMove);
}
bool regret() {
// TODO
final lastMove = _recorder.removeLast();
@ -1594,7 +1582,7 @@ class Position {
board[lastMove.from] = board[lastMove.to];
board[lastMove.to] = lastMove.captured;
_sideToMove = Color.opponent(_sideToMove);
changeSideToMove();
final counterMarks = MillRecorder.fromCounterMarks(lastMove.counterMarks);
_recorder.halfMove = counterMarks.halfMove;
@ -1642,7 +1630,10 @@ class Position {
get side => _sideToMove;
changeSideToMove() => _sideToMove = Color.opponent(_sideToMove);
void changeSideToMove() {
them = _sideToMove;
_sideToMove = Color.opponent(_sideToMove);
}
get halfMove => _recorder.halfMove;

View File

@ -293,6 +293,13 @@ class _BattlePageState extends State<BattlePage> {
Navigator.of(context).pop();
Battle.shared.newGame();
setState(() {});
if (Battle.shared.isAIsTurn()) {
print("New Game: AI's turn.");
engineToGo();
}
setState(() {});
}
cancel() => Navigator.of(context).pop();