From d251da1593cc56fae11093cf50c40e48d6cc693c Mon Sep 17 00:00:00 2001 From: oers Date: Tue, 19 Nov 2024 09:46:36 +0100 Subject: [PATCH] #79 Wrong Disc count --- .../de/earthlingz/oerszebra/DroidZebraTest.java | 16 ++++++++++++++++ .../oerszebra/BoardView/GameStateBoardModel.java | 7 ++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/project/src/androidTest/java/de/earthlingz/oerszebra/DroidZebraTest.java b/project/src/androidTest/java/de/earthlingz/oerszebra/DroidZebraTest.java index 8f55c42d..7b27c68b 100644 --- a/project/src/androidTest/java/de/earthlingz/oerszebra/DroidZebraTest.java +++ b/project/src/androidTest/java/de/earthlingz/oerszebra/DroidZebraTest.java @@ -65,6 +65,22 @@ public void testIssue22() throws InterruptedException { assertSame(32, countSquares(ZebraEngine.PLAYER_BLACK)); } + @Test + public void testIssue79() throws InterruptedException { + Intent intent = new Intent(); + intent.setAction(Intent.ACTION_SEND); + intent.setType("message/rfc822"); + intent.putExtra(Intent.EXTRA_TEXT, "E6F6C4D6F7C3C6C7G6H6C8G8C2B2A2C1G7C5B3B6A6H8E3A3F4A1"); + + zebra.runOnUiThread(() -> zebra.onNewIntent(intent)); + waitForOpenendDialogs(false); + assertSame(34, countSquares(ZebraEngine.PLAYER_EMPTY)); + assertSame(15, countSquares(ZebraEngine.PLAYER_WHITE)); + assertSame(15, countSquares(ZebraEngine.PLAYER_BLACK)); + assertSame(32,zebra.getState().getBlackScore()); + assertSame(32,zebra.getState().getWhiteScore()); + } + @Test public void testCrash1() throws InterruptedException { Intent intent = new Intent(); diff --git a/project/src/main/java/de/earthlingz/oerszebra/BoardView/GameStateBoardModel.java b/project/src/main/java/de/earthlingz/oerszebra/BoardView/GameStateBoardModel.java index 1ec7a1a9..c8084d0e 100644 --- a/project/src/main/java/de/earthlingz/oerszebra/BoardView/GameStateBoardModel.java +++ b/project/src/main/java/de/earthlingz/oerszebra/BoardView/GameStateBoardModel.java @@ -70,7 +70,12 @@ public void processGameOver() { int max = currentBoard.size() * currentBoard.size(); if (getBlackScore() + getWhiteScore() < max) { //adjust result - if (getBlackScore() > getWhiteScore()) { + if (getBlackScore() == getWhiteScore()) { + int empty = max - blackScore - whiteScore; + this.blackScore = blackScore + empty/2; + this.whiteScore = whiteScore + empty/2; + } + else if (getBlackScore() > getWhiteScore()) { this.blackScore = max - getWhiteScore(); } else { this.whiteScore = max - getBlackScore();