src/main/java/ru/alphatech/icfpc/cards/Attack.java
author indvdum
Sun, 19 Jun 2011 13:38:48 +0400
changeset 56 1ff9e4ee2b02
parent 35 743564afa994
child 64 8ce8964b584f
permissions -rw-r--r--
* merge
     1 package ru.alphatech.icfpc.cards;
     2 
     3 import ru.alphatech.icfpc.game.ICFPCException;
     4 import ru.alphatech.icfpc.game.IValue;
     5 import ru.alphatech.icfpc.game.Player;
     6 import ru.alphatech.icfpc.game.Value;
     7 
     8 public class Attack implements ICard
     9 {
    10 	@Override
    11 	public IValue returnValue(final IValue i, Player proponent, Player opponent)
    12 	{
    13 		return new ICard()
    14 		{
    15 			@Override
    16 			public IValue returnValue(final IValue j, Player proponent, Player opponent)
    17 			{
    18 				return new ICard()
    19 				{
    20 					@Override
    21 					public IValue returnValue(final IValue n, Player proponent, Player opponent)
    22 					{
    23 						if (i.getClass().equals(Value.class) && j.getClass().equals(Value.class) && n.getClass().equals(Value.class))
    24 						{
    25 							int ival = ((Value)i).getValue();
    26 							int jval = ((Value)j).getValue();
    27 							int nval = ((Value)n).getValue();
    28 
    29 							if (ival >= 0 && ival < 256 && jval >= 0 && jval < 256)
    30 							{
    31 								int v = proponent.getSlot(ival).getVitality();
    32 								int w = opponent.getSlot(255 - jval).getVitality();
    33 								if (v - nval < 1)
    34 								{
    35 									proponent.getSlot(ival).setVitality(v - nval);
    36 									if (w > 0)
    37 									{
    38 										opponent.getSlot(255 - jval).setVitality(w - ((9 * nval)/10));
    39 									}
    40 								}
    41 								else
    42 								{
    43 									throw new ICFPCException();
    44 								}
    45 							}
    46 							else
    47 							{
    48 								throw new ICFPCException();
    49 							}
    50 						}
    51 						else
    52 						{
    53 							throw new ICFPCException();
    54 						}
    55 						return new I();
    56 					}
    57 				};
    58 			}
    59 		};
    60 	}
    61 
    62 }