From 5912b49356922275a8e9e8db46ab9e278de4d608 Mon Sep 17 00:00:00 2001 From: Quentin Legot Date: Tue, 26 Oct 2021 17:17:06 +0200 Subject: [PATCH] Partially fix GridTest.java --- .../server/games/player/AbstractPlayer.java | 2 +- .../java/fr/lnl/game/server/GridTest.java | 24 ++++++++----------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/server/src/main/java/fr/lnl/game/server/games/player/AbstractPlayer.java b/server/src/main/java/fr/lnl/game/server/games/player/AbstractPlayer.java index e174fb5..c25567e 100644 --- a/server/src/main/java/fr/lnl/game/server/games/player/AbstractPlayer.java +++ b/server/src/main/java/fr/lnl/game/server/games/player/AbstractPlayer.java @@ -24,7 +24,7 @@ public abstract class AbstractPlayer implements Player { } public boolean isAlive(){ - return true; + return energy > 0; } public int getId() { diff --git a/server/src/test/java/fr/lnl/game/server/GridTest.java b/server/src/test/java/fr/lnl/game/server/GridTest.java index 783f917..815f1e5 100644 --- a/server/src/test/java/fr/lnl/game/server/GridTest.java +++ b/server/src/test/java/fr/lnl/game/server/GridTest.java @@ -51,22 +51,18 @@ public class GridTest { while (!game.isOver()){ Random random = new Random(); Action action = null; - do { - action = game.getCurrentPlayer().getActions()[random.nextInt(0,game.getCurrentPlayer().getActions().length -1)]; - }while (!action.isPossible()); + while ((action == null || !action.isPossible()) && game.getCurrentPlayer().getActions().length != 0) { + if(game.getCurrentPlayer().getActions().length == 1) { + action = game.getCurrentPlayer().getActions()[0]; + } else { + action = game.getCurrentPlayer().getActions()[random.nextInt(0,game.getCurrentPlayer().getActions().length -1)]; + } + + } action.doAction(); System.out.println(game.getGrid().toString()); - if(game.getCurrentPlayer().getEnergy() <= 0){ - game.decrementPlayers(game.getCurrentPlayer()); - } - else{ - if(game.getCurrentPlayer() == game.getPlayers().get(0)){ - game.setCurrent_player(game.getPlayers().get(1)); - } - else{ - game.setCurrent_player(game.getPlayers().get(0)); - } - } + game.nextCurrentPlayer(); + } System.out.println("Le joueur gagnant : " + game.getWinner().getId()); }