src/main/java/ru/alphatech/icfpc/cards/Attack.java
author indvdum
Sun, 19 Jun 2011 17:14:19 +0400
changeset 83 5940c7605d03
parent 79 0bfd181c663e
child 102 cc814352ab43
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 implements ICard
    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 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 					@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 = opponent.getSlot(255 - j).getVitality();
    56 											
    57 											if(Run.getAutoMode())
    58 											{
    59 												if(w > 0)
    60 												{
    61 													int wdec = (int) Math.floor(9 * n / 10);
    62 													int resw = w + wdec;
    63 
    64 													opponent.getSlot(255 - j).setVitality(resw > 65535 ? 65535 : w);
    65 												}
    66 											}
    67 											else
    68 											{
    69 												if (w > 0)
    70 												{
    71 													int wdec = (int) Math.floor(9 * n / 10);
    72 													int resw = w - wdec;
    73 
    74 													opponent.getSlot(255 - j).setVitality(resw < 0 ? 0 : w);
    75 												}
    76 											}											
    77 
    78 											return new I();
    79 										}
    80 										else
    81 										{
    82 											throw new ICFPCException();
    83 										}
    84 									}
    85 									else
    86 									{
    87 										throw new ICFPCException();
    88 									}
    89 								}
    90 								else
    91 								{
    92 									throw new ICFPCException();
    93 								}
    94 							}
    95 							else
    96 							{
    97 								throw new ICFPCException();
    98 							}
    99 						}
   100 						else
   101 						{
   102 							throw new ICFPCException();
   103 						}
   104 					}
   105 				};
   106 			}
   107 		};
   108 	}
   109 
   110 }