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