From 44ff79411eebdeaf313b0aa8fbdec589d8194a9c Mon Sep 17 00:00:00 2001 From: Steffen Helmke Date: Wed, 2 Feb 2022 14:41:10 +0100 Subject: [PATCH] 4gewinnt: added clearField method --- src/main/java/de/tims/viergewinnt/ai/Logic.java | 6 +++++- src/test/java/de/tims/viergewinnt/ai/LogicTest.java | 11 ++++++++++- 2 files changed, 15 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 fa0a461..2b7c862 100644 --- a/src/main/java/de/tims/viergewinnt/ai/Logic.java +++ b/src/main/java/de/tims/viergewinnt/ai/Logic.java @@ -30,6 +30,10 @@ public class Logic { return this.board[row][column]; } + public void clearField() { + this.setField(0, 0, 0); + } + public int getBoardSize() { return this.board.length; } @@ -230,6 +234,6 @@ public class Logic { } public void gameover() { - setPlayer1Score(10); + setPlayer1Score(calcScore()); } } diff --git a/src/test/java/de/tims/viergewinnt/ai/LogicTest.java b/src/test/java/de/tims/viergewinnt/ai/LogicTest.java index 6ddeefa..ca8ca7f 100644 --- a/src/test/java/de/tims/viergewinnt/ai/LogicTest.java +++ b/src/test/java/de/tims/viergewinnt/ai/LogicTest.java @@ -184,7 +184,16 @@ class LogicTest { testObj.gameover(); - assertEquals(10, testObj.getPlayer1Score()); + assertEquals(1010, testObj.getPlayer1Score()); + } + + @Test + void clearFieldTest() { + testObj.setField(1, 0, 0); + + testObj.clearField(); + + assertEquals(0, testObj.getField(0, 0)); } @Test