flutter: 完成 checkGameOverCondition() 等函数
This commit is contained in:
parent
77208226c1
commit
37cd709ff0
|
@ -62,6 +62,7 @@ class Color {
|
||||||
static const white = 'O';
|
static const white = 'O';
|
||||||
static const ban = 'X';
|
static const ban = 'X';
|
||||||
static const nobody = '-';
|
static const nobody = '-';
|
||||||
|
static const draw = '=';
|
||||||
|
|
||||||
static String of(String piece) {
|
static String of(String piece) {
|
||||||
if (black.contains(piece)) return black;
|
if (black.contains(piece)) return black;
|
||||||
|
|
|
@ -729,6 +729,49 @@ class Position {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setGameOver(String w, GameOverReason reason) {
|
||||||
|
phase = Phase.gameOver;
|
||||||
|
gameOverReason = reason;
|
||||||
|
winner = w;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool checkGameOverCondition() {
|
||||||
|
if (phase == Phase.ready || phase == Phase.gameOver) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (rule.maxStepsLedToDraw > 0 && rule50 > rule.maxStepsLedToDraw) {
|
||||||
|
winner = Color.draw;
|
||||||
|
phase = Phase.gameOver;
|
||||||
|
gameOverReason = GameOverReason.drawReasonRule50;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pieceCountOnBoard[Color.black] + pieceCountOnBoard[Color.white] >=
|
||||||
|
rankNumber * fileNumber) {
|
||||||
|
if (rule.isBlackLoseButNotDrawWhenBoardFull) {
|
||||||
|
setGameOver(Color.white, GameOverReason.loseReasonBoardIsFull);
|
||||||
|
} else {
|
||||||
|
setGameOver(Color.draw, GameOverReason.drawReasonBoardIsFull);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (phase == Phase.moving && action == Act.select && isAllSurrounded()) {
|
||||||
|
if (rule.isLoseButNotChangeSideWhenNoWay) {
|
||||||
|
setGameOver(
|
||||||
|
Color.opponent(sideToMove()), GameOverReason.loseReasonNoWay);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
changeSideToMove(); // TODO: Need?
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void removeBanStones() {
|
void removeBanStones() {
|
||||||
assert(rule.hasBannedLocations);
|
assert(rule.hasBannedLocations);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue