From 6dd8f7a4098905b1fb8970797093cef02efa6240 Mon Sep 17 00:00:00 2001 From: Steffen Helmke Date: Fri, 14 Jan 2022 17:03:26 +0100 Subject: [PATCH] 4gewinnt: calcScore pointsPerChip --- src/main/java/de/tims/viergewinnt/ai/Logic.java | 10 +++++++++- src/test/java/de/tims/viergewinnt/ai/LogicTest.java | 9 ++++++++- 2 files changed, 17 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 db16fdc..368dd08 100644 --- a/src/main/java/de/tims/viergewinnt/ai/Logic.java +++ b/src/main/java/de/tims/viergewinnt/ai/Logic.java @@ -148,6 +148,14 @@ public class Logic { } public int calcScore(int[][] playfield, int player) { - return 0; + int score = 1000; + for(int i = 0; i < playfield.length; i++) { + for(int j = 0; j < playfield[i].length; j++) { + if(playfield[i][j] != 0) { + score += 10; + } + } + } + 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 56c7cb9..97aeda7 100644 --- a/src/test/java/de/tims/viergewinnt/ai/LogicTest.java +++ b/src/test/java/de/tims/viergewinnt/ai/LogicTest.java @@ -119,8 +119,15 @@ class LogicTest { } private static Stream playfieldForScore() { + int[][] playfield1 = {{0, 0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0, 0}, + {0, 0, 1, 2, 0, 0}, + {0, 0, 1, 2, 0, 0}, + {0, 0, 1, 2, 0, 0}, + {0, 0, 1, 1, 2, 0}}; return Stream.of( - Arguments.of("emptyField", new int[6][6], 1, 0) + Arguments.of("emptyField", new int[6][6], 1, 1000), + Arguments.of("9 chips played", playfield1, 1, 1090) ); }