Skip to content

Commit

Permalink
random strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
4ban committed Nov 29, 2018
1 parent f694982 commit c892b41
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/game/strategies/PlayerStrategies/AiRandomStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -234,17 +234,21 @@ protected Void doInBackground() {
unSelectCountries(gameState);
resetToAndFrom(gameState);

gameState.setCountryFrom(attackFromList.get(random.nextInt(attackFromList.size())));
if(attackFromList.size() > 0) {
gameState.setCountryFrom(attackFromList.get(random.nextInt(attackFromList.size())));

List<Country> attackToList = new ArrayList<>();
for (Country country : gameState.getCountryFrom().getNeighbours()) {
if (country.getPlayer() != gameState.getCurrentPlayer()) {
attackToList.add(country);
}
}

List<Country> attackToList = new ArrayList<>();
for (Country country : gameState.getCountryFrom().getNeighbours()){
if (country.getPlayer() != gameState.getCurrentPlayer()){
attackToList.add(country);
if(attackToList.size() > 0) {
gameState.setCountryTo(attackToList.get(random.nextInt(attackToList.size())));
}
}

gameState.setCountryTo(attackToList.get(random.nextInt(attackToList.size())));

if (gameState.getCountryFrom() != null && gameState.getCountryTo() != null) {
String message = gameState.getCurrentPlayer().getName() + " attacks from " + gameState.getCountryFrom().getName() + " to " + gameState.getCountryTo().getName();
gameState.setCurrentTurnPhraseText(message);
Expand Down

0 comments on commit c892b41

Please sign in to comment.