From 5614b7f180e72eb6d7c5a6f57e244681644cb3f7 Mon Sep 17 00:00:00 2001 From: Steffen Helmke Date: Wed, 2 Feb 2022 14:53:34 +0100 Subject: [PATCH] 4gewinnt: refactored and updated GameOver method and tests --- src/main/java/de/tims/viergewinnt/ai/Logic.java | 7 ++++++- src/test/java/de/tims/viergewinnt/ai/LogicTest.java | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/tims/viergewinnt/ai/Logic.java b/src/main/java/de/tims/viergewinnt/ai/Logic.java index a899c8a..4aba921 100644 --- a/src/main/java/de/tims/viergewinnt/ai/Logic.java +++ b/src/main/java/de/tims/viergewinnt/ai/Logic.java @@ -234,6 +234,11 @@ public class Logic { } public void gameover() { - setPlayer1Score(calcScore()); + if(getCurrentPlayer() == 1) { + setPlayer1Score(calcScore()); + } else { + setPlayer2Score(calcScore()); + } + clearField(); } } diff --git a/src/test/java/de/tims/viergewinnt/ai/LogicTest.java b/src/test/java/de/tims/viergewinnt/ai/LogicTest.java index 51e149a..02d6719 100644 --- a/src/test/java/de/tims/viergewinnt/ai/LogicTest.java +++ b/src/test/java/de/tims/viergewinnt/ai/LogicTest.java @@ -184,7 +184,7 @@ class LogicTest { testObj.gameover(); - assertEquals(1010, testObj.getPlayer1Score()); + assertEquals(1010 == testObj.getPlayer1Score(), 0 == testObj.getField(0,0)); } @Test