src/main/java/ru/alphatech/icfpc/cards/Help.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 Help implements ICard
     8 public class Help 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 							if (ival >= 0 && ival < 256 && jval >= 0 && jval < 256)
    28 							
       
    29 							if(i >= 0 && i <= 255 && n <= v)
    29 							{
    30 							{
    30 								int v = proponent.getSlot(ival).getVitality();
    31 								if(jobj instanceof Value)
    31 								int w = proponent.getSlot(jval).getVitality();
       
    32 
       
    33 								if (v > nval)
       
    34 								{
    32 								{
    35 									proponent.getSlot(ival).setVitality(v - nval);
    33 									int j = ((Value)jobj).getValue();
    36 									if (w > 0)
    34 									
       
    35 									if(j >= 0 && j <= 255)
    37 									{
    36 									{
    38 										if (w >= 65535)
    37 										int w = proponent.getSlot(j).getVitality();
       
    38 										
       
    39 										if(w > 0)
    39 										{
    40 										{
    40 											proponent.getSlot(jval).setVitality(65535);
    41 											int winc = (int) Math.floor(11 * n / 10);
       
    42 											int resw = w + winc;
       
    43 											
       
    44 											proponent.getSlot(j).setVitality(resw > 65535 ? 65535 : resw);
    41 										}
    45 										}
    42 										else
    46 										
    43 										{
    47 										return new I();
    44 											proponent.getSlot(jval).setVitality(w + ((11 * nval)/10));
    48 									}
    45 										}
    49 									else
       
    50 									{
       
    51 										throw new ICFPCException();
    46 									}
    52 									}
    47 								}
    53 								}
    48 								else
    54 								else
    49 								{
    55 								{
    50 									throw new ICFPCException();
    56 									throw new ICFPCException();
    52 							}
    58 							}
    53 							else
    59 							else
    54 							{
    60 							{
    55 								throw new ICFPCException();
    61 								throw new ICFPCException();
    56 							}
    62 							}
    57 
       
    58 							return new I();
       
    59 						}
    63 						}
    60 						return null;
    64 						else
       
    65 						{
       
    66 							throw new ICFPCException();
       
    67 						}
    61 					}
    68 					}
    62 				};
    69 				};
    63 			}
    70 			}
    64 		};
    71 		};
    65 	}
    72 	}