From 0db7e779ba038a5fbc91aac3049330380bfa2702 Mon Sep 17 00:00:00 2001 From: Steffen Helmke Date: Fri, 14 Jan 2022 17:31:31 +0100 Subject: [PATCH] 4gewinnt: calcScore pointsForAnyRow --- src/main/java/de/tims/viergewinnt/ai/Logic.java | 8 ++++---- src/test/java/de/tims/viergewinnt/ai/LogicTest.java | 9 ++++++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/tims/viergewinnt/ai/Logic.java b/src/main/java/de/tims/viergewinnt/ai/Logic.java index f1c2619..f0cc5e6 100644 --- a/src/main/java/de/tims/viergewinnt/ai/Logic.java +++ b/src/main/java/de/tims/viergewinnt/ai/Logic.java @@ -150,15 +150,15 @@ public class Logic { public int calcScore(int[][] playfield, int player) { int score = 1000; for(int i = 0; i < playfield.length; i++) { + int oldScore = score; for(int j = 0; j < playfield[i].length; j++) { if(playfield[i][j] != 0) { score += 10; } } - } - if(playfield[5][0] != 0 && playfield[5][1] != 0 && playfield[5][2] != 0 - && playfield[5][3] != 0 && playfield[5][4] != 0 && playfield[5][5] != 0) { - score += 60; + if(score - 60 == oldScore) { + score += 60; + } } 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 52ed2bc..e66c8c6 100644 --- a/src/test/java/de/tims/viergewinnt/ai/LogicTest.java +++ b/src/test/java/de/tims/viergewinnt/ai/LogicTest.java @@ -131,10 +131,17 @@ class LogicTest { {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {1, 1, 1, 2, 2, 2}}; + int[][] playfield3 = {{0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {1, 1, 2, 2, 1, 2}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {1, 1, 1, 2, 2, 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("first row filled", playfield2, 1, 1120), + Arguments.of("2 rows filled", playfield3, 1, 1240) ); }