src/main/java/ru/alphatech/icfpc/cards/Help.java
author Azamat S. Kalimoulline <turtle@bazon.ru>
Tue, 21 Jun 2011 11:55:31 +0400
changeset 140 9ddaa68cccae
parent 102 cc814352ab43
permissions -rw-r--r--
Cards bugs revealed.
     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 "help(" + iobj + ")";
    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 "help(" + iobj + ")(" + jobj + ")";
    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 									proponent.getSlot(i).setVitality(v - n);
    57 									
    58 									if(jobj instanceof Value)
    59 									{
    60 										int j = ((Value)jobj).getValue();
    61 										
    62 										if(j >= 0 && j <= 255)
    63 										{
    64 											int w = proponent.getSlot(j).getVitality();
    65 											
    66 											if(Run.getAutoMode())
    67 											{
    68 												if(w > 0)
    69 												{
    70 													int winc = (int) Math.floor(11 * n / 10);
    71 													int resw = w - winc;
    72 													
    73 													proponent.getSlot(j).setVitality(resw < 0 ? 0 : resw);
    74 												}
    75 											}
    76 											else
    77 											{
    78 												if(w > 0)
    79 												{
    80 													int winc = (int) Math.floor(11 * n / 10);
    81 													int resw = w + winc;
    82 													
    83 													proponent.getSlot(j).setVitality(resw > 65535 ? 65535 : resw);
    84 												}
    85 											}											
    86 											
    87 											return new I();
    88 										}
    89 										else
    90 										{
    91 											throw new ICFPCException();
    92 										}
    93 									}
    94 									else
    95 									{
    96 										throw new ICFPCException();
    97 									}
    98 								}
    99 								else
   100 								{
   101 									throw new ICFPCException();
   102 								}
   103 							}
   104 							else
   105 							{
   106 								throw new ICFPCException();
   107 							}
   108 						}
   109 						else
   110 						{
   111 							throw new ICFPCException();
   112 						}
   113 					}
   114 				};
   115 			}
   116 		};
   117 	}
   118 }