From 96df3db067f940d6019c0cfc433adbc6bb521ec4 Mon Sep 17 00:00:00 2001 From: Calcitem Date: Sun, 15 Nov 2020 13:14:39 +0800 Subject: [PATCH] =?UTF-8?q?flutter:=20=E5=AE=8C=E6=88=90=20updateScore()?= =?UTF-8?q?=20=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ui/flutter/lib/mill/position.dart | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/ui/flutter/lib/mill/position.dart b/src/ui/flutter/lib/mill/position.dart index 0f30c1ac..d86a67bc 100644 --- a/src/ui/flutter/lib/mill/position.dart +++ b/src/ui/flutter/lib/mill/position.dart @@ -67,9 +67,7 @@ class Position { Phase phase = Phase.none; Act action = Act.none; - int scoreBlack = 0; - int scoreWhite = 0; - int scoreDraw = 0; + Map score = {Color.black: 0, Color.white: 0, Color.draw: 0}; int currentSquare; int nPlayed = 0; @@ -143,9 +141,7 @@ class Position { phase = other.phase; action = other.action; - scoreBlack = other.scoreBlack; - scoreWhite = other.scoreWhite; - scoreDraw = other.scoreDraw; + score = other.score; currentSquare = other.currentSquare; nPlayed = other.nPlayed; @@ -158,8 +154,6 @@ class Position { String sideToMove() => _sideToMove; - void updateScore() {} - void setSideToMove(String color) { _sideToMove = color; } @@ -735,6 +729,17 @@ class Position { winner = w; } + void updateScore() { + if (phase == Phase.gameOver) { + if (winner == Color.draw) { + score[Color.draw]++; + return; + } + + score[winner]++; + } + } + bool checkGameOverCondition() { if (phase == Phase.ready || phase == Phase.gameOver) { return true;