/* * CoalitionalDef5DecisionStrategy.java * * Created on May 26, 2004, 1:24 AM */ package simulations.core.strategy.decisionSupportStrategy; import java.util.ArrayList; import java.util.Iterator; import simulations.core.Player; import simulations.core.history.PlayerTurn; /** * This class describes a decison support strategy that ack players that accept * attack from players in my coalition vs players that are not in my coalition * (definition 5) from last turn * @author tom */ public class CoalitionalDef5DecisionStrategy extends DecisionSupportStrategy { /** The coalition **/ private ArrayList lastTurnCoalition; /** Creates a new instance of CoalitionalDef5DecisionStrategy */ public CoalitionalDef5DecisionStrategy() { super(); name="CoalitionalDef5DecisionStrategy"; negative=false; lastTurnCoalition=new ArrayList(); memoryParam=false; abr="14"; } /** return the description of this decision support strategy * @return return the description of this decision support strategy **/ public String getDescription() { return "Asking strategy : I accept to help players\n"+ "that are in my coalition and attack a player that is\n"+ "not in my coalition (definition 5)\n"; } /** * return true if the player will support the attack. * @return return true if the player will support the attack. * @param playerList The list of remaining players * @param player The owner of the strategy * @param attackingPlayer The attacking player * @param attackedPlayer The attacked player */ public boolean supportAttack(Player player, Player attackingPlayer, Player attackedPlayer, ArrayList playerList) { if (simulations.SimulationParameters.debug) { System.out.println("CoalDef5DecisionStrat : coalList = "+lastTurnCoalition.toString()); System.out.println("player = "+player.toString()); System.out.println("attackingPlayer = "+attackingPlayer.toString()); System.out.println("attackedPlayer = "+attackedPlayer.toString()); } if (player.equals(attackedPlayer)) { return false; } ArrayList l = new ArrayList(); Iterator it = lastTurnCoalition.iterator(); while (it.hasNext()) { ArrayList l2 = (ArrayList)it.next(); Iterator it2 = l2.iterator(); while (it2.hasNext()) { Player p = (Player)it2.next(); if (!(l.contains(p))) { if (!(p.equals(player))) { l.add(p); } } } } if (!(l.contains(attackingPlayer))) { if (simulations.SimulationParameters.debug) { System.out.println("false car j attaquant pas ds ma coal"); } if (negative) { return true; } else { return false; } } if (l.contains(attackedPlayer)) { if (simulations.SimulationParameters.debug) { System.out.println("false car j attaque ds ma coal"); } if (negative) { return true; } else { return false; } } if (simulations.SimulationParameters.debug) { System.out.println("true"); } if (negative) { return true; } else { return true; } } /** * This method is called by the judge after the decision of players to attack and to ask supports * to inform the strategy * @param player The owner of the strategy * @param attacksList The list of attacks **/ public void updateAttacksInfos(Player player, ArrayList attacksList) { } /** 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) { // Construct coalition list ArrayList l = new ArrayList(); for(int i=0;i