/*
* AttackAttackedPlayersStrategy.java
*
* Created on April 21, 2004, 2:33 AM
*/
package simulations.core.strategy.attackStrategy;
import simulations.core.strategy.PlayerIntElement;
import simulations.core.Player;
import simulations.core.Attack;
import simulations.core.history.PlayerTurn;
import java.util.ArrayList;
import java.util.Iterator;
/**
* This class describes a strategy that attack only the players that I have already attacked
* @author tom
*/
public class AttackAttackedPlayersStrategy 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 AttackAttackedPlayersStrategy() {
super();
attackList = new ArrayList();
name="AttackAttackedPlayersStrategy";
memoryParam=true;
abr="1";
}
/** 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"+
"memory="+memory+" COMPLEMENTARY\n";
} else {
return "Attack strategy \n"+
"I attack the player that I have already attacked\n"+
"memory="+memory+"\n";
}
}
/** return the player to attack
* @param player The attacking player
* @param playerList The list of avalaible 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 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;i