/* * AskingPlayersDontAttackMeStrategy.java * * Created on April 23, 2004, 1:42 AM */ package simulations.core.strategy.askingSupportStrategy; import simulations.core.Player; import simulations.core.strategy.PlayerIntElement; import java.util.ArrayList; import java.util.Iterator; import simulations.core.history.Turn; import simulations.core.history.PlayerTurn; /** * This class describes an asking strategy that ask to all players * that have never attack directly me * @author tom */ public class AskingPlayersDontAttackMeStrategy extends AskingStrategy { /** This list store the players that have never attack me directly **/ private ArrayList notAskingList; /** True if its the first called of this strategy **/ private boolean first; /** Creates a new instance of AskingPlayersDontAttackMeStrategy */ public AskingPlayersDontAttackMeStrategy() { super(); name="AskingPlayersDontAttackMeStrategy"; notAskingList=new ArrayList(); first=true; memoryParam=true; abr="3"; } /** This method returns the description of the strategy * @return returns the description of the strategy */ public String getDescription() { if (negative) { return "Asking support strategy :\n"+ "I ask to all players that have never\n"+ "attacked me directly memory="+memory+"\n"+ "COMPLEMENTARY"; } else { return "Asking support strategy :\n"+ "I ask to all players that have never\n"+ "attacked me directly memory="+memory+"\n"; } } /** This method returns true if the player p is already in notAskingList * @return true if the player p is already in notAskingList false otherwise **/ private boolean containsPlayer(Player p) { for(int i=0;iavalaible player */ public java.util.ArrayList getPlayersToAskSupport(simulations.core.Player player, simulations.core.Player attackedPlayer, java.util.ArrayList playerList) { if (simulations.SimulationParameters.debug) { System.out.println("notAskingList = "+notAskingList); } ArrayList l = new ArrayList(); if (negative) { Iterator it = playerList.iterator(); while (it.hasNext()) { Player p = (Player)it.next(); if (containsPlayer(p)) { l.add(p); } } } else { Iterator it = playerList.iterator(); while (it.hasNext()) { Player p = (Player)it.next(); if (!(containsPlayer(p))) { l.add(p); } } } if (simulations.SimulationParameters.debug) { System.out.println("l = "+l); } return l; } /** This method is called by the judge to inform players of the last turn * @param turn The turn * @param player The owner of the strategy * @param remainingPlayers The list of the remaining players */ public void updateLastTurn(simulations.core.history.Turn turn, simulations.core.Player player, java.util.ArrayList remainingPlayers) { // remove dead players for(int i=0;i