src/main/java/ru/alphatech/icfpc/cards/Attack.java
changeset 67 e2df2fbc6e8e
parent 64 8ce8964b584f
child 68 a84a3c755d93
equal deleted inserted replaced
66:8c820ab3cd8a 67:e2df2fbc6e8e
     6 import ru.alphatech.icfpc.game.Value;
     6 import ru.alphatech.icfpc.game.Value;
     7 
     7 
     8 public class Attack implements ICard
     8 public class Attack implements ICard
     9 {
     9 {
    10 	@Override
    10 	@Override
    11 	public IValue returnValue(final IValue i, Player proponent, Player opponent)
    11 	public IValue returnValue(final IValue iobj, Player proponent, Player opponent)
    12 	{
    12 	{
    13 		return new ICard()
    13 		return new ICard()
    14 		{
    14 		{
    15 			@Override
    15 			@Override
    16 			public IValue returnValue(final IValue j, Player proponent, Player opponent)
    16 			public IValue returnValue(final IValue jobj, Player proponent, Player opponent)
    17 			{
    17 			{
    18 				return new ICard()
    18 				return new ICard()
    19 				{
    19 				{
    20 					@Override
    20 					@Override
    21 					public IValue returnValue(final IValue n, Player proponent, Player opponent)
    21 					public IValue returnValue(final IValue nobj, Player proponent, Player opponent)
    22 					{
    22 					{
    23 						if (i.getClass().equals(Value.class) && j.getClass().equals(Value.class) && n.getClass().equals(Value.class))
    23 						if(iobj instanceof Value && nobj instanceof Value)
    24 						{
    24 						{
    25 							int ival = ((Value)i).getValue();
    25 							int i = ((Value)iobj).getValue();
    26 							int jval = ((Value)j).getValue();
    26 							int n = ((Value)nobj).getValue();
    27 							int nval = ((Value)n).getValue();
    27 							int v = proponent.getSlot(i).getVitality();
       
    28 							
       
    29 							if(i >= 0 && i <= 255 && n <= v)
       
    30 							{
       
    31 								if(jobj instanceof Value)
       
    32 								{
       
    33 									int j = ((Value)jobj).getValue();
       
    34 									
       
    35 									if(j >= 0 && j <= 255)
       
    36 									{
       
    37 										int w = opponent.getSlot(255 - j).getVitality();
       
    38 										
       
    39 										if (w > 0)
       
    40 										{
       
    41 											int wdec = (int) Math.floor(9 * n / 10);
       
    42 											int resw = w - wdec;
    28 
    43 
    29 							if (ival >= 0 && ival < 256 && jval >= 0 && jval < 256)
    44 											opponent.getSlot(255 - j).setVitality(resw < 0 ? 0 : w);
    30 							{
    45 										}
    31 								int v = proponent.getSlot(ival).getVitality();
    46 
    32 								int w = opponent.getSlot(255 - jval).getVitality();
    47 										return new I();
    33 								if (v - nval < 1)
    48 									}
    34 								{
    49 									else
    35 									proponent.getSlot(ival).setVitality(v - nval);
       
    36 									if (w > 0)
       
    37 									{
    50 									{
    38 										opponent.getSlot(255 - jval).setVitality(w - ((9 * nval)/10));
    51 										throw new ICFPCException();
    39 									}
    52 									}
    40 								}
    53 								}
    41 								else
    54 								else
    42 								{
    55 								{
    43 									throw new ICFPCException();
    56 									throw new ICFPCException();
    50 						}
    63 						}
    51 						else
    64 						else
    52 						{
    65 						{
    53 							throw new ICFPCException();
    66 							throw new ICFPCException();
    54 						}
    67 						}
    55 						return new I();
       
    56 					}
    68 					}
    57 				};
    69 				};
    58 			}
    70 			}
    59 		};
    71 		};
    60 	}
    72 	}