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