Partially fix GridTest.java
This commit is contained in:
parent
3a31f8485d
commit
5912b49356
@ -24,7 +24,7 @@ public abstract class AbstractPlayer implements Player {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAlive(){
|
public boolean isAlive(){
|
||||||
return true;
|
return energy > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId() {
|
public int getId() {
|
||||||
|
@ -51,22 +51,18 @@ public class GridTest {
|
|||||||
while (!game.isOver()){
|
while (!game.isOver()){
|
||||||
Random random = new Random();
|
Random random = new Random();
|
||||||
Action action = null;
|
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)];
|
action = game.getCurrentPlayer().getActions()[random.nextInt(0,game.getCurrentPlayer().getActions().length -1)];
|
||||||
}while (!action.isPossible());
|
}
|
||||||
|
|
||||||
|
}
|
||||||
action.doAction();
|
action.doAction();
|
||||||
System.out.println(game.getGrid().toString());
|
System.out.println(game.getGrid().toString());
|
||||||
if(game.getCurrentPlayer().getEnergy() <= 0){
|
game.nextCurrentPlayer();
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
System.out.println("Le joueur gagnant : " + game.getWinner().getId());
|
System.out.println("Le joueur gagnant : " + game.getWinner().getId());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user