flutter: 完成 updateScore() 函数

This commit is contained in:
Calcitem 2020-11-15 13:14:39 +08:00
parent 37cd709ff0
commit 96df3db067
1 changed files with 13 additions and 8 deletions

View File

@ -67,9 +67,7 @@ class Position {
Phase phase = Phase.none; Phase phase = Phase.none;
Act action = Act.none; Act action = Act.none;
int scoreBlack = 0; Map<String, int> score = {Color.black: 0, Color.white: 0, Color.draw: 0};
int scoreWhite = 0;
int scoreDraw = 0;
int currentSquare; int currentSquare;
int nPlayed = 0; int nPlayed = 0;
@ -143,9 +141,7 @@ class Position {
phase = other.phase; phase = other.phase;
action = other.action; action = other.action;
scoreBlack = other.scoreBlack; score = other.score;
scoreWhite = other.scoreWhite;
scoreDraw = other.scoreDraw;
currentSquare = other.currentSquare; currentSquare = other.currentSquare;
nPlayed = other.nPlayed; nPlayed = other.nPlayed;
@ -158,8 +154,6 @@ class Position {
String sideToMove() => _sideToMove; String sideToMove() => _sideToMove;
void updateScore() {}
void setSideToMove(String color) { void setSideToMove(String color) {
_sideToMove = color; _sideToMove = color;
} }
@ -735,6 +729,17 @@ class Position {
winner = w; winner = w;
} }
void updateScore() {
if (phase == Phase.gameOver) {
if (winner == Color.draw) {
score[Color.draw]++;
return;
}
score[winner]++;
}
}
bool checkGameOverCondition() { bool checkGameOverCondition() {
if (phase == Phase.ready || phase == Phase.gameOver) { if (phase == Phase.ready || phase == Phase.gameOver) {
return true; return true;