src/main/java/ru/alphatech/icfpc/cards/Help.java
author akhmetovlz
Sun, 19 Jun 2011 16:52:20 +0400
changeset 76 5955cb5e5ef3
parent 68 a84a3c755d93
child 74 b277f6c31f5f
permissions -rw-r--r--
policies
     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 							
    28 							if(i >= 0 && i <= 255)
    29 							{
    30 								int v = proponent.getSlot(i).getVitality();
    31 								
    32 								if(n <= v)
    33 								{
    34 									if(jobj instanceof Value)
    35 									{
    36 										int j = ((Value)jobj).getValue();
    37 										
    38 										if(j >= 0 && j <= 255)
    39 										{
    40 											int w = proponent.getSlot(j).getVitality();
    41 											
    42 											if(w > 0)
    43 											{
    44 												int winc = (int) Math.floor(11 * n / 10);
    45 												int resw = w + winc;
    46 												
    47 												proponent.getSlot(j).setVitality(resw > 65535 ? 65535 : resw);
    48 											}
    49 											
    50 											return new I();
    51 										}
    52 										else
    53 										{
    54 											throw new ICFPCException();
    55 										}
    56 									}
    57 									else
    58 									{
    59 										throw new ICFPCException();
    60 									}
    61 								}
    62 								else
    63 								{
    64 									throw new ICFPCException();
    65 								}
    66 							}
    67 							else
    68 							{
    69 								throw new ICFPCException();
    70 							}
    71 						}
    72 						else
    73 						{
    74 							throw new ICFPCException();
    75 						}
    76 					}
    77 				};
    78 			}
    79 		};
    80 	}
    81 }