Partially fix GridTest.java

This commit is contained in:
Quentin Legot 2021-10-26 17:17:06 +02:00
parent 3a31f8485d
commit 5912b49356
2 changed files with 11 additions and 15 deletions

View File

@ -24,7 +24,7 @@ public abstract class AbstractPlayer implements Player {
}
public boolean isAlive(){
return true;
return energy > 0;
}
public int getId() {

View File

@ -51,22 +51,18 @@ public class GridTest {
while (!game.isOver()){
Random random = new Random();
Action action = null;
do {
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)];
}while (!action.isPossible());
}
}
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());
}