src/main/java/ru/alphatech/icfpc/cards/Help.java
author indvdum
Sun, 19 Jun 2011 15:38:01 +0400
changeset 74 b277f6c31f5f
parent 68 a84a3c755d93
child 79 0bfd181c663e
permissions -rw-r--r--
+ cards names
     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 String getName() {
    12 		return "help";
    13 	}
    14 	
    15 	@Override
    16 	public IValue returnValue(final IValue iobj, Player proponent, Player opponent)
    17 	{
    18 		return new ICard()
    19 		{
    20 			@Override
    21 			public String getName() {
    22 				return "";
    23 			}
    24 			
    25 			@Override
    26 			public IValue returnValue(final IValue jobj, Player proponent, Player opponent)
    27 			{
    28 				return new ICard()
    29 				{
    30 					@Override
    31 					public String getName() {
    32 						return "";
    33 					}
    34 					
    35 					@Override
    36 					public IValue returnValue(final IValue nobj, Player proponent, Player opponent)
    37 					{
    38 						if(iobj instanceof Value && nobj instanceof Value)
    39 						{
    40 							int i = ((Value)iobj).getValue();
    41 							int n = ((Value)nobj).getValue();
    42 							
    43 							if(i >= 0 && i <= 255)
    44 							{
    45 								int v = proponent.getSlot(i).getVitality();
    46 								
    47 								if(n <= v)
    48 								{
    49 									if(jobj instanceof Value)
    50 									{
    51 										int j = ((Value)jobj).getValue();
    52 										
    53 										if(j >= 0 && j <= 255)
    54 										{
    55 											int w = proponent.getSlot(j).getVitality();
    56 											
    57 											if(w > 0)
    58 											{
    59 												int winc = (int) Math.floor(11 * n / 10);
    60 												int resw = w + winc;
    61 												
    62 												proponent.getSlot(j).setVitality(resw > 65535 ? 65535 : resw);
    63 											}
    64 											
    65 											return new I();
    66 										}
    67 										else
    68 										{
    69 											throw new ICFPCException();
    70 										}
    71 									}
    72 									else
    73 									{
    74 										throw new ICFPCException();
    75 									}
    76 								}
    77 								else
    78 								{
    79 									throw new ICFPCException();
    80 								}
    81 							}
    82 							else
    83 							{
    84 								throw new ICFPCException();
    85 							}
    86 						}
    87 						else
    88 						{
    89 							throw new ICFPCException();
    90 						}
    91 					}
    92 				};
    93 			}
    94 		};
    95 	}
    96 }