/* * AttackAttackedPlayersStrategy2.java * * Created on April 21, 2004, 2:33 AM */ package simulations.core.strategy.attackStrategy; import simulations.core.Player; import simulations.core.Attack; import simulations.core.history.PlayerTurn; import simulations.core.strategy.PlayerIntElement; import java.util.ArrayList; import java.util.Iterator; /** * This class describes a strategy that attack only the players that I have already attacked * or that I support an attack versus them * @author tom */ public class AttackAttackedPlayersStrategy2 extends AttackStrategy { /** This list store the player that I have already attack me and are * still in the game **/ private ArrayList attackList; /** Creates a new instance of AttackAttackedPlayersStrategy */ public AttackAttackedPlayersStrategy2() { super(); attackList = new ArrayList(); name="AttackAttackedPlayersStrategy2"; memoryParam=true; abr="2"; } /** return the description of this attack strategy * @return return the description of this attack strategy **/ public String getDescription() { if (negative) { return "Attack strategy \n"+ "I attack the player that I have already attacked\n"+ "directly or indirectly memory="+memory+"\n"+ "COMPLEMENTARY"; } else { return "Attack strategy \n"+ "I attack the player that I have already attacked\n"+ "directly or indirectly 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 * @return The player to attack */ public ArrayList getPlayerToAttack(Player player, ArrayList playerList) { ArrayList l = new ArrayList(); Iterator it = attackList.iterator(); while (it.hasNext()) { l.add(((PlayerIntElement)it.next()).getPlayer()); } if (negative) { ArrayList l2 = new ArrayList(); it = playerList.iterator(); while (it.hasNext()) { Player p = (Player)it.next(); if (p.equals(player)) { continue; } if (!(l.contains(p))) { l2.add(p); } } return l2; } else { 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, Player player, ArrayList remainingPlayers) { for(int i=0;i