From 9f995384062795380f29fa01598038a9e6246278 Mon Sep 17 00:00:00 2001 From: Steffen Helmke Date: Fri, 14 Jan 2022 18:40:53 +0100 Subject: [PATCH] 4gewinnt: calcScore refactored --- .../java/de/tims/viergewinnt/ai/Logic.java | 10 +++++----- .../de/tims/viergewinnt/ai/LogicTest.java | 20 +++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/main/java/de/tims/viergewinnt/ai/Logic.java b/src/main/java/de/tims/viergewinnt/ai/Logic.java index e79bcf8..d4a20aa 100644 --- a/src/main/java/de/tims/viergewinnt/ai/Logic.java +++ b/src/main/java/de/tims/viergewinnt/ai/Logic.java @@ -147,7 +147,7 @@ public class Logic { return false; } - public int calcScore(int[][] playfield, int player) { + public int calcScore(int[][] playfield) { int score = 1000; for(int i = 0; i < playfield.length; i++) { int oldScore = score; @@ -156,8 +156,8 @@ public class Logic { score += 10; } } - if(score - 60 == oldScore) { - score += 60; + if(score - (10 * playfield[0].length) == oldScore) { + score += (10 * playfield[0].length); } } for(int i = 0; i < playfield[0].length; i++) { @@ -166,11 +166,11 @@ public class Logic { break; } if(j == playfield.length - 1) { - score += 60; + score += (10 * playfield.length); } } } - if(score == 2080) { + if(score == (1000 + 3 * (10 * playfield.length * playfield[0].length))) { score += 500; } return score; diff --git a/src/test/java/de/tims/viergewinnt/ai/LogicTest.java b/src/test/java/de/tims/viergewinnt/ai/LogicTest.java index 0531164..d37645c 100644 --- a/src/test/java/de/tims/viergewinnt/ai/LogicTest.java +++ b/src/test/java/de/tims/viergewinnt/ai/LogicTest.java @@ -68,11 +68,11 @@ class LogicTest { assertEquals(expectedResult, realResult); } - @ParameterizedTest(name = "[{index}] {0} Win for Player {2} {1}") + @ParameterizedTest(name = "[{index}] {0} with {1}") @MethodSource("playfieldForScore") - void calcScoreTest(String testName, int[][] playfield, int player, int expectedResult) { + void calcScoreTest(String testName, int[][] playfield, int expectedResult) { - int realResult = testObj.calcScore(playfield, player); + int realResult = testObj.calcScore(playfield); assertEquals(expectedResult, realResult); } @@ -156,13 +156,13 @@ class LogicTest { {2, 1, 2, 2, 1, 2}, {2, 1, 2, 2, 1, 2}}; return Stream.of( - Arguments.of("emptyField", new int[6][6], 1, 1000), - Arguments.of("9 chips played", playfield1, 1, 1090), - Arguments.of("first row filled", playfield2, 1, 1120), - Arguments.of("2 rows filled", playfield3, 1, 1240), - Arguments.of("first column filled", playfield4, 1, 1120), - Arguments.of("2 column filled", playfield5, 1, 1240), - Arguments.of("fullyFilled", playfield6, 1, 2580) + Arguments.of("emptyField", new int[6][6], 1000), + Arguments.of("9 chips played", playfield1, 1090), + Arguments.of("first row filled", playfield2, 1120), + Arguments.of("2 rows filled", playfield3, 1240), + Arguments.of("first column filled", playfield4, 1120), + Arguments.of("2 column filled", playfield5, 1240), + Arguments.of("fullyFilled", playfield6, 2580) ); }