src/main/java/ru/alphatech/icfpc/cards/Attack.java
author indvdum
Mon, 20 Jun 2011 02:00:52 +0400
changeset 125 292347b71221
parent 102 cc814352ab43
child 140 9ddaa68cccae
permissions -rw-r--r--
* merge:
     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 Attack extends AbstractCard
    10 {
    11 	@Override
    12 	public String getName() {
    13 		return "attack";
    14 	}
    15 
    16 	@Override
    17 	public IValue returnValue(final IValue iobj, Player proponent, Player opponent)
    18 	{
    19 		return new AbstractCard()
    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 				incAndTest();
    30 				
    31 				return new AbstractCard()
    32 				{
    33 					@Override
    34 					public String getName() {
    35 						return "";
    36 					}
    37 					@Override
    38 					public IValue returnValue(final IValue nobj, Player proponent, Player opponent)
    39 					{
    40 						incAndTest();
    41 						
    42 						if(iobj instanceof Value && nobj instanceof Value)
    43 						{
    44 							int i = ((Value)iobj).getValue();
    45 							int n = ((Value)nobj).getValue();
    46 							
    47 							if(i >= 0 && i <= 255)
    48 							{
    49 								int v = proponent.getSlot(i).getVitality();
    50 
    51 								if(n <= v)
    52 								{
    53 									if(jobj instanceof Value)
    54 									{
    55 										int j = ((Value)jobj).getValue();
    56 										
    57 										if(j >= 0 && j <= 255)
    58 										{
    59 											int w = opponent.getSlot(255 - j).getVitality();
    60 											
    61 											if(Run.getAutoMode())
    62 											{
    63 												if(w > 0)
    64 												{
    65 													int wdec = (int) Math.floor(9 * n / 10);
    66 													int resw = w + wdec;
    67 
    68 													opponent.getSlot(255 - j).setVitality(resw > 65535 ? 65535 : w);
    69 												}
    70 											}
    71 											else
    72 											{
    73 												if (w > 0)
    74 												{
    75 													int wdec = (int) Math.floor(9 * n / 10);
    76 													int resw = w - wdec;
    77 
    78 													opponent.getSlot(255 - j).setVitality(resw < 0 ? 0 : w);
    79 												}
    80 											}											
    81 
    82 											return new I();
    83 										}
    84 										else
    85 										{
    86 											throw new ICFPCException();
    87 										}
    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 				};
   110 			}
   111 		};
   112 	}
   113 
   114 }