src/main/java/ru/alphatech/icfpc/cards/Help.java
author Azamat S. Kalimoulline <turtle@bazon.ru>
Sun, 19 Jun 2011 14:29:38 +0400
changeset 64 8ce8964b584f
parent 35 743564afa994
child 68 a84a3c755d93
permissions -rw-r--r--
Cards up to help.
     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 Help implements ICard
     9 {
    10 	@Override
    11 	public IValue returnValue(final IValue iobj, Player proponent, Player opponent)
    12 	{
    13 		return new ICard()
    14 		{
    15 			@Override
    16 			public IValue returnValue(final IValue jobj, Player proponent, Player opponent)
    17 			{
    18 				return new ICard()
    19 				{
    20 					@Override
    21 					public IValue returnValue(final IValue nobj, Player proponent, Player opponent)
    22 					{
    23 						if(iobj instanceof Value && nobj instanceof Value)
    24 						{
    25 							int i = ((Value)iobj).getValue();
    26 							int n = ((Value)nobj).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 = proponent.getSlot(j).getVitality();
    38 										
    39 										if(w > 0)
    40 										{
    41 											int winc = (int) Math.floor(11 * n / 10);
    42 											int resw = w + winc;
    43 											
    44 											proponent.getSlot(j).setVitality(resw > 65535 ? 65535 : resw);
    45 										}
    46 										
    47 										return new I();
    48 									}
    49 									else
    50 									{
    51 										throw new ICFPCException();
    52 									}
    53 								}
    54 								else
    55 								{
    56 									throw new ICFPCException();
    57 								}
    58 							}
    59 							else
    60 							{
    61 								throw new ICFPCException();
    62 							}
    63 						}
    64 						else
    65 						{
    66 							throw new ICFPCException();
    67 						}
    68 					}
    69 				};
    70 			}
    71 		};
    72 	}
    73 }