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