Browse Source

4gewinnt: calcScore pointsForAnyRow

4gewinnt
Steffen Helmke 3 years ago
committed by Lorenz Hohmann
parent
commit
0db7e779ba
  1. 6
      src/main/java/de/tims/viergewinnt/ai/Logic.java
  2. 9
      src/test/java/de/tims/viergewinnt/ai/LogicTest.java

6
src/main/java/de/tims/viergewinnt/ai/Logic.java

@ -150,16 +150,16 @@ 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) {
if(score - 60 == oldScore) {
score += 60;
}
}
return score;
}
}

9
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)
);
}

Loading…
Cancel
Save