Skip to content

Commit

Permalink
Fixed test bug, setting ai strength
Browse files Browse the repository at this point in the history
  • Loading branch information
jberclaz committed Jul 14, 2024
1 parent 1cc998a commit 5822672
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
10 changes: 8 additions & 2 deletions src/main/java/com/leflat/jass/server/ArtificialPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,18 @@ public class ArtificialPlayer extends AbstractRemotePlayer {
private int ourScore = 0;
private int theirScore = 0;
private int numberOfPliesWonByOwnTeam;
private int strength = 1000;

public ArtificialPlayer(int id, String name) {
super(id);
setName(name);
}

public ArtificialPlayer(int id, String name, int strength) {
this(id, name);
this.strength = strength;
}

@Override
public void setPlayerInfo(BasePlayer player) {
var relativePosition = getInitialRelativePosition(player);
Expand Down Expand Up @@ -246,7 +252,7 @@ private Card chooseBestCard() {
Card bestCard = null;
float bestScore = -1000;
for (Card validCard : validCards) {
var score = evaluateMoveReward(hand, validCard, 10000);
var score = evaluateMoveReward(hand, validCard, strength * 10);
if (score > bestScore) {
bestScore = score;
bestCard = validCard;
Expand Down Expand Up @@ -350,7 +356,7 @@ int chooseBestAtout(boolean canPass) {
}
float maxScore = -10000;
for (var card : hand) {
float score = evaluateMoveReward(hand, card, 1000);
float score = evaluateMoveReward(hand, card, strength);
if (score > maxScore) {
maxScore = score;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/leflat/jass/test/MockNetworkFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.leflat.jass.common.IClientNetworkFactory;

public class MockNetworkFactory implements IClientNetworkFactory {
private static int nbrPlayers = 0;
private int nbrPlayers = 0;

public MockNetworkFactory() {

Expand Down
12 changes: 7 additions & 5 deletions src/test/java/FunctionalTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import com.leflat.jass.server.PlayerLeftExpection;
import com.leflat.jass.test.MockNetworkFactory;
import com.leflat.jass.test.MockUiFactory;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;

public class FunctionalTest {
@Test
Expand All @@ -29,11 +31,11 @@ void functional_test() throws PlayerLeftExpection {
game.addPlayer(player3);
game.addPlayer(player4);

assertTrue(game.isGameFull());
Assertions.assertTrue(game.isGameFull());

game.setNoWait(true);

game.run();
assertDoesNotThrow(() -> {game.run();});
}

@Test
Expand All @@ -48,17 +50,17 @@ void functional_test_with_artificial_player() throws PlayerLeftExpection {
player2.setName("GC");
var player3 = new JassPlayer(clientNetworkFactory, new MockUiFactory());
player3.setName("Pischus");
var player4 = new ArtificialPlayer(3, "Wein");
var player4 = new ArtificialPlayer(3, "Wein", 20);

game.addPlayer(player1);
game.addPlayer(player2);
game.addPlayer(player3);
game.addPlayer(player4);

assertTrue(game.isGameFull());
Assertions.assertTrue(game.isGameFull());

game.setNoWait(true);

game.run();
assertDoesNotThrow(() -> {game.run();});
}
}

0 comments on commit 5822672

Please sign in to comment.