diff --git a/src/game/strategies/PlayerStrategies/AiRandomStrategy.java b/src/game/strategies/PlayerStrategies/AiRandomStrategy.java index a3f227e..8ab52f5 100644 --- a/src/game/strategies/PlayerStrategies/AiRandomStrategy.java +++ b/src/game/strategies/PlayerStrategies/AiRandomStrategy.java @@ -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 attackToList = new ArrayList<>(); + for (Country country : gameState.getCountryFrom().getNeighbours()) { + if (country.getPlayer() != gameState.getCurrentPlayer()) { + attackToList.add(country); + } + } - List 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);